Aug. 2, 2021

There is math and gaming in building a long-term automated stock trading strategy. Some of it is quite elementary and ignoring it could be unwise. The math sets limits, boundaries, and constraints on what you can or could do in trading stocks over the short to long term.

I use math to describe the game and see its limits, and when programming trading procedures, try to enhance strengths and alleviate weaknesses within the confines of limited capital, limited time, limited know-how, and limited resources.

You do not have to be good at everything to make it work for you.

A very simple mathematical expression for a stock trading strategy could be: F(t) = F_{0} + *X* where F_{0} is the initial trading capital at risk, and *X* the accrued profits and losses from all the thousands of trades taken over that strategy's lifespan.

Adding all the trades together for *i* = 1, … , N gives: *X* = Ʃ_{i}^{N}(q* _{i}* ∙ Δ

_{i}p

_{i}). The ongoing result of the trading strategy F(t) is always visible on the bottom line of the trading account.

After executing thousands of trades, we need a strategy to finish with a profit: *X* > 0. However, being positive is not enough. We need our strategy to generate enough profits to produce more than the market's long-term average r_{m} as in: F_{a}(t) > F(t) = F_{0} ∙ (1 + r_{m})^{t}.

**You Need To Do More Than Average**

If we do not exceed r_{m}, then someone else could have done a better job (even if simply buying index funds). In fact, many (maybe some ~40% of market participants) with g > r_{m}could have done better. So, our own objective should start with: F_{a}(t) = F_{0} ∙ (1 + g)^{t} where g = r_{m} + α with α the excess return, an expression for the skills we can bring to the game.

Setting a trading strategy F_{a}(t) as a payoff matrix, we have: *X*_{a} = Ʃ_{i}^{N}(**H**_{a} ∙ Δ**P**_{a}) where Δ**P**_{a} is the price difference matrix from period to period for the selected stocks. **P**_{a}is a subset of **P** which represents the whole tradable stock universe (thousands of stocks). Unselected stocks will not impact the strategy's final results since Ʃ(0 ∙ (**P** - Δ**P**_{a})) = 0, meaning you cannot profit or lose on price variations from unselected stocks. However, this does not mean that **P** or **P**_{a} cannot influence our trade decision-making process. Our selected stocks **P**_{a} usually represent only a very tiny subset of the available stock universe **P**.

The payoff matrix will keep a detailed record, from period to period, of the profits and losses for each position taken. It gives the exact same answer as its vector series counterpart. It displays historical transaction data in a more orderly fashion, by rows (time) and columns (stocks).

**Comparing Strategies**

We want to compare strategies based on profits, then the comparison is very simple: is *X*_{a} > *X*_{b}? Other portfolio characteristics could be considered. But for the most part, it remains: is strategy *X*_{a} producing more than *X*_{b} or *X*_{c} or *X*_{z} or whatever over the same time interval using the same initial capital? Was it the best we could do considering our own set of trading constraints? That is the question. Almost as a corollary, could we have done even better?

In the growth rate formula, we have: F_{0}, g, t, and from the trading point of view: F_{0}, N, x_{bar}. Both formulas give the same answer since: F(t) = F_{0} ∙ (1 + g)^{t} = F_{0} + N ∙ x_{bar} = F_{0} + *X*. Each formula brings a different insight, one considering time as a major element while the others only look at executed trades.

We do have limited time, limited capital, limited machine powers, limited know-how, limited trading procedures, and programming skills, to which we should add the market's own constraints to overcome. The how we handle everything, from start to finish, is what will give us our own *X*_{a}.

**We Should Want It Big**

Evidently, we want to make it large with as little risk as possible. That does not mean with no risk at all. We should know better. We play the game. We will win some and lose some. We will have risk of loss. The whole point is how much of it will we tolerate or endure?

Another expression for a portfolio is: F_{a}(t) = F_{0} ∙ ∏ (1 + r* _{i}*) where the emphasis is put on the incremental portfolio returns. It should be evident that if ever r

_{i}= - 1, game over, you lost it all. Fortunately, this is hard to do even if some do manage to do it anyway.

The payoff matrix can be reduced to two numbers:

F_{a}(t) = F_{0} + Ʃ_{i}^{N}(**H**_{a} ∙ Δ**P**_{a}) = F_{0} + N ∙ x_{bar}

where x_{bar} is the average net profit per trade and again N the total number of executed trades. The justification for x_{bar} is very simple: Ʃ_{i}^{N}(**H**_{a} ∙ Δ**P**_{a}) / N = x_{bar}, it is the strategy's total generated profits divided by the total number of trades N. Any trade simulation software will give you those 2 numbers.

We can compare strategy payoff matrices. Is Ʃ_{i}^{Na}(**H**_{a} ∙ Δ**P**_{a}) > Ʃ_{i}^{Nb}(**H**_{b} ∙ Δ**P**_{b}) > Ʃ_{i}^{Nc}(**H**_{c} ∙ Δ**P**_{c})? which can be simplified to: is *X*_{a} > *X*_{b} > *X*_{c}?

**The Trading Portfolio**

The following chart is based on a constant portfolio outcome *X* = N ∙ x_{bar}. You could make a similar chart for any value of *X*. The chart shows the distribution gamut of possible scenarios that could satisfy N ∙ x_{bar} = 10,000,000 (or based on any other amount for that matter) as an acceptable solution to this two-variable equation.

**Trading Spectrum**

The second chart in my last March article: **Basic Portfolio Math **showed the same information (N ∙ x_{bar}), but in a more dramatic way on a semi-log scale.

In the above chart, strategies **H**_{a} and **H**_{b} have quite different makeups, even though they give the same answer:

**H**_{a} = N_{a} ∙ x_{bara} = 100 ∙ 100,000 = 10,000,000

**H**_{b} = N_{b} ∙ x_{barb} = 100,000 ∙ 100 = 10,000,000

Strategy **H**_{a} is more oriented towards long-term trades, while **H**_{b} goes for short-term trades with a much lower average profit per trade.

Not every trade is a winner, especially in short-term trading systems. Markets are very chaotic and randomness comes to play a major role in daily price variations. If we cannot predict with any real confidence what the price will be tomorrow, it is due to this high degree of randomness found in stock prices. There is so much market noise, it often almost totally buries underlying long-term market signals.

**Win - Loss Distribution**

From the above example, we can extract:

*X*_{a} = (N - λ) ∙ AW + λ ∙ AL = 10,000,000

where λ is the number of losing trades, AW the average profit per winning trade, AL the average loss per losing trade, with N - λ the number of winning trades.

Isolating AW and AL, we get:

AW = 10,000,000 - λ ∙ AL / (N - λ) and

AL = 10,000,000 - (N - λ) ∙ AW / λ

With λ = 0 (no losses), we have: AW = 10,000,000 / N. AL would produce a divide by zero error.

With λ = N (all losses) we should get: AL = -10,000,000 / N. AW would now get a divide by zero error, as should be expected. Therefore, one should check for the division by zero before the calculation is done. It should be noted that achieving λ = N is very hard to do. We might be better off saying: as λ tends to N, then the strategy's outcome will tend to total capital loss: λ → N implies X_a → - 10,000,000.

With N - λ = λ, or λ = N / 2 we have a 50/50 scenario where we get: λ ∙ (AW + AL) = 10,000,000. For **H**_{a} this would give: (AW + AL) = 10,000,000 / 50 = 200,000 for the average trade. And for **H**_{b}: (AW + AL) = 10,000,000 / 50,000 = 200.

**What Is Your Choice?**

The question is: which is easier to realize, having $200,000 per average trade or $200? That is where short-term trading comes into play. Making on average about $200 per trade over the long term should be considered easy money (even if half your bets are wrong). The bigger the bet size, the easier it will be to reach that goal. This does not mean that you cannot find 100 trades over a period of 20 years that might generate an average of over $200,000 per trade. But, it does mean that a different skill set might be needed.

A $200 per trade does not require much. On a 1000-share bet, it would represent a 20 cents price move. A multitude of stocks will fluctuate by much more than 20 cents every single trading day.

Nonetheless, whatever you do trading, your final solution will fit into the above chart since, in the end, only those five numbers will matter: P_{0}, g, t, N, and x_{bar}.

Your job is to bring some alpha (α) to the party which will come to make quite a difference over the long term since it will be compounding.

It should be evident from the above that increasing the number of trades or increasing the average net profit per trade or both at the same time is what needs to be done, and as a side effect it will increase your alpha.

If you can make your strategy run longer (t + Δt), you should benefit greatly from that too.

This article is also in **HTML format**.

**Related Articles:**

Your Automated Stock Trading Portfolio

On The Use of a Rebalancer, a Flipper, and a Flusher

Making Money with no Fault of Your Own

Designing Successful Stock Trading Strategies

Winning The Automated Stock Trading Game

The In and Out Stock Trading Strategy

Aug. 2, 2021, © Guy R. Fleury. All rights reserved.