I'm having two issues with data that I don't understand. I'm using the continuous contract of light sweet crude (CL)
I need to get the previous days open and close, and I think I am doing that properly in the algo below. What I don't understand is how the open and close prices never intersect.
In other words if the market closes at 60 on day 1, it should open at 60 on day 2. See the data below, and you will see there is no intersection.
Lastly, the data itself is a bit off from what I get in Tradestation (also checked on yahoo finance). What the heck am I doing wrong?
import numpy as np
import scipy as sp
from quantopian.algorithm import order_optimal_portfolio
import quantopian.optimize as opt
def initialize(context):
# Get continuous futures for Light Sweet Crude Oil...
context.crude_oil = continuous_future('CL', roll='calendar')
# Record Crude Oil and Gasoline Futures prices everyday
schedule_function(do_trading,
date_rules.every_day(),
time_rules.market_open())
def do_trading(context, data):
crude_oil_close = data.history(context.crude_oil, 'close', 2, "1d")
crude_oil_open = data.history(context.crude_oil, 'open', 2, "1d")
print 'close = ' + str(crude_oil_close)
print 'open = ' + str(crude_oil_open)
print ''
---------------------------Quantopian Algo Output---------------------------
2018-10-30 05:31 PRINT close = 2018-10-29 00:00:00+00:00 66.69
2018-10-30 00:00:00+00:00 66.67
Freq: C, Name: ContinuousFuture(90999980361318400 [CL, 0, calendar, mul]), dtype: float64
2018-10-30 05:31 PRINT open = 2018-10-29 00:00:00+00:00 67.51
2018-10-30 00:00:00+00:00 66.70
Freq: C, Name: ContinuousFuture(90999980361318400 [CL, 0, calendar, mul]), dtype: float64
2018-10-31 05:31 PRINT close = 2018-10-30 00:00:00+00:00 66.34
2018-10-31 00:00:00+00:00 66.34
Freq: C, Name: ContinuousFuture(90999980361318400 [CL, 0, calendar, mul]), dtype: float64
2018-10-31 05:31 PRINT open = 2018-10-30 00:00:00+00:00 66.70
2018-10-31 00:00:00+00:00 66.28
Freq: C, Name: ContinuousFuture(90999980361318400 [CL, 0, calendar, mul]), dtype: float64
2018-11-01 05:31 PRINT close = 2018-10-31 00:00:00+00:00 64.86
2018-11-01 00:00:00+00:00 64.77
Freq: C, Name: ContinuousFuture(90999980361318400 [CL, 0, calendar, mul]), dtype: float64
2018-11-01 05:31 PRINT open = 2018-10-31 00:00:00+00:00 66.28
2018-11-01 00:00:00+00:00 64.98
Freq: C, Name: ContinuousFuture(90999980361318400 [CL, 0, calendar, mul]), dtype: float64
2018-11-02 05:31 PRINT close = 2018-11-01 00:00:00+00:00 63.54
2018-11-02 00:00:00+00:00 63.64
Freq: C, Name: ContinuousFuture(90999980361318400 [CL, 0, calendar, mul]), dtype: float64
2018-11-02 05:31 PRINT open = 2018-11-01 00:00:00+00:00 64.98
2018-11-02 00:00:00+00:00 63.52
Freq: C, Name: ContinuousFuture(90999980361318400 [CL, 0, calendar, mul]), dtype: float64
---------------------------End Quantopian Algo Output---------------------------
---------------------------Tradestation Data (close)---------------------------
10/30/2018 3:00:00 PM - 60.19
10/31/2018 3:00:00 PM - 59.55
11/1/2018 3:00:00 PM - 60.08
11/2/2018 3:00:00 PM - 60.29
---------------------------End Tradestation Data---------------------------