I am interested in backtesting and automating my risk-parity strategy with futures (UB, ES, GC) while holding the cash in 3 month t-bills. I currently use about 2.5x leverage and a risk allocation of 50%, 40% and 10% respectively, with quarterly rollovers and yearly rebalancing. I need a template where I can tweak and backtest with varying degrees of leverage and rebalancing frequencies. If too difficult to get futures data, TLT, SPY and GLD are good approximations. Can anyone help?
James Smith
On the face of it, with a few compromises, it sounds like what you want isn't terribly difficult to acheive. I have cut a few corners and adapted the basic template algorithm.
If this is any help perhaps you can explain the underlying assertions of the strategy. How are the risk allocations arrived at? What is the preference of holding t-bills?
Fernando Rubiao
James Smith
Thanks. As you say, this is not risk adjusted, (and without a stop loss) which means it's a fairly simple strategy. I believe there are methods exposed to the algorithm to calculate correlations on the fly, but when you're talking about long timescales, this is not particularly useful. What approach would you take if you wanted to convert this into a full risk parity strategy? Would you require an additional hedging strategy or are the risks already adequately hedged? I suppose if you hard code the risk allocations you would want to hedge against the correlations falling out of expectation.
As you’ll see I’ve diverged in a few areas from your description, and am fairly sure I’ve transposed your risk allocations. You should be able to tweak the main parameters you mentioned with the months and leverage variables. If you need to rebalance at a frequency less than annually or more than monthly, wider changes will be needed.
I'm intrigued by the consistent performance up until the middle of last year and am wondering what steps could be taken to avoid the drawdown.
Fernando Rubiao
I also thought of replacing the ETFs for long dated options strategies. This is a way that you definitely could improve the risk reward profile, but it would be hell to backtest. SPY options have a lot of skew, you could place a risk-reversal with SPY, SPX or ES options instead of owning the ETF. On the other hand, collars on treasury futures tend to have a good payoff profile. Another way would be to sell long dated atm puts and roll them over yearly, but I have not clue whatsoever on how to backtest these strategies, but I am sure they would be good. You could increase the leverage while naturally limiting risk.
James Smith
I’ve been working on a project that allows genetic optimization of algorithm parameters. I ran this strategy in the optimizer and as it is low resolution with only two parameters, it decided an optimum fairly quickly:
I then extended the parameters to include asset allocations for the ETF’s. This was still a fairly simple solution which resulted in the following optimum:
These results aren’t of great practical significance given the timescale of the test data (and some other caveats). You’ll notice that the GLD event last year contributes to an optimum excluding this asset. I’m wondering how these findings compare to your expectations based on macroeconomic or other factors?
Fernando Rubiao
Regarding leverage, there were some margin calls using over 3x. I think one would definitely get better returns using about 3.5x but rebalancing would need to happen weekly or maybe even daily. I don't know how to change that. Lastly, I don't know what brokerage model the algo is currently using, but mine is a portfolio margin with IB brokers. I suppose making these adjustments would allow backtesting with more leverage and get good results.
James Smith
I have rejigged this slightly for a longer timescale and required a minimum 10% of each etf. Rebalancing can now occur every n>7 days. Slippage and fees will likely preclude rebalancing too frequently on IB, and this will be accounted for by the backtests.
When run through the optimizer, there was no way to survive 2008 without a margin call event. This means the trading engine may detect an imminent margin call and offload the culprit to bring the portfolio back within limit. Whether this would work in (freefall) live trading is anyone’s guess. The eventual optimum was found to be:
start: 2017-01-27 14:44:11Z
end: 2017-01-27 16:17:35Z
leverage: 2
days: 330
tlt: 0.3
spy: 0.4
sharpe: 0.618
James Smith
To investigate the effect of higher leverage, I changed the default IB leverage to a maximum of x4. I also changed the start date to late 2004 as the Yahoo data does not extend any earlier for the GLD ETF. As results were nearing the 365 days rebalancing ceiling I increased the maximum, to encourage the optimizer to explore higher values. This is still using the default (optimistic) slippage, which will bias towards more frequent rebalancing. If you’d like to suggest a slippage estimation, this can be included in the model.
start: 2017-01-30 09:58:05Z
end: 2017-01-30 10:14:27Z
leverage: 3.8
days: 391
tlt: 0.3
spy: 0.5
sharpe: 0.84
Fernando Rubiao
James Smith
Sure.
Fernando Rubiao
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!