I am having an issue accessing the 'close' field in the History dataframe for the S&P Futures Contract with the highest open interest. See code below:
class MultidimensionalNadionCircuit(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 5, 18) # Set Start Date
self.SetEndDate(2020, 5, 18) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.SP = self.AddFuture(Futures.Indices.SP500EMini,Resolution.Minute)
self.SP.SetFilter(0, 90)
def OnData(self, slice):
for chain in slice.FutureChains:
self.popularContracts = [contract for contract in chain.Value if contract.OpenInterest > 1000]
if len(self.popularContracts) == 0:
continue
sortedByOIContracts = sorted(self.popularContracts, key=lambda k : k.OpenInterest, reverse=True)
self.liquidContract = sortedByOIContracts[0]
hist = self.History(self.liquidContract.Symbol, 60, Resolution.Minute)
hist =hist["close"]
def OnEndOfDay(self):
pass
In the hist=hist["close"] statement, I get an error: Runtime Error: Trying to retrieve an element from a collection using a key that does not exist in that collection throws a KeyError exception KeyError : 'close' . Shouldn't I be able top access the 'close' column of the hist dataframe? Is this a bug?