I decided to use History instead of RollingWindow because history gave me a multi-index pandas df that I was more used to.
However, running a couple backtests and checking the logs, the history window seems to be stuck the first instance when it was ran and doesn't move with day change as expected. Is there something wrong with the code below?
#in initialise
# History method returns a dict with a pandas.DataFrame - multi-index pandas DataFrame.
self.pxhistory = self.History(["BTCUSD","LTCUSD", "ETHUSD", "LTCBTC", "ETHBTC","LTCEUR", "ETHEUR", "BTCEUR"], TimeSpan.FromDays(self.lookback), Resolution.Daily)
#set warmup
self.SetWarmUp(200)
def OnData(self, data):
if not self.pxhistory.empty:
price_history = self.pxhistory["open"]
price_history = price_history.unstack('symbol')
Jing Wu
Hi YiPeng,
You requested the history price in Initialize(), it only runs once in your algorithm. Please put the history request in OnData() to get the updated history. However, history request every day for multiple symbols is not efficient, that's why we create the rolling window method.
Yi Peng Neo
Thanks Jing!
Yi Peng Neo
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!