| Overall Statistics |
|
Total Trades 48 Average Win 0.30% Average Loss -0.23% Compounding Annual Return 0.432% Drawdown 1.000% Expectancy 0.041 Net Profit 0.221% Sharpe Ratio 0.263 Probabilistic Sharpe Ratio 30.008% Loss Rate 54% Win Rate 46% Profit-Loss Ratio 1.27 Alpha 0.01 Beta -0.015 Annual Standard Deviation 0.019 Annual Variance 0 Information Ratio -2.09 Tracking Error 0.167 Treynor Ratio -0.338 Total Fees $48.00 Estimated Strategy Capacity $81000000.00 |
class PairsStrategy(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 9, 14) # Set Start Date
self.SetCash(10000) # Set Strategy Cash
self.AddEquity("NFLX", Resolution.Hour)
self.AddEquity("ROKU", Resolution.Hour)
self.lookbackdays = 5
self.diffthreshold = 5 # 5 = 5%
self.profitlevel = 10 # 10 = 10%
self.stoplevel = 5 # 5 = 5%
self.tradestoday = 0
self.dailytradeslimit = 6
self.holding_roku = 0
def OnData(self, data):
# Reset the Trades Counter at the beginning of each day
if int(str(self.Time.time())[0:8].replace(':','')) == 100000: # Note: on hourly resolution, 10:00 AM is the first datapoint we get for the day
self.tradestoday = 0
# Limit Number of Trades in a Day
if self.tradestoday >= self.dailytradeslimit:
return
# Get last X Days of Data to Compare Move With
NFLXhis = self.History(["NFLX"], self.lookbackdays, Resolution.Daily)
ROKUhis = self.History(["ROKU"], self.lookbackdays, Resolution.Daily)
# Identify The Close From X Days Ago
NFLXcomppoint = NFLXhis.close[0]
ROKUcomppoint = ROKUhis.close[0]
# Identify The Current Price
NFLXprice = self.Securities["NFLX"].Price
ROKUprice = self.Securities["ROKU"].Price
# Calculate The Percantage Gain/Loss of Each Symbol
if NFLXcomppoint >= NFLXprice:
self.NFLXmove = 100*(1-(NFLXprice/NFLXcomppoint))
else:
self.NFLXmove = -100*(1-(NFLXcomppoint/NFLXprice))
if ROKUcomppoint >= ROKUprice:
self.ROKUmove = 100*(1-(ROKUprice/ROKUcomppoint))
else:
self.ROKUmove = -100*(1-(ROKUcomppoint/ROKUprice))
# Enter Short Position
if self.holding_roku == 0 and self.ROKUmove > self.NFLXmove and self.Portfolio.TotalPortfolioValue > max(NFLXprice, ROKUprice):
if abs(self.NFLXmove-self.ROKUmove) > self.diffthreshold:
self.MarketOrder("ROKU", -1)
self.shortprofit = ROKUprice*(1-(self.profitlevel/100))
self.shortstop = ROKUprice*(1+(self.stoplevel/100))
self.holding_roku = self.holding_roku + 1
# Enter Long Position
if self.holding_roku == 0 and self.ROKUmove < self.NFLXmove and self.Portfolio.TotalPortfolioValue > max(NFLXprice, ROKUprice):
if abs(self.ROKUmove-self.NFLXmove) > self.diffthreshold:
self.MarketOrder("ROKU", 1)
self.longprofit = ROKUprice*(1+(self.profitlevel/100))
self.longstop = ROKUprice*(1-(self.stoplevel/100))
self.holding_roku = self.holding_roku + 1
# Long Take Profit
if self.Portfolio["ROKU"].Quantity > 0 and ROKUprice >= self.longprofit:
self.Liquidate()
self.tradestoday = self.tradestoday+1
self.holding_roku = self.holding_roku - 1
# Long Stop Loss
if self.Portfolio["ROKU"].Quantity > 0 and ROKUprice <= self.longstop:
self.Liquidate()
self.tradestoday = self.tradestoday+1
self.holding_roku = self.holding_roku - 1
# Short Take Profit
if self.Portfolio["ROKU"].Quantity < 0 and ROKUprice <= self.shortprofit:
self.Liquidate()
self.tradestoday = self.tradestoday+1
self.holding_roku = self.holding_roku - 1
# Short Stop Loss
if self.Portfolio["ROKU"].Quantity < 0 and ROKUprice >= self.shortstop:
self.Liquidate()
self.tradestoday = self.tradestoday+1
self.holding_roku = self.holding_roku - 1