Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Why the price is different between research and back test?

In the back test, I logged the price. The prices are different, some of them is due to display issue, but some are not. Also, the volume is massively different.

2017-07-05 09:31  PRINT                             open    high      low    close    price     volume  
2017-07-03 00:00:00+00:00  125.0  125.04  124.020  124.418  124.418  7512425.0  
2017-07-05 00:00:00+00:00  124.2  124.20  124.135  124.150  124.150    33861.0  
2017-07-06 09:31  PRINT                              open    high      low   close   price      volume  
2017-07-05 00:00:00+00:00  124.20  124.65  124.115  124.47  124.47  10028780.0  
2017-07-06 00:00:00+00:00  123.52  123.53  123.490  123.50  123.50    115198.0  
4 responses

This is the code used in back test.

Keep an eye on the bar_count when calling the data history, I forgot exactly how it worked but refer to quantopians help page with regard to that. You may have to call the "df" object to get what you want.

Try writing

print(df[0])  

& checking it against a known value..

Also if you want the my_rebalance function to run 1 hour after market open don't leave the market_open() field blank but rewrite it to say

time_rules.market_open(hours = 1)  

So the code knows to rebalance 1 hour after market open

@ John Wu

The reason the numbers don't match (in places) is that you are fetching them at different times of the day. Specifically, all the daily data returned by 'get-pricing' in a notebook are end of day or close values. The data fetched by the algorithm using 'data.history' are as of the current minute.

So, looking at your algorithm output, this makes perfect sense...

2017-07-05 09:31  PRINT                             open    high      low    close    price     volume  
2017-07-03 00:00:00+00:00  125.0  125.04  124.020  124.418  124.418  7512425.0  
2017-07-05 00:00:00+00:00  124.2  124.20  124.135  124.150  124.150    33861.0  

As of 2017-07-05 09:31 the volume for the current day (ie 07-05) was 33861 shares. This is how many shares had traded through the first minute of trading that day (ie as of 9:31 am). The volume for the previous day (ie 07-03) was 7512425 shares and represent the total shares traded for that day.

Now let's look at the notebook price and volumes for those same two days...

open_price  high    low close_price volume  price  
2017-07-03 00:00:00+00:00   125.00  125.04  124.020 124.418 7512425.0   124.418  
2017-07-05 00:00:00+00:00   124.20  124.65  124.115 124.470 10028780.0  124.470

Remember notebook data is end of day. So 2017-07-05 end of day volume was 10028780 shares. This doesn't match the algorithm volume because the algorithm volume was printed at 9:31am and NOT the end of day. However, the volume for the previous day (ie 07-03) was 7512425 shares and represent the total shares traded for that day and also matches exactly the value in the algorithm.

A lot of people would like at 9:31 in the morning to know the closing price for the day but no can do. Can't look into the future. There's no crystal ball. No lookahead bias.

@Dan Whitnable
This is helpful.
Thanks for clarification.