Hi guys, I'm trying to obtain the historical prices of the past 60 trading days for 20 symbols. I'm passing this list of symbols "self.trading_symbols" into self.history. However, I've noticed that the historical dataframe is not the output I'm expecting. Instead of giving me a dataframe with the shape (1200, 5), it either returns (1140, 5) or (1080, 5).
I've checked the length of self.trading_symbols as well and it clearly shows that there are 20 symbols in the list. I am at a lost as to what the problem may be and any help will be greatly appreciated, thank you!
from QuantConnect.Data.Custom.Tiingo import *
import pandas as pd
from itertools import chain
class TransdimensionalTachyonCompensator(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 1, 1) # Set Start Date
self.SetEndDate(2020, 11, 11)
self.SetCash(100000) # Set Strategy Cash
self.AddUniverse(self.CoarseSelectionFunction)
self.UniverseSettings.Resolution = Resolution.Daily
self.spy = self.AddEquity("SPY", Resolution.Daily).Symbol
self.trading_symbols = []
self.Train(self.DateRules.MonthEnd(), self.TimeRules.AfterMarketOpen(self.spy, 0), Action(self.train))
self.Schedule.On(self.DateRules.MonthStart(), self.TimeRules.AfterMarketOpen(self.spy, 0), Action(self.rebalance))
def CoarseSelectionFunction(self, coarse):
sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
self.filtered = [ x.Symbol for x in sortedByDollarVolume if x.HasFundamentalData ]
return self.filtered[:20]
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
'''
pass
def rebalance (self):
self.trading_symbols = [ (str(symbol).split(" ")[0]) for symbol in self.filtered[:20]]
def train(self):
if not self.trading_symbols: return
self.Debug(len(self.trading_symbols)) # gives a length of 20
for symbol in self.trading_symbols:
self.AddEquity(symbol, Resolution.Daily)
self.lookback_period = 60
history = self.History(self.trading_symbols , self.lookback_period , Resolution.Daily)
self.Debug(history.shape) # shows (1140, 5) or (1080, 5)