I believe there’s an error in your cagr function: I didn’t look at how it’s used too closely, but whenever you see 365 in financial code it’s usually an error. It would be more appropriate to use 252, the average number of trading days for US equity exchanges, instead of 365.I have some questions regarding the article: How are you hedging? What instrument are you hedging with?
Also, how much leverage are you taking on? If you’re not selling out any original shares and shorting an equal amount of some other shares (see my first question), you’re taking on 2x leverage. As such, you’re not really comparing apples to apples.
Moreover, Puru Saxena is not really doing what your blog is describing. What he’s doing (at least according to some Twitter posts I read), is holding a market neutral portfolio where the long side consists of specific stocks he likes and the short side an ETF to hedge the geography exposure. Because he’s investing in high beta tech stocks, he can lower his beta and his geography exposure through shorting the appropriate ETF. This is a smart strategy, but is only going to work on high beta companies.
Anyways, in general, we do not want to look at returns when analyzing an investment strategy. Instead, we should look at the Sharpe ratio. While I don’t have enough information to say whether your results are correct, honestly, they don’t pass the smell test. I feel like the EMA window is overfit, your CAGR is being boosted by the use of 365 instead of 252, and I suspect that you are taking on leverage, which might be also boosting your returns.
Also looking at the code, it’s needlessly complex because you’re dealing with actual shares and such. A better method is to just deal with returns directly and represent your portfolio as a vector of weights, the sum of the absolute values should add up to zero with no leverage.
The type of hedging you describe in your example is equivalent to just selling the shares, but a little worse. You’re paying interest on your shorts, so you’re losing 2% annually from holding shares and shorting some other shares. There’s literally no reason why you would want to hold both a long and short position on a stock.
I recommend you check out Quantopian (https://www.quantopian.com/). It makes your life so much easier and they have all the data, plus great risk models and alpha factor generation tools.
Also as a fellow software engineer interested in finance, you might like my financial blog, https://cryptm.org/.