A few simple rows
--- I encourage all of you to see A few simple rows – Restated for the most up-to-date work ---
Today, I show you a simple illustration of how the investment strategy works. For brevity, I choose to focus on only five of the most popular OMX 30 constituents. Doing so, I overcome some of the problems associated with irregular pricing dates and missing values and my code will hopefully also become easier to follow.
First, we need data and I use yfinance to download historical prices and volumes.
Second, I take out the adjusted close prices and volumes from the total data frame. These will be used for calculating stock returns and the two asset factors of past trading volume and market beta.
Before we continue any further, it now makes sense to show you some of the math behind the strategy that is largely based on the parametric portfolio policy. If you want to even more about this topic, I recommend you take a look at my master's thesis in finance (accessible here).
In essence, I model the asset weights as:
Do you follow? When I try to explain this to my mother, I usually say that this model works kind of like an optimizing portfolio sorting strategy. We sort stocks given our chosen asset factors and the estimated thetas tell us how much and in which direction we should do so.
Once we have gotten some asset weights, we calculate the portfolio return as:
After doing so, we simply use these estimated values of theta as in the first equation for arriving to our final optimal asset allocation.
Now, let’s continues with the code illustration, starting with the asset factors, x. As we already have data for both volume and price, we calculate past trading volume, dolvol, quite easy.
For the market beta, I use the Fama and French five-factor model and a moving window a to estimate beta.
All data that is needed for the five-factor model is free and available at Kenneth R. French data library (following this link) under the heading “U.S. Research Returns Data (Downloadable Files)”.
Once we have calculated dolvol and beta, I first make sure that all our variables (including price and return) have the same lengths. Next, I standardize the asset factors to zero mean and unit standard deviation. This is an essential step for ensuring that our final asset weights sum up to one. Last, I combine both standardized asset factors into the x matrix.
We have now collected and created all data that we need, and it is finally time for the optimization.
In the pr= row, you see me playing around a bit with np.exp and np.log. I use log weights to ensure a positive position only (no big short) since I want the final outcome to be as practical as possible for any individual to use. Following this optimization, we get two estimated values of theta equal to:
Which basically tells you to put more value on stocks with a high past trading volume compared to socks with a high market beta.
We can now use the estimated values of theta to find our final asset allocation, focusing on as of 1 July 2022 that is our latest month in this available to us.
The first three rows show you the optimal weight of each stock conditioned on the thetas and asset factors that we have used. However, as we usually buy stocks in units rather than in percent, this exact allocation might be rather difficult to obtain.
The second four rows therefore tell you the number of units of each stock that you should buy for obtaining a close approximation of the optimal allocation. This is conditioned on a budget equal to 5000 SEK and accordingly, you should buy: 1 of HEXA-B.ST, 7 of AZN.ST, 9 of INVE-B.ST, 3 of KINV-B.ST, and 4 of SKF-B.ST.
The three last rows show you the actual weights that you get conditioned on the buy recommendation above.
When extending the strategy over all OMX 30 constituents, I arrived at two slightly different values of theta:
Those are the ones that I used for my first platonic investment displayed in Lets’ open the black box.
Next, I will probably show you some background analytics that I faced before arriving to this initial strategy. I will also give you some updates on how the investments are going and hopefully continue my search for an even better investment strategy.
Comments
Post a Comment