Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
history function (suddenly) not working? or feed data scrambled?

Hi guys,

All of a sudden an algo I've been working on for weeks started reporting bewildering results. Narrowing it down, I found that a function
I wrote to calculate lows and highs for a period was returning gibberish, or rather the lows and highs were identical

From the debugger here are results:
highs = history(5, '1m', 'high').dropna(axis=1)
highs
DataFrame:
Equity(8554 [SPY])
2015-09-23 19:57:00+00:00 193.82
2015-09-23 19:58:00+00:00 193.81
2015-09-23 19:59:00+00:00 193.79
2015-09-23 20:00:00+00:00 193.78
2015-09-24 13:31:00+00:00 192.28
lows = history(5, '1m', 'low').dropna(axis=1)
lows
DataFrame:
Equity(8554 [SPY])
2015-09-23 19:57:00+00:00 193.82
2015-09-23 19:58:00+00:00 193.81
2015-09-23 19:59:00+00:00 193.79
2015-09-23 20:00:00+00:00 193.78
2015-09-24 13:31:00+00:00 192.28

Any body else see this? I am running this on Sunday at 3:33pm EST 10/4/2015.

Thanks
Serge

11 responses

Ok , I created a simple test program to demonstrate this data. It must be run in minute mode to see the behavior.
I have since verified that it applies to earlier years (2014) also. I DO NOT get the skewed results in daily mode.

Look at the minute bar lows and highs. They should not be at the same values.

I see it too, jeepers. How does something like that make it to prod...

If there is only one SPY trade within a given minute, then the OHLC values would all be the same. Also, there is the possibility that SPY did not trade at all, and the data were forward-filled (see https://www.quantopian.com/help#ide-history, under Illiquidity and Forward Filling), although it is not clear from the documentation how OHLC values are filled. Are opening prices filled with the last known opening price, highs with the last known high, etc. or do all OHLC values get filled with the last known close? Note that forward-filling can be toggled off with ffill=False.

Grant,

Your points are all true, but SPY trades at such high frequency that it is close to impossible that there are no trades within a 60 second period. (Volume of shares at end of day close to 1/2 million trades in a minute). Also I double checked a few trades with minute prices on IB and TradingView and Stockcharts.

For example check out these recent dates,
2015-09-28 13:31:00+00:00 191.91
2015-09-28PRINThighs
2015-09-28PRINT Equity(8554 [SPY])
2015-09-25 19:58:00+00:00 193.01
2015-09-25 19:59:00+00:00 193.02
2015-09-25 20:00:00+00:00 193.06
2015-09-28 13:31:00+00:00 191.91
2015-09-28 13:32:00+00:00 191.61
2015-09-28PRINTlows
2015-09-28PRINT Equity(8554 [SPY])
2015-09-25 19:58:00+00:00 193.01
2015-09-25 19:59:00+00:00 193.02
2015-09-25 20:00:00+00:00 193.06
2015-09-28 13:31:00+00:00 191.91
2015-09-28 13:32:00+00:00 191.61

The high/low of 191.91 on the morning of the 28th is shown at tradingview to be 188.52 and 188.20,a 32 cent spread.

No something else is amiss. I've been wondering why my day trading algo produced such incredibly different results than my real live trading algo.
Until now I just ascribed it to poor programming skills and nuckled down to tweak my code again and again. LOL.

Sorry I misworded that last statement. I do not have a live trading algo (yet). The results were different from my live trading (done in the old "snail human" fashion, by me entering trades on a keyboard).

Serge/Simon/Grant - we're taking a look at the history calls and will share with any updates we find.

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.

It's now been fixed. If you run that sample algo (and any other algo) you'll see the correct values.

Thanks,
Alisa

Thanks Alisa,

Now if my strategy still doesn't make money, I've got nobody to blame but myself. #)$)$)%%)##_#)(*&^ ... kinda liked having that excuse...

Hi Alisa,

I agree with Simon's sentiment regarding the quality control lapse here. Have you added some checks to ensure the problem won't make it to production again?

Grant

There is a (large) suite of test cases automatically run for each deployment. Each feature or bug fix almost always includes new test cases. Unfortunately, things slip past the automated test suite on occasion because we're not perfect and don't foresee every possible circumstance and in those situations we're designed to react quickly in order to rectify.

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.

To be more explicit, yes, new unit test cases were added as part of this bug fix.