| Overall Statistics |
|
Total Trades 611 Average Win 2.93% Average Loss -2.33% Compounding Annual Return 387.305% Drawdown 17.600% Expectancy 0.380 Net Profit 1008.899% Sharpe Ratio 7.586 Probabilistic Sharpe Ratio 99.429% Loss Rate 39% Win Rate 61% Profit-Loss Ratio 1.26 Alpha 4.886 Beta 0.241 Annual Standard Deviation 0.651 Annual Variance 0.424 Information Ratio 6.905 Tracking Error 0.682 Treynor Ratio 20.49 Total Fees $0.00 |
class FadingTheGap(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019, 1, 1)
#self.SetEndDate(2018, 7, 1)
self.SetCash(100000)
self.SetBrokerageModel(BrokerageName.Alpaca)
self.tickers=["TQQQ", "UVXY", "FAS", #"UPRO", "NUGT", "UDOW", "TECL", "SPXL", "SOXL"
]
self.volatilities = {}
self.windows = {}
for ticker in self.tickers:
symbol = self.AddEquity(ticker, Resolution.Minute).Symbol
self.volatilities[symbol] = StandardDeviation(ticker, 120)
self.windows[symbol] = RollingWindow[TradeBar](2)
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.BeforeMarketClose("TQQQ", 0), self.ClosingBar)
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen("TQQQ", 2), self.OpeningBar)
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen("TQQQ", 90), 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, 2/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])