Greetings everyone! Algorithm and backtest attached. I'd like to keep my max drawdown each day to 4.5% using the code implementation below bu it doesn't seem to be working. Suggestions?
self.SetRiskManagement(MaximumDrawdownPercentPortfolio(0.045))
However, as shown in the drawdown chart, this is not the case.
Any idea why this is?
Lucas
Hi James
I have been dealing with this issue before.
The thing is that the portfolio rebalances the day after the flat signal has been produced by the risk management model. To stop this from happening, the best thing is to import the logic of the “MaximumDrawdownPercentPortfolio” to the alpha model. I suggest you go over this thread:
James Hawkins
Thanks for the help Lucas ! Unfortunately, that specific solution is quite above my skill level 😬. I'm trying to implement a simple tradeLock instead, which is enabled on each insight and not disabled until 2359 EOD. However, the tradeLock function is in the AlphaModel class and I am not quite sure how to call that function via a schedule from the Initialize class. Basically, cross-class function calling. What are your thoughts?
Lucas
Hi James
Could you elaborate a little bit more about the tradelock function and what it is supposed to do? I would be happy to see if I could make it for you 😊
Furthermore, it should be noted, that we should try to abstain from cross-class as much as possible. It breaks the seperation of concern principle, which makes the QC framework less flexable.
Lucas
James Hawkins
Lucas absolutely! The tradeLock is a simple boolean True/False object that is initially defined within the class as False. Special criteria is then added to the insight trade logic so that the insights will only be produced/returned if the tradeLock is False ("Off"). Once the insight is produced/returned, then the tradeLock is set to True ("On"). This way, going forward, if the trade produced by the insight is stopped out by MaxDrawDown, Alpha will not re-enter it because the tradeLock criteria is not met in the trade logic. Finally, to reset the tradeLock, we call the tradeLockReset function at 2359 of each day when markets are close which resets it for the next day where the process repeats itsself.
The challenge faced here is that I am using the Alpha Model versus typically placing everything in the Initialize function. I tried placing the tradeLockReset function in the AlphaModel, but to no avail.
Lucas
Hi James
I've imported the “MaximumDrawdownPercentPortfolio" to the alpha model. It should do as you have asked. It only gets one update pr day (as it is set to daily resolution, if you want to change this to something like hour, a simple statement like):
with self.lastDay being set to -1 in the init method of the alpha model.
Furthermore, it is reset everday, so the drawdown insight is only valid for a single day, and after this, the normal alpha can kick in. The overall drawdown is still bigger than 0.05 percent, as the drawdown is being reset everyday, and is theirfore not protected from a “lower low”.
I have actually imported 2 max drawdown approach, the first one is commented out, but as I like the second way better. It is possible to modify the code, so a lower low is not possible, but I did not have the time ;(
Have a good day
Lucas
James Hawkins
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!