Back to Community
Futures prices mismatch: notebook vs algorithm

Why is that these two prints of close prices don't agree on notebook vs algorithm? (see the close price before last)


from datetime import timedelta

from quantopian.research.experimental import history, continuous_future  
import scipy.stats  
import numpy as np  
import pandas as pd  
import matplotlib.pyplot as plt  
#import matplotlib.patches as mpatches  
import alphalens

from statsmodels.regression.linear_model import OLS  
from import add_constant

data = history(  
    continuous_future('TU', adjustment=None, roll='calendar'),  
    fields = ['open_price','high','low','close_price','contract'],  
    frequency = 'daily',  
    start = '2010-01-01',  
    end = '2013-01-01'  



[110.234375, 110.203125, 110.203125, 110.1953125, 110.1875, 110.1484375, 110.1484375, 110.1328125, 110.1796875, 110.15625, 110.140625, 110.09375, 110.109375, 110.1015625, 110.125, 110.1015625, 110.109375, 110.109375, 110.1171875, 110.125, 110.078125, 110.1171875, 110.140625, 110.1796875, 110.203125, 110.203125, 110.203125, 110.2265625, 110.2578125, 110.2890625]

Algorithm code:

from zipline.api import continuous_future, schedule_function  
from zipline.api import time_rules, date_rules, record  
#from zipline.algorithm import log  
#from zipline.assets.continuous_futures import ContinuousFuture  
from zipline.api import order_target_value, order_target_percent  
from zipline.utils.calendars import get_calendar  
import numpy as np  
import scipy as sp  
import pandas as pd  
#from quantopian.algorithm import order_optimal_portfolio  
#import quantopian.optimize as opt

def initialize(context):  
    schedule_function(my_rebalance, date_rules.every_day(), time_rules.market_open(minutes=30))  
def my_rebalance(context, data):  
    f = continuous_future("TU", offset=0, roll='calendar', adjustment=None)  
    ohlc = data.history(f,  


2012-07-17 12:00 my_rebalance:24 INFO [110.23399999999999, 110.203, 110.203, 110.19499999999999, 110.187, 110.148, 110.148, 110.13200000000001, 110.179, 110.15600000000001, 110.14, 110.093, 110.10899999999999, 110.101, 110.125, 110.101, 110.10899999999999, 110.10899999999999, 110.117, 110.125, 110.078, 110.117, 110.14, 110.179, 110.203, 110.203, 110.203, 110.226, 110.25700000000001, 110.289]  
3 responses


Thanks for the post.

You've uncovered a bug, unfortunately.

It looks like the bug is in data.history(). data.history() is returning only 3 digits after the decimal. In this example you made, the tick size is .000125, so data.history() is only successfully reporting when the price moves 8 ticks. For some futures this will not be a problem at all (when the tick size is large), while for other futures, like currencies, the problem will be larger.

The simulation is buying and selling correctly at the more precise prices, so the actual simulation is correct. The bug will be a problem if your strategy depends on detecting the tick movement, and the movement is not revealed by data.history() because of the bug.

I'm sorry for any inconvenience this bug is causing. It's in our bug database to be fixed sometime in the future.


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.

Not sure I understand. Given that an algorithm depends on the data it pulls to make decisions, if you give it different data it might make different decisions. So you can't really say that the simulation is correct, right? The same algorithm on the same instrument might perform differently without this bug, right?

Also, can you point me to where this issue has been opened? I can't find it on zipline.