Back

How to implement Max Daily Drawdown in the Framework?

Hi guys,

Here is what I'm hoping to do:

  • If portfolio drawdown from start of day is below a threshold set all holdings to 0
  • Also don't enter into any new transactions for the rest of the day
I could do the portfolio drawdown check in a RiskManagementModel, the problem is that I need a way to clear all the ActiveInsights so that the algorithm does not make additional transactions based on them.  I can't emit insights in the risk model because the RiskModel is executed inside the ProcessInsights loop and EmitInsights would kick off another ProcessInsights loop.

So I decided to do it in my alpha model and check for drawdown as a first step in the Update process. I set the Insights to flat and the Portfolio Target to 0 on the holding.  This does not work though.  Setting the portfolio target does nothing because it will be overwritten by the targets created from the Insights.  However the targets created from the flat insights do not cause the sale of the holdings.

It seems at this point the only way to implement this will be with a custom PortfolioConstructionModel.  Any recommendation or suggestions would be welcomed.
Update Backtest







0

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.


The only way I have found to do this now is to call Liquidate from the Alpha model, but a more elegant solution would be preferred.

0

Hey Kctrader,

The most elegant solution is to implement it in a RiskManagementModel. In general, it is good practice to keep the AlphaModel's calculations independent of the contents of the portfolio. It is also good practice to limit AlphaModel to emitting insights and not calling Liquidate within that class.

0

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.


Hi Rahul,

I tried my best to do that.  The challenge is that the risk management model cannot expire the insights, so even if it sets the portfolio targets to 0 and exits the position, it will simply re-enter based on the unexpired insights.  This is also a problem with the current RiskManagementModels, not just the one I want to implement. 

We had a thread in Slack about it and there was some discussion about the best way to handle this going forward.  Jared suggested adding the ability to expire insights.  

0

Thanks, KC we've added a Github issue for expiring insights and will get there ASAP. 

If you can post a mock example of the risk model getting ignored it would help debug this. I think the model's outputs are meant to be "pulsing" not "steady-state", so if something is getting overridden/ignored we might need to really look into why. 

Also really consider if you need the framework; if you need to control each trade you might not want to use the framework scaffolding. 

 

0

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.


Jared Broad Here is a backtest that shows the issue.  A UGAZ insight is generated at 9:31 and the framework enters the position. The risk model exits the position shortly past 10am.  At 12pm we generate an insight for DGAZ.  At that point the framework enters an equal position on both DGAZ and UGAZ because the UGAZ insight has not expired.

I think the crux of the issue is that sending in additional insights for any security causes ProcessInsights to execute and it continues to use all unexpired insights, regardless of what the Risk Management Model has done.

I'll post this to Github as well.

1


Update Backtest





0

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.


Loading...

This discussion is closed