I get an a run time error when I call the History function:
Runtime Error: Trying to retrieve an element from a collection using a key that does not exist in that collection throws a KeyError exception
Apparently the 'close' column is not found. But when I look at the log, it appears that there are close values but the column name 'Close' is not there. Any ideas on what could be the problem and how to resolve this?
2019-11-17 00:00:00 Launching analysis for 9c30ce40576d83fea3ffa1a3085b4f22 with LEAN Engine v2.4.0.0.8348
2019-11-17 18:01:00 expiry symbol time
2019-12-27 GC XAOU1HJH8XI5 2019-11-15 15:52:00 1467.1
2019-11-15 15:53:00 1467.3
2019-11-15 15:54:00 1467.3
2019-11-15 15:55:00 1467.3
2019-11-15 15:56:00 1467.3
2019-11-15 15:57:00 1467.3
2019-11-15 15:58:00 1467.1
2019-11-15 15:59:00 1467.3
2019-11-15 16:00:00 1467.4
2019-11-15 16:01:00 1467.4
2019-11-15 16:02:00 1467.2
2019-11-15 16:03:00 1467.3
Lordy Mike
This error only happens when I comment out the 'return' statement in the if self.Portfolio[self.liquidContract.Symbol].Invested statement.
Alexandre Catarino
Hi Lordy Mike ,
Sorry about the wait.
We have found a bug in the historical data request caused by a time zone issue. Essentially, the data from the last four hours of the day (the time zone difference from EDT and UTC) was not fetched. Consequently, the data frame was empty, and an empty data frame does not have the 'close' column:
hist = self.History(self.liquidContract.Symbol, self.lookback) if hist.empty: self.Log(f'Empty history data frame for {self.liquidContract.Symbol} at {self.Time}.') continue hist = hist['close']
Meanwhile, we have fixed the issue. I have tested your algorithm and the bug is gone.
Lordy Mike
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!