Overall Statistics
Total Trades
10
Average Win
0.74%
Average Loss
0%
Compounding Annual Return
59.364%
Drawdown
1.200%
Expectancy
0
Net Profit
3.728%
Sharpe Ratio
10.106
Probabilistic Sharpe Ratio
98.511%
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
0.207
Beta
0.477
Annual Standard Deviation
0.061
Annual Variance
0.004
Information Ratio
-3.826
Tracking Error
0.064
Treynor Ratio
1.301
Total Fees
$10.00
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")
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)