Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0.387
Tracking Error
0.507
Treynor Ratio
0
Total Fees
$0.00
class HorizontalUncoupledInterceptor(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 1, 1)   # Set Start Date
        self.SetEndDate(2020, 6, 10)    # Set End Date
        self.SetCash(100000)            # Set Strategy Cash
        
        self.spy = self.AddEquity("SPY", Resolution.Daily)
        self.xlf = self.AddEquity("XLF", Resolution.Daily)
        
        
        self.ratio = IndicatorExtensions.Over(Identity('SPY'), Identity('XLF'))
        self.ratio_ema = IndicatorExtensions.EMA(self.ratio, 20)
        
        
        self.flag1 = 0
        self.SetWarmUp(20, Resolution.Daily)
        self.Schedule.On(self.DateRules.EveryDay('SPY'), self.TimeRules.At(10, 00), self.Rebalance)
        
        
    def OnData(self, data):
        if self.flag1 == 1:
            if not self.ratio_ema.IsReady:  return
        
            ratioCurrent = self.ratio.Current.Value
            emaCurrent = self.ratio_ema.Current.Value
            self.Debug(ratioCurrent)
            self.Debug(emaCurrent)
            
            lowThreshold = emaCurrent * 0.995
            highThreshold = emaCurrent * 1.005
            
            if ratioCurrent < emaCurrent:
                self.SetHoldings(self.spy.Symbol, 0.5)
                self.SetHoldings(self.xlf.Symbol, -0.5)
            if ratioCurrent > emaCurrent:
                self.Liquidate()
        
        self.flag1 = 0
        
        
    def Rebalance(self):
        self.flag1 = 1