Hello everyone,
I'd like to use the history method to create a dataframe, then sort it by the price of the highs and get the timestamp of the all-time high out of it.
history = ("AAPL", 200, Resolution.Daily)
history = history.sort_values(by="high", ascending=False)
timestamp = history.loc["time"][0]
This way it's not working because I get a key error. So what do I have to use instead of "time"?
Best regards,
Christian
Link Liang
Hi Christian,
qb.History() will return a panda dataframe. Here is some information about usage.
"time" is not a column of the dataframe. In fact, it is index. Therefore we should access it by dataframe.index.
Here is my attemp to realize your idea. Hope it helps!
Christian Lauer
Hello Link,
thank you for your answer. It's clear to me now that I have to access it differently as an index. Now it's working:
history = self.History("AAPL", 200, Resolution.Daily) history = history.sort_values(by= "high", ascending=False) self.Log(history.loc["AAPL"].index[0])
Â
Christian Lauer
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!