Overall Statistics
class NadionHorizontalCircuit(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2018, 1, 2)  # Set Start Date
        self.SetEndDate(2018, 1, 30)
        self.SetCash(10000)  # Set Strategy Cash
        # self.AddEquity("SPY", Resolution.Minute)
        self.spy = self.AddEquity("SPY", Resolution.Minute)
        self.spy.SetDataNormalizationMode(DataNormalizationMode.Raw)
    
        self.roc = RateOfChange(5)
        self.roc.Updated += self.OnROC
        
        self.rocWindow = RollingWindow[IndicatorDataPoint](2)
        
        self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.BeforeMarketClose("SPY", 5), self.Rebalance)
        
    def Rebalance(self):
        
        if not self.roc.IsReady:
            history = self.History("SPY", 5, Resolution.Daily)
            for bar in history:
                self.roc.Update(bar.EndTime, bar.Close)
        
        self.roc.Update(self.Time, self.Securities["SPY"].Close)
        
        if not self.rocWindow.IsReady:
            return
        
        long_signal = self.rocWindow[0] > self.rocWindow[1]
        
        if long_signal:
            self.SetHoldings("SPY",1)
        else:
            self.Liquidate("SPY")
            
    def OnROC(self, sender, updated):
        if self.roc.IsReady:
            self.rocWindow.Add(updated)
class Volatility(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2018, 1, 2)  # Set Start Date
        self.SetCash(10000)  # Set Strategy Cash
        # self.AddEquity("SPY", Resolution.Minute)
        self.ziv = self.AddEquity("ZIV", Resolution.Daily)
        self.ziv.SetDataNormalizationMode(DataNormalizationMode.Raw)
    
        self.roc = self.ROC("ZIV", 5, Resolution.Daily)
        self.SetWarmUp(5)
        
        
    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
            Arguments:
                data: Slice object keyed by symbol containing the stock data
        '''
        if self.IsWarmingUp:
            return
        
        if self.roc.Current.Value > 0:
            self.SetHoldings("ZIV",1)
        else:
            self.Liquidate("ZIV")