Back

Check if History() actually worked?

Hey everybody.

Is there a way to test ifor history() actually came back with data? For example, I run the history() function on a lot of stock over quite a few years. I want to make sure none of them come back null or don't retrieve all the data, etc.

Thanks again!

Update Backtest








Hi Tayler Allen 

There should be a lot of method to validate the data. I just show you the method I use. Assume self.symbols is your list of symbols:

history = self.History(252,Resolution.Daily)

for i, bar in enumerate(history):
# I just check the first two bars, you can check more depending on your needs
if i == 2:
break
# check if the TradeBar contains the symbol in our list, if not, you can print it out or remove it
# by self.symbols.remove(symbol)

for symbol in self.symbols:
if not bar.ContainsKey(symbol):
self.Log(str(symbol))

 

0

Thanks Yan but that only checks if there is a specific symbol in the history. I need to check if the history contains real prices or if it couldnt retrieve history that old.

0

Hi Tayer, If you want to validate date, you can check TradeBar.EndTime. My Common method is to put the prices in a pandas Series, and use time as the index of the series. 

0

Thank that's one way but I think I found a way that may work better for my needs. 

I create a list of the history tradebars and checked to see if the Count for the list was the same as the amount of history I requested. If it is, all the data are there. If it's not, there's not enough historical data.

I'll post an example soon.

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