I can't get risk models to close out all positions as I would expect. I hope someone here can help me understand QuantConnect's behavior?
To understand risk models I threw together a trivial algorithm that uses QC standard framework components with a manual universe. This universe should not generate any symbol changes over time, so the only source of change would be the alpha signals and portfolio rebalancing. I have gone over the lean engine code that invokes risk balancing, which appears to be here:
https://github.com/QuantConnect/Lean/blob/master/Algorithm/QCAlgorithm.Framework.cs#L197
If i'm reading this right, rebalancing is run only on targets, which are in turn generated from insights and rebalances. And only those symbols for which targets exist are subject to risk management. By default portfolio risk management should generate a “close all positions” signal each time there's a drawdown > 5%. Visually, from the drawdown graph, it looks like this happens quite frequently with my algorithm. But in the logs I only see three times where risk management kicks in:
2018-10-17 00:00:00 10/17/2018 12:00:00 AM: RISK: AA: 0 | AAPL: 0 | GE: 0 | IBM: 0 | JNJ: 0 | MMM: 0 | MSFT: 0
2018-10-17 00:00:00 10/17/2018 12:00:00 AM: RISK ADJUSTED TARGETS: AA: 0 | AAPL: 0 | GE: 0 | IBM: 0 | JNJ: 0 | MMM: 0 | MSFT: 0
2019-09-14 00:00:00 9/14/2019 12:00:00 AM: RISK: AA: 0 | AAPL: 0 | GE: 0 | IBM: 0 | JNJ: 0 | MMM: 0 | MSFT: 0
2019-09-14 00:00:00 9/14/2019 12:00:00 AM: RISK ADJUSTED TARGETS: AA: 0 | AAPL: 0 | GE: 0 | IBM: 0 | JNJ: 0 | MMM: 0 | MSFT: 0
2019-10-31 00:00:00 10/31/2019 12:00:00 AM: RISK: AA: 0 | AAPL: 0 | GE: 0 | IBM: 0 | JNJ: 0 | MMM: 0 | MSFT: 0
2019-10-31 00:00:00 10/31/2019 12:00:00 AM: RISK ADJUSTED TARGETS: AA: 0 | AAPL: 0 | GE: 0 | IBM: 0 | JNJ: 0 | MMM: 0 | MSFT: 0
I'd like to understand why risk adjustment isn't kicking in. The actual scenario I am working with makes things harder because I try to ensure monthly trades with no rebalancing. Which means there are no insights generated mid-month and no portfolio targets from the portfolio construction model. As a result I get no risk management whatsoever. I'll create a simplified implementation of that scenario once I understand the behavior here.
Sunil
Varad Kabade
Hi Sunil Mishra,
You are correct RiskManagement only gets triggered when portfolio targets are created. To resolve this, we can copy the MaximumDrawdownPercentPortfolio and fix it to remove the dependency of new targets. We can alternatively move the logic to Update method to emit a flat insight if the risk management signal is achieved.
Best,
Varad Kabade
Sunil Mishra
Thanks for the suggestion Varad, I did implement my own based on the existing implementation to look at the whole portfolio rather than the incoming targets. It now works but the results are less than stellar.
Sunil
Sunil Mishra
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!