Overall Statistics
Total Trades
66
Average Win
1.27%
Average Loss
-1.30%
Compounding Annual Return
26.934%
Drawdown
4.200%
Expectancy
0.376
Net Profit
17.029%
Sharpe Ratio
2.393
Probabilistic Sharpe Ratio
83.208%
Loss Rate
30%
Win Rate
70%
Profit-Loss Ratio
0.97
Alpha
0.281
Beta
-0.01
Annual Standard Deviation
0.117
Annual Variance
0.014
Information Ratio
0.861
Tracking Error
0.189
Treynor Ratio
-28.093
Total Fees
$115.05
Estimated Strategy Capacity
$9700000.00
class FadingTheGap(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2017, 11, 1)
        self.SetEndDate(2018, 7, 1)
        self.SetCash(100000) 
        tsla = self.AddEquity("TSLA", Resolution.Minute)
        tsla.SetDataNormalizationMode(DataNormalizationMode.Raw)
        self.symbol = tsla.Symbol
        
        self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.BeforeMarketClose(self.symbol, 0), self.ClosingBar) 
        self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen(self.symbol, 1), self.OpeningBar)
        self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen(self.symbol, 45), self.ClosePositions) 
        
        self.window = RollingWindow[TradeBar](2)
        
    def ClosingBar(self):
        if self.symbol in self.CurrentSlice.Bars:
            self.window.Add(self.CurrentSlice[self.symbol])
    
    def OpeningBar(self):
        if self.symbol in self.CurrentSlice.Bars:
            self.window.Add(self.CurrentSlice[self.symbol])
        
        #1. If our window is not full use return to wait for tomorrow
        if not self.window.IsReady:
            return
        
        #2. Calculate the change in overnight price
        delta = self.window[0].Open - self.window[1].Close
        
        #3. If delta is less than -$2.5, SetHoldings() to 100% TSLA
        if delta < -2.5:
            self.SetHoldings(self.symbol, 1)
        
    def ClosePositions(self):
        self.Liquidate()