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

 

Author