| Overall Statistics |
|
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio -3.758 Tracking Error 0.151 Treynor Ratio 0 Total Fees $0.00 |
import pickle
import numpy as np
from collections import deque
class TachyonResistanceEngine(QCAlgorithm):
def Initialize(self):
self.KEY = 'futures'
useStoredData = True
endDay = 5
# uncomment below and run once, then set useStoredData = True
# self.SetStartDate(2020, 9, 15)
# self.SetEndDate(2020, 10, endDay)
# comment out below when running with the two lines above
self.SetStartDate(2020, 10, endDay+1)
self.SetCash(100000) # Set Strategy Cash
self.gc = self.AddFuture(Futures.Metals.Gold)
self.gc.SetFilter(0, 365)
self.x = True
futures = [self.gc]
period = 10
if self.ObjectStore.ContainsKey(self.KEY) and useStoredData:
byteData = self.ObjectStore.ReadBytes(self.KEY)
self.futures_data = pickle.loads(bytearray(byteData))
else:
self.futures_data = {}
for future in futures:
symbolString = future.Symbol.ID.Symbol
# we use a deque because they are picklable unlike RW's
self.futures_data[symbolString] = deque(maxlen=period)
self.curr_day = -1
def OnEndOfAlgorithm(self):
self.ObjectStore.SaveBytes(self.KEY, pickle.dumps(self.futures_data))
def OnData(self, data):
if self.curr_day == self.Time.day:
return
self.curr_day = self.Time.day
for contracts in data.FutureChains.Values:
sorted_contracts = sorted(contracts, key=lambda c: c.Expiry, reverse = True)
if (len(sorted_contracts) == 0):
continue
front_contract = sorted_contracts[0]
self.futures_data[front_contract.Symbol.ID.Symbol].append(front_contract.LastPrice)
for symbol, data in self.futures_data.items():
if len(data) == data.maxlen:
self.Plot('Variance', symbol, np.var(data))