I am sharing a few thoughts on risk management I had while developing trading algorithms for myself and my clients. Keep in mind my focus is mostly on Machine Learning based algorithms but these considerations are general enough apply also to all quants and even discretionary traders.
Most of the quants, or even traders, have the tendency to jump to the “sexy” part of the strategy definition, namely, using exotic datasets, crunching data via traditional analysis or Machine Learning to generate trading signals. Hours and resources are poured into squeezing the next 1% accuracy out of your signal generating model without acknowledging the elephant in the room: What happens when your signal is wrong?
This is not a hypothetical question, your model will be wrong at some point, maybe in a small way every day or in a big way during crashes. Therefore it is critical for you to adjust your trading framework accordingly.
I advocate for flipping the sequence of activities in trading algorithms’ development from:
- Analyze data and generate signals ideas
- Develop an algorithm to generate trading signals
- (Back)Test the trading signal
- Add a risk management layer
To:
- Define what is risk for you and how much you are willing to take
- Develop an infrastructure that targets the desired level of risk
- (Back)Test the risk infrastructure in the worst possible scenario (I like using a random model)
- Add a signal generation layer
While the concept of risk is very slippery (and its measurement even more), this change of perspective is certainly useful. You stop thinking that your signals are flawless and you start building contingency for when things will go against you.
To make things more practical you can find below a short algorithm that trades daily the SPY and that implements these concepts:
- A risk management framework: In this case I have used the Kelly Criterion which, together with the next day’s Up/Down prediction, defines the size of the position for that day.
- A signal generating model: Since the focus is on testing the risk management, I am using a DummyClassifier generating random 0/1 trading signals. I want to see how the algorithm behaves when a blindfolded monkey is on the steering wheel.
As you can see, the performance is by no means exceptional but, even with a totally random trading signal, the risk management still achieves reasonable returns and drawdown while squeezing out even a tiny alfa.
This is enlightening on the importance of this often overlooked component and my recommendation is to find your preferred risk management mechanism and test it under different conditions (tickers, asset classes, resolutions, …) with very bad or even random signals. In this way you can refine your own risk management layer so you can confidently release your real trading models.
Francesco
www.beawai.com
P.S. The considerations are inspired by several readings across Finance, Math and sometimes even Philosophy. I am sharing a few of these should you want to dig deeper:
Brandon Leonard
The longer I trade, the more this makes sense.
Axist
This is really cool, and I could see being useful when combining with an In/Out or momentum based algo. Took a crack at trying to make this work for multiple tickers at once. While I am not getting an error, I think there is an issue with training multiple tickers? Curious if anyone's gotten it to function with a list:
Jens.
Hi,
I really like the idea to use a random signal and I stumbled upon that myself. Thank you for your post and example. I figured that different monkeys (=different fixed seeds) get significantly different Sharpe Ratios. So I recommend employing a monkey gang to stress-test!
For me, risk management typically costs performance especially in the recent bull phase, but also makes the results more independent from the market. Do you have the same observation?
I will probably play around with your implementation to find out for myself, and post my assumptions later on.
Jens
Francesco Baldisserri
Hi Axist,
You can definitely make it work with multiple tickers but the critical part is that, where you calculate the Kelly Criterion, you need to calculate the past win rate and returns for your trading strategy. I took a look at your code and the In/Out is used in the trading part but the Kelly Criterion is still being fed with the results of the Dummy Classifier which is never used to trade.
If you want to use the Kelly Criterion you need to calculate the signals for your In/Out strategy for the last X days and the related wins and returns.
Hope it helps!
Francesco Baldisserri
Hi Jens. ,
You are totally right that a single backtest has limited information. I have made a few tweaks and added the parameter “seed” and “use_kelly” (0/1) so those parameters can be controlled and I ran a grid search over those.
Unfortunately I cannot share the grid search results like the backtests (feature request😊) but I am attaching one backtest with the new code, the screenshot of the grid search and the results in an excel (link).
Clearly this topic requires much more thought and analysis (the problem of induction has been debated for millenia) but the parameter “use_kelly” is positively correlated with the PSR, the Alfa and negatively correlated with Beta, Drawdown and Trades (to be fair it also has lower profit and annual returns, probably due to the limited trading during high risk situations).
PSR23%Sharpe Ratio-10%Net Profit-33%Drawdown-63%Total Trades-99%Alpha26%Compounding Annual Return-25%Beta-99%Annual Standard Deviation-99%
Thanks for the input and let me know if you have more insights!
Francesco Baldisserri
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!