| Overall Statistics |
|
Total Trades 4 Average Win 0.56% Average Loss 0% Compounding Annual Return 3.965% Drawdown 0.200% Expectancy 0 Net Profit 1.124% Sharpe Ratio 1.4 Probabilistic Sharpe Ratio 63.906% Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 0.034 Beta 0.005 Annual Standard Deviation 0.024 Annual Variance 0.001 Information Ratio 0.454 Tracking Error 0.506 Treynor Ratio 6.91 Total Fees $23.33 |
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.spy_close = self.Identity('SPY', Resolution.Daily, Field.Close)
self.xlf_close = self.Identity('XLF', Resolution.Daily, Field.Close)
self.ratio = IndicatorExtensions.Over(self.spy_close, self.xlf_close)
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