Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Some glitches with history() [or my error]

Hey guys,

Super happy to see the developments of the history function. It's making some of the tedious work really easy and quick.

While playing with it I noticed a few things:

1. I tried having a global variable, BARS = 10 , to pass to history

BARS = 10  
history(bar_count=BARS, ...... )  

It gives an error 'bar_count must be an int'.

2. I have the following code to get the prices:

price_history = history(bar_count=10, frequency='1m', field='price')  
for s in data:  
        price  = price_history[s]  
        print price

This returns:

PRINT2014-09-19 19:52:00+00:00 7.605
2014-09-19 19:53:00+00:00 7.600
2014-09-19 19:54:00+00:00 7.600
2014-09-19 19:55:00+00:00 7.609
2014-09-19 19:56:00+00:00 7.610
2014-09-19 19:57:00+00:00 7.605
2014-09-19 19:58:00+00:00 7.610
2014-09-19 19:59:00+00:00 7.605
2014-09-19 20:00:00+00:00 7.610
2014-09-22 13:31:00+00:00 7.590
Name: 33026, dtype: float64

The last price value seems to have an older time stamp. I've noticed this on all the fields, not just the price field.

Again, maybe I'm just messing something up, but yeah. There it is

2 responses

Starting from the 1st row if there is missing data this doesn't get forward filled also though a previous price was available at some point in time. Maybe this can be fixed with the above.

I think I can explain what you're seeing.

  1. History requires you to specify the number of bars requested explicitly. That number is used before the backtest starts in order to pre-load the history you need; we don't support that number changing dynamically during a backtest. If you want a variable number of bars, you should request the maximum number you will need up front, and then slice into the history result to get the smaller number. As example, if sometimes you need 100 bars and sometimes you need 10, then you do bar_count=100, and sometimes you use the whole result, and sometimes you just use a subset.

  2. That looks like the right output to me. The last price value is the most recent, not the older. First of all, notice that the timestamps are +00, meaning they are in UTC. I'm presuming that in the example your backtest starts on Sept 22 of 2014. The first bar of Sept 22 2014 is at 9:31 Eastern, aka 13:31+00. That is exactly what you're seeing in the 10th line of your output - the price at the end of the first bar of the day. The previous 9 lines are the trailing minute history - the prices leading up to market close on Sept 19 2014

I think that should clear it up.

Disclaimer

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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.