Hello , When i add the risk management function to my algorithm ,it seems that it s not working as the report doesn't recognize the risk control.

Can someone help me on this please ?

from Risk.TrailingStopRiskManagementModel import TrailingStopRiskManagementModel import numpy as np import pandas as pd import datetime class NadionResistanceAutosequencers(QCAlgorithm): def Initialize(self): self.SetStartDate(2017, 1, 1) self.SetEndDate(2020,1,1)# Set Start Date self.SetCash(100000) self.Security=["LMT","MSFT","GM","MS","FB","NKE","AAL","TSLA","MS","GS","AMZN","T","BA","BLK","EA","C","KO","AMD","MMM","AXP","F","HON","SPY"] for s in self.Security: self.AddEquity(s,Resolution.Daily) self.SetRiskManagement(TrailingStopRiskManagementModel(0.03)) self.SetExecution(ImmediateExecutionModel()) # Set Strategy Cash # self.AddEquity("SPY", Resolution.Minute) def OnData(self,data): S=["LMT","MSFT","GM","MS","FB","NKE","AAL","TSLA","MS","GS","AMZN","T","BA","BLK","EA","C","KO","AMD","MMM","AXP","F","HON","SPY"] M=self.History(S,360,Resolution.Daily) M=M.close V=M.unstack(level=0) Daily_returns=np.log(V/V.shift(1)) Daily_returns_mean = Daily_returns.mean() SPY_index_return = Daily_returns_mean[-1] SPY_index_Var = Daily_returns.var()[-1] covariance_index_stock = Daily_returns.cov() Beta = covariance_index_stock.iloc[:,-4]/SPY_index_Var Rcapm = 0.02 + Beta * (SPY_index_return-0.02) SR = (Rcapm-0.02)/SPY_index_Var for i in range(len(S)-1): if SR[i]<0: self.SetHoldings(S[i],0.10) else : return for i in range(len(S)-1): if SR[i]>0: self.SetHoldings(S[i],-0.10) else: return

 

Author