I was on it for a few days already,
I'm trying to add another security level to simple Manual Universe strategy
option 1: adding simple stop loss if strategy start to loose 5% form its top line
option 2: adding risk management frame work with drawdown parameter
I tried both options and nothing worked for me.
Please help me or let me know your thoughts.
I'll appreciate it a lot!
Thank you.
D
Mak K
Hi,
If you follow this guide it should be relatively simple, if you have any more questions let me know;
https://www.quantconnect.com/docs/algorithm-framework/risk-management
And here you can find all the available modules;
https://github.com/QuantConnect/Lean/tree/master/Algorithm.Framework/Risk
Thanks!
Clueless
Mak, thank you very much for your response.
I was trying to solve it with Framework for the last a few days, (the first link you sent), but I still feel like I'm missing something,
The second link with a several framework strategies is very helpful, thank you very much for sharing it.
Following the above, I created “MaximumDrawdownPercentPerSecurity” class in a stand alone file and called it in a main.py with “self.AddRiskManagement(MaximumDrawdownPercentPerSecurity(self)), which seems to be a wrong way because I keep on getting the following error; ”"During the algorithm initialization, the following exception has occurred: TypeError : bad operand type for abs(): 'WellDressedSkyBlueSardine' at __init__ self.maximumDrawdownPercent = -abs(maximumDrawdownPercent) File "main.py" in MaximumDrawdownPercentPerSecurity.py: line 10 TypeError : bad operand type for abs(): 'WellDressedSkyBlueSardine'"
also, my “OnSecuritiesChanged” includes only code that relevant to my original “universe selection”, and have no reference to the risk management code, so I'm not sure how it supposed to pick up the “sale” signal when its a time
I'm trying my best with Python but I feel I still missing something.
Mak, I'll appreciate your help.
(the updated code attached for your review)
D
Mak K
Hi,
Thanks for the attached code, I will get this working for you today!
Clueless
Hi again I think I found the way to add “TrailingStopRiskManagementModel” however I still don't have a way to do a liquidate in case of market/portfolio meltdown ( lets say if portfolio goes 10% down, I want to liquidate and wait timedelta days
attached is my final code
Please let me know your thoughts.
D
Mak K
Hi,
There are complete models to solve that problem, will link you in a minute.
Thanks!
Mak K
Hi again,
You can add this model to your code for the max loss per portfolio;
https://github.com/QuantConnect/Lean/blob/master/Algorithm.Framework/Risk/MaximumDrawdownPercentPortfolio.py
Works the same way as trailing stop etc. implementation wise.
For the timed delta thing to avoid market meltdown I would pick something less arbitrary if I was you. Maybe try using VIX or something like that.
Thanks!
Varad Kabade
Hi Clueless,
The class MaximumDrawdownPercentPerSecurity takes only a float input or none during initialization, as seen in the __init__ function. To resolve the issue, we need to remove the algorithm parameter which we are passing when creating the risk management model:
We can implement an OnSecuritiesChanged event handler inside the RiskManagementModel. Refer to the attached backtest.
Best,
Varad Kabade
Clueless
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!