| Overall Statistics |
|
Total Trades 360 Average Win 0.05% Average Loss -0.05% Compounding Annual Return 1.689% Drawdown 0.500% Expectancy 0.300 Net Profit 2.833% Sharpe Ratio 1.75 Probabilistic Sharpe Ratio 89.111% Loss Rate 34% Win Rate 66% Profit-Loss Ratio 0.97 Alpha 0.012 Beta 0 Annual Standard Deviation 0.007 Annual Variance 0 Information Ratio -0.818 Tracking Error 0.219 Treynor Ratio -123.718 Total Fees $0.00 |
import numpy as np
class TransdimensionalCalibratedRadiator(QCAlgorithm):
def Initialize(self):
#approximate QC implementation of stragety from https://www.reddit.com/r/algotrading/comments/iznj50/intraday_mean_reversion/
self.SetStartDate(2019, 1, 1) # Set Start Date
self.SetEndDate(2020, 8, 31) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.AddCrypto("BTCUSD", Resolution.Hour,Market.Bitfinex)
#self.SetBrokerageModel(BrokerageName.Bitfinex)
self.last_close = RollingWindow[float](744) #keep 31 days of hourly closes
self.last_high = RollingWindow[float](24) #keep 2 days of hourly highs
self.last_low = RollingWindow[float](24) #keep 2 days of hourly lows
self.downtrend = False
self.uptrend = False
self.trend_thresh = 5/100 #3% in the post
RangeChart = Chart("Range")
RangeChart.AddSeries(Series("31DayClose",SeriesType.Line))
RangeChart.AddSeries(Series("24hLow",SeriesType.Line))
RangeChart.AddSeries(Series("24hHigh",SeriesType.Line))
RangeChart.AddSeries(Series("LastClose",SeriesType.Line))
TrendChart = Chart("Trend")
TrendChart.AddSeries(Series("TrendDirection",SeriesType.Line))
def OnData(self, data):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
Arguments:
data: Slice object keyed by symbol containing the stock data
'''
if self.last_close.IsReady: #the longest array is populated, otherwise we just wait and collect values as above
self.Liquidate()
#self.Plot("Range","31DayClose",self.last_close[743])
#self.Plot("Range","LastClose",data['BTCUSD'].Close)
if (data['BTCUSD'].Close / self.last_close[743] - 1) > self.trend_thresh: #we're in an uptrend / last_close[0] means previous close
self.uptrend = True
self.downtrend = False
if (data['BTCUSD'].Close / self.last_close[743] - 1) < -self.trend_thresh: #we're in a downtrend
self.uptrend = False
self.downtrend = True
if self.uptrend:
#self.Log("Uptrend @ "+str(data['BTCUSD'].Time))
#self.Plot("Trend","TrendDirection",1)
#self.Plot("Range","24hLow",np.min(list(self.last_low)))
if data['BTCUSD'].Close < np.min(list(self.last_low)):#last close lower than 24 hour low
self.MarketOrder("BTCUSD",1)
if self.downtrend:
#self.Log("Downtrend @ "+str(data['BTCUSD'].Time))
#self.Plot("Trend","TrendDirection",-1)
#self.Plot("Range","24hHigh",np.max(list(self.last_high)))
if data['BTCUSD'].Close > np.max(list(self.last_high)):#last close higher than 24 hour high
self.MarketOrder("BTCUSD",-1)
self.last_high.Add(data['BTCUSD'].High)
self.last_low.Add(data['BTCUSD'].Low)
self.last_close.Add(data['BTCUSD'].Close)