Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to avoid a look ahead bias

I did some test from 11/21/2016 to 11/23/2016
Question1 : When i backtest with time_rules.market_open(hours = 0, minutes = 5)) ,the log result shows a time from 2016-11-21 22:35 to 2016-11-23 22:35 But when I changed to time_rules.market_close(hours = 0, minutes = 5)) Why the log result shows a time from 2016-11-22 04:55 to 2016-11-24 04:55 ? why the time had a one day ahead?

Question2: it appears to me when I use time_rules.market_open(hours = 0, minutes = 5)) , I had to shift the dataframe to avoid a look ahead bias. But in real world trading, when I do a time_rules.market_close(hours = 0, minutes = 5)) , I thought I don't need to the shift any more,(the line f.shift(1) is not needed ) , I think I still have a 5 minutes look ahead bias in this example ? Am i right?

3 responses

The way to avoid look ahead bias is to use the pipeline. Fetching and manipulating that data can expose you to 'seeing' data that doesn't exist yet. The pipeline functionality protects you from that.

That said. Here's my take on your questions...

The log prints the local time and not the market time. You must be 13 hours ahead of the time in New York (China perhaps?) That's why it appears to be the following day.

If you are trying to use VIX pricing, I'd suggest not using 'fetch_csv' and instead use a pipeline and the free dataset from Quandl supplied by Quantopian (https://www.quantopian.com/data/quandl/cboe_vix). That will eliminate any possibility of forward bias and make the backtest environment identical to the live one.

@Dan Thank you.
I thought the limit of pipeline is it does not provide minute data for vix.(vxv ,vxst). which means we can only use time_rules.market_open(hours = 0, minutes = 5)) after the vix yesterday price is updated. If we have access to minute data, then we can trade based on the instant market price. we don't have to wait for the cboe or quandl update.

In order to trade based on the real time vix price, I don't know if it's possible to update the csv file in dropbox and fetch it through quantopian. I thought there's a lot of risk for the process

Eric, there isn't currently a way to get the actual VIX index imported into Quantopian on a minutely basis. The next best thing is the price of VXX

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.