Basic Portfolio Math

Some of the stuff in portfolio management is so basic that we often forget how really basic it is. The building block of a portfolio is the position taken in some shares of a listed company as an investment or as a short-term speculative move. In both cases, the objective is to make a profit. We buy an asset and hold on to it, or resell it later on for a profit. Trading is simply doing the latter often.

The problem in not in the understanding of the game, it comes from asking very basic questions, like: what, when, and how much. An even more basic question is: why initiate that trade, at that time, in the first place?

A Trade

A trade origins from some stock price at some time $\,p_t\,$ taken from its price series $p(t)$ chosen from the available stock universe at time $t$ with the intention of profitably holding on to it over some time interval $(t + \tau).$ The quantity $\,q,\,$ bought at time $\,t,\,$ is held over the period $\,(t + \tau).$

A completed trade will generate a profit or a loss: $\,q \cdot (p_{t + \tau} - p_t ) = x.\,$ Looking backward in time, the same principle applies: $q \cdot (p_t - p_{t - \tau} ) = x.$ We can view the price difference as: $(p_t - p_{t - \tau} ) = \Delta p,\,$ and picture the outcome of a trade as: $\,q \cdot \Delta p= x.$ This last expression will hold for any trade. The value of a position at any one time will be: $\,q \cdot p_t$.

A trader, by definition, intends to do many trades. We can sum them all using the following expression: $\sum^n (q_i \cdot \Delta^i p),\,$ which adds the result of the sequence of trades as a vector of lenght $\,n.\,$ Here, $\,\Delta^i \,$ is understood to include the exit price associated with the initiating trade id $\,i.\,$ That there be hundreds, thousands or millions of trades, this sum of profits and losses (P$\&$L) will give the final outcome.

No matter how we slice and dice a stock price series, we can always know the end result, which is a simple addition: $\sum^n (q_i \cdot \Delta^i p).$

To resume all trades taken on that one stock, we can write the following equation: $F(t) = F_0 + \sum^n (q_i \cdot \Delta^i p)\,$ which states that the final outcome is composed of the original stake allocated to the task to which is added the result of all the taken trades. Again, very basic.

A Portfolio

A portfolio is usually composed of many stocks. We can add an index to identify which stock we are dealing with. The trade outcome vector would be: $\sum^n (q_{i, \,j} \cdot \Delta^i p_{\,j}) = \sum^n (P\&L).$ Still, every profit and loss is accounted for. However, this makes it a sequence of trades hard to analyze since it is just an order sequence of trades without patterns to distinguish a particular stock $\,j\,$ even if it is easily identified in the portfolio.

It is why I prefer the matrix payoff representation of that same data: $\sum^n (\mathbf{H}_{d, \,j} \cdot \Delta^i \mathbf{P}_{d, \,j})$ which says the same thing but disposes everthing in neet rows and columns. And, where $\mathbf{H}$ is the ongoing inventory matrix, holding quantity of shares held ($\,h\,$) in each stock ($\,j\,$) at any one time ($\,d\,$).

The outcome of a trading strategy could be resumed to: $\sum^n (\mathbf{H} \cdot \Delta^i \mathbf{P})\,$ with the understanding that the structure has its implicit indexes. In Python, it could have for expression: $payoff\_matrix = (\textsf{H} \cdot d\textsf{P}).sum() $.

The inventory matrix $\mathbf{H}$ has a simple composition: $\mathbf{H} = \mathbf{B} - \mathbf{S}.\,$ It is the sum of the quantities $\mathbf{B}$ought minus the quantities $\mathbf{S}$old. These are usually sparse matrices, and can become even more sparse as the trading interval is increased.

$\textsf{The inventory matrix}$ $ \,\textbf{is}\,$ $\textsf{the trading strategy.}$

It holds the historical record of all the trading decisions taken. It has for each element: $\;\mathbf{h}_{d, \,j} = \mathbf{h}_{d-1, \,j} + \mathbf{b}_{d, \,j} - \mathbf{s}_{d, \,j}.\,$ Which says: the current inventory in each stock is equal to the inventory values in the previous period to which is added the shares bought, and from which is subtracted the quantities sold in each of the stocks. What remains is the net running total of shares held as $\,d\,$ increases.

This also implies that if $\;\mathbf{h}_{d, \,j} = \mathbf{h}_{d-1, \,j}\, $ then, it can only mean that $\;\mathbf{b}_{d, \,j} = 0$, and $\;\mathbf{s}_{d, \,j }= 0$. Stating that the inventory did not change which is equivalent to holding all the current positions as they were.

I find it easier to handle the payoff matrix rather than the payoff vector even if both say the same thing. One can view the payoff matrix growing from period by period as it increases its number of rows ($\,d\,$) and/or columns ($\,j\,$). Also, we can easily distinguish the trade history of each stock $\,j$ since they are organized as columns in the matrix.

All the above is trivial. Has been known for generations.

Still, few look at the portfolio problem is such a manner. Usually what we see are trading strategies designed to go from period to period trying to forecast what is coming next. With little as generalized long-term views of where a strategy is going in time.

Whereas, the payoff matrix deals with the impact of a trading strategy from start to finish. Seeing the trading strategy as a whole with its strenghts and weaknesses as they are played out over the long term. It is concerned with period to period plays, but its real strenght is in giving the ability to plan for much further than just the next period.

$\textbf{A portfolio has for equation}$: $$F(t) = F_0 + \sum^n (\mathbf{H} \cdot \Delta^i \mathbf{P}) - \sum^n (\mathbf{E}xp)\,$$It reads: the portfolio value, or its net liquidation value, at time $\,t\,$ is the sum of the initial capital plus the sum of the result of all ($n$) trades taken over the time interval from $\,t_0\,$ to $\,t\,$ and from which is subtracted all trading expenses.

With that equation, every trade in every stock is accounted for over the entire life of a portfolio. This portfolio can be of any size, contain hundreds of stocks over thousands of days, and the equation will still hold.

The equation is not just for traders, it is the same for any kind of stock portfolio. That it be discretionary trading or investing, or the result of some software program.

What should stand out is the trading strategy $\,\mathbf{H}$. It acts as the engine for this equation, its profit or loss generator.

If somehow the outcome of the payoff matrix is zero: $\sum^n (\mathbf{H} \cdot \Delta^i \mathbf{P}) = 0,\,$ then no need to guess that much as to your terminal portfolio value.

Comparing Trading Strategies

Comparing strategies is simple. Provide them with an identifier, as in: $\sum^n (\mathbf{H}_a \cdot \Delta^i \mathbf{P}).\,$ Then, ask if strategy $\mathbf{a}$ is better than strategy $\mathbf{b}$: $\sum^n (\mathbf{H}_a \cdot \Delta^i \mathbf{P}) > \sum^n (\mathbf{H}_b \cdot \Delta^i \mathbf{P}) ?\,$ The output of a payoff matrix is just a number giving the total profit or loss. Therefore, one is actually comparing two numbers as to their respective size. How complicated can it be?

We are not just comparing from one period to the next, even if it is included. We are comparing strategies over their entire lifespan, and this using a single expression. In Python, one could write: $\, If \; (\textsf{H}_{a} \cdot d\textsf{P}).sum() > (\textsf{H}_{b} \cdot d\textsf{P}).sum(): \dots$

Evidently, if you can compare two trading strategies, you can compare any number of them. Sort them out according to performance or whatever other criteria. We can also include a benchmark in the lot. $$\sum^n (\mathbf{H}_a \cdot \Delta^i \mathbf{P}) > \sum^n (\mathbf{H}_b \cdot \Delta^i \mathbf{P}) >, \dots, > \sum^n (\mathbf{H}_{SPY} \cdot \Delta^i \mathbf{P}) > , \dots, > \sum^n (\mathbf{H}_z \cdot \Delta^i \mathbf{P})$$With this comparaison, a trader can locate the relative performance level of any trading strategy he/she might design or compare their respective benefits. One thing is sure, you can always order those numbers according to size.

Trading More Than One Strategy

To trade a number of strategies simultenuously and still have the ability to summarize and compare them, add an index to the payoff matrix: $$\sum^n (\mathbf{H}_{k, \, d, \,j} \cdot \Delta^i \mathbf{P}_{k, \, d, \,j})$$ where $\,k = 1, \dots, k\,$ identifies the strategies. This $k$ by $d$ by $j$ payoff matrix is sufficient to evaluate all applied strategies over all their respective stocks, or any group of stocks in each portfolio for any duration.

This is the kind of problem Quantopian is trying to solve, which is to find, out of all the tested trading strategies on its site (over some 4,000,000 backtests to date) which are the best. Which are acting best have also a Python one-liner expression: $(\textsf{H} \cdot d\textsf{P}).sum(axis=0)$. The $\,k\,$ best strategies can be viewed as Quantopian's selected few it intends to execute live from all its backtested strategies including those selected from its contests.

Point72, (one of Quantopian's funders (\$250M) has the next level problem to solve. Handle a fund of funds of portfolios of trading strategies and also pick the best of them.

It too can add an index to its payoff matrix: $$\sum^n (\mathbf{H}_{e, k, \, d, \,j} \cdot \Delta^i \mathbf{P}_{e, k, \, d, \,j})$$where $\,e = 1, \dots, e\,$ identifies the funds. This results in an $e$ by $k$ by $d$ by $j$ payoff matrix. Multiple funds having multiple portfolios of multiple strategies of multiple stocks each.

The job is to find the expected best strategies of the group and put all the emphasis on these selected few since they have the task to drive the whole portfolio forward. At this level, our machines can do all the work.

Undertandably, one would be interested only in the top few funds operating at top performance anyway. Anything below a certain level would only degrade what was already there.

The reason is that even with multiple strategies, the game remains a CAGR game. In the beginning, strategy performance differences might appear small, but with compounding, it could make quite a difference later on. And later on, catching up, might be doable.

Averaging out ever decreasing numbers will simply produce ever decreasing averages. And that is not the object of the game.

The Payoff Matrix

It was set that the portfolio, whatever its size, had for equation: $F(t) = F_0 + \sum^n (\mathbf{H} \cdot \Delta^i \mathbf{P}) - \sum^n (\mathbf{E}xp).\,$ It can be reduced further to bring out the following: $F(t) = F_0 + n \cdot \bar x.\;$ For a demonstration of this, see my website, papers, and books which elaborates more on its decomposition.

However, no need to read all that, since the explanation is quite straightforward. The average net profit per trade is simply: $$\displaystyle{\frac{\sum^n (\mathbf{H} \cdot \Delta^i \mathbf{P})-\sum^n (\mathbf{E}xp)}{n} = \bar x}$$ This lets us rewrite the portfolio equation as: $F(t) = F_0 + n \cdot \bar x.\;$ Reducing the whole portfolio accounting to a simple procedure, one of counting the trades and multiplying that number by the average net profit per trade to obtain the total generated profit of loss.

From this, we can plan for objectives. We can start from the final outcome, and build by what process we could have achieved that outcome. As if designing from the end results what we could have done to get there.

The above formula says nothing about how, what or how much should have been traded. Only, that it needs a positive edge ($\bar x > 0$) to be repeated a number of times. Just as it provided no "why" should it have been so. Nonetheless, there is a lot that can be deduce from such an outcome.

A ten-bagger portfolio would have for equation: $F(t) = F_0 + 9 \cdot F_0 = 10 \cdot F_0$. Where $\,9 \cdot F_0 = n \cdot \bar x.\;$ This says that any combinaison of trades times its average net profit per trade equaling $\,9 \cdot F_0 \,$ can do the job. And therefore, any trading strategy producing those two numbers is suitable.

For this ten-bagger, the CAGR would be: $$CAGR = \displaystyle{\left(\frac{10 \cdot F_0}{F_0}\right)^{1/t}-1} = \left(\frac{F_0 + n \cdot \bar x}{F_0 }\right)^{1/t}-1$$which puts the emphasis on finding a suitable $\,\bar x > 0$ that can be repeated $\,n\,$ times.

A World of Possibilities

It is not finding a trading strategy that does this or that under specific constraints. It is more about finding a strategy that has a positive edge $\,\bar x > 0\,$ which can be executed $\,n\,$ times. There is not just one strategy that can do the job, but most likely an infinite set of possibilities.

Whatever strategy you design, or any modification you bring to an existing one, it must have an impact on $\;n \cdot \bar x.\;$ Otherwise, whatever the modification was, it was just cosmetic programming.

$©$ March 2018 Guy R. Fleury