Back

Emitting Insight Flat If Securites were removed by Risk Management?

Hello,

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.

Thanks very much!

 

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.


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

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 __init__(self, maximumDrawdownPercent = 0.05, reenter_after_days = 5):
self.maximumDrawdownPercent = -abs(maximumDrawdownPercent)
self.liquidated_dates_by_symbol = {}
self.reenter_after_days = timedelta(reenter_after_days)

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.


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