Back

Bar Time in History - Python

I am using the following to retrieve prices from History with a Minute resolution.  How do I get the times?

hist = self.History(["ADBE"], 780, Resolution.Minute)
prices = hist.close
for price in prices:
self.Log(str(price))

I know it's there but can't figure out how to access it and would appreciate some help.

Update Backtest







"hist" is a pandas dataframe. The index is datetime. Any functions of pandas dataframe apply to history request result. 

https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html

You could use 

for tuple in history.itertuples():
time = tuple.Index
close = tuple.close

 

 

 

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.


Jing Wu 

Thanks, as always.  Since the Index includes both symbol and time it appears I can tweak your answer and use:

history = self.History(["ADBE"], 780, Resolution.Minute)
for tuple in history.itertuples():
time = tuple.Index[1]
close = tuple.close
self.Log(str(time)+' '+str(close))

I've got a lot to learn.

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