LEAN is the open source
algorithmic trading engine powering QuantConnect. Founded in 2013 LEAN has been built by a
global community of 80+ engineers and powers more than a dozen hedge funds today.
Alpha League Competition: $1,000 Weekly Prize Pool
Qualifying Alpha Streams Reentered Weekly Learn
more
Is there any way the alpha model can emit flat insight if securities were liquidated by Risk management such as by specified drawdown? If so, are there any simple examples of this?
For example, I would like to wait for 5 days to re-buy the securities, if they are liquidated when there is -30% drawdown by the risk management module.
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 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.
Juhwan Kim
1k Pro
,
Just for the answer to my own question..
I saved stocks that were liquidated by the risk management module in alpha module to control how long to wait to reenter.
I hope this helps someone who may have the same question.
0
Edited by Juhwan Kim
Derek Melchin
STAFF Pro
,
Hi Juhwan,
Implementing this re-entry logic in the alpha model violates the separation of concerns design principle. Instead, we can accomplish the same thing by utilizing a custom risk management model. The risk management model below liquidates securities that experience a drawdown >=5%. When a security is liquidated, the risk management model keeps the PortfolioTarget value at 0 until 5 days have passed.
class MaximumDrawdownPercentPerSecurityCustom(RiskManagementModel):
def ManageRisk(self, algorithm, targets):
symbols_to_pop = []
for symbol, liquidation_date in self.liquidated_dates_by_symbol.items():
if algorithm.Time - liquidation_date >= self.reenter_after_days:
symbols_to_pop.append(symbol)
for symbol in symbols_to_pop:
self.liquidated_dates_by_symbol.pop(symbol, None)
targets = []
for kvp in algorithm.Securities:
security = kvp.Value
pnl = security.Holdings.UnrealizedProfitPercent
if pnl < self.maximumDrawdownPercent or security.Symbol in self.liquidated_dates_by_symbol:
# liquidate
targets.append(PortfolioTarget(security.Symbol, 0))
if algorithm.Securities[security.Symbol].Invested:
self.liquidated_dates_by_symbol[security.Symbol] = algorithm.Time
return targets
See the attached backtest for a full example algorithm. Also, consider reviewing our documentation on risk management models.
Best, Derek Melchin
1
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 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...
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!