Hi Everyone,
For my algorithm I require to compare open prices for CFDs for previous 10 days open. I was reading about the self.history method, however, I am unsure of how to use it exactly.
How do I get the code to 'print/show' the value for historical open. Or more generally, how do I just print out the structure i get when i run the self.history method.
I hope that makes sense?
Alexandre Catarino
Here is an example of a History Request in Python:
def Initialize(self): ticker = "XAUUSD"; self.SetStartDate(2017,1,1) #Set Start Date cfd = self.AddCfd(ticker, Resolution.Minute, Market.Oanda) # History method returns a dict with a pandas.DataFrame history = self.History([ticker], 10, Resolution.Daily) # prints out the tail of the dataframe self.Log(str(history[ticker].head())) for index, row in history[ticker].iterrows(): self.Log(str(index) + str(row))
Note that we need to pass the ticker in a list to have a pandas.DataFrame as output.
Allan Wojnowski
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!