| Overall Statistics |
|
Total Trades 378 Average Win 0.42% Average Loss -0.38% Compounding Annual Return 27.319% Drawdown 5.900% Expectancy 0.230 Net Profit 17.263% Sharpe Ratio 1.837 Probabilistic Sharpe Ratio 74.840% Loss Rate 42% Win Rate 58% Profit-Loss Ratio 1.11 Alpha 0.252 Beta 0.002 Annual Standard Deviation 0.138 Annual Variance 0.019 Information Ratio 0.709 Tracking Error 0.201 Treynor Ratio 106.746 Total Fees $1772.33 |
class FadingTheGap(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2017, 11, 1)
self.SetEndDate(2018, 7, 1)
self.SetCash(100000)
self.tickers=["TSLA", "FB", "SPY", "NVDA", "AMD"]
self.volatilities = {}
self.windows = {}
for ticker in self.tickers:
symbol = self.AddEquity(ticker, Resolution.Minute).Symbol
self.volatilities[symbol] = StandardDeviation(ticker, 60)
self.windows[symbol] = RollingWindow[TradeBar](2)
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.BeforeMarketClose("SPY", 0), self.ClosingBar)
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen("SPY", 1), self.OpeningBar)
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen("SPY", 45), self.ClosePositions)
def OnData(self, data):
for symbol, std in self.volatilities.items():
if data.ContainsKey(symbol) and data[symbol] is not None: #
std.Update(self.Time, data[symbol].Close)
def OpeningBar(self):
for symbol, window in self.windows.items():
if self.CurrentSlice[symbol] is not None:
window.Add(self.CurrentSlice[symbol])
if not all([window.IsReady for symbol, window in self.windows.items()]) or not all([std.IsReady for symbol, std in self.volatilities.items()]):
return
symbolsToTrade = []
for symbol, window in self.windows.items():
delta = window[0].Open - window[1].Close
deviations = delta / self.volatilities[symbol].Current.Value
if deviations < -3:
symbolsToTrade.append(symbol)
for symbol in symbolsToTrade:
self.SetHoldings(symbol, 1/len(symbolsToTrade))
def ClosePositions(self):
self.Liquidate()
def ClosingBar(self):
for symbol, window in self.windows.items():
if self.CurrentSlice[symbol] is not None:
window.Add(self.CurrentSlice[symbol])