trophy

Long Only, ETF Alpha Streams Competition with $27,500 Prize Pool

Back

Accessing time in history data frame

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

Update Backtest







0

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.


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!

1

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.


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])

 

0

Update Backtest





0

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.


Loading...

This discussion is closed