Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
continuous future error

When running this code I get an error which is quite strange, since PL1 has end and start date within the range used in history. Is this a bug of continuous future?

PL0=continuous_future('PL', offset=0, roll='volume', adjustment='mul')
PL1=continuous_future('PL', offset=1, roll='volume', adjustment='mul')
List=[PL0,PL1]
print map(lambda x: [x.start_date,x.end_date], List)
dateI='2017-04-01'
dateF='2018-04-01'
print history(
PL0,
fields='close_price',
frequency='daily',
start=dateI,
end=dateF).head(1)
print history(
PL1,
fields='close_price',
frequency='daily',
start=dateI,
end=dateF).head(1)

With PL0 there is not problem, PL1 gives the error below

OUTPUT

[[Timestamp('2007-09-24 00:00:00+0000', tz='UTC'), Timestamp('2018-04-13 00:00:00+0000', tz='UTC')], [Timestamp('2007-09-24 00:00:00+0000', tz='UTC'), Timestamp('2018-04-13 00:00:00+0000', tz='UTC')]] 2017-04-03 00:00:00+00:00 977.1
Freq: C, Name: ContinuousFuture(94659155075334144 [PL, 0, volume, mul]), dtype: float64

AttributeErrorTraceback (most recent call last)
in ()
16 frequency='daily',
17 start=dateI,
---> 18 end=dateF).head(1)

/build/src/qexec_repo/qexec/research/api.py in history(symbols, fields, start, end, frequency, symbol_reference_date, handle_missing, start_offset) 537 findata_dir=findata_dir,
538 user_id=user_id,
--> 539 start_offset=start_offset,
540 )
541

/build/src/qexec_repo/qexec/research/_api.pyc in inner_history(symbols, fields, frequency, start, end, symbol_reference_date, handle_missing, asset_data_dir, findata_dir, user_id, start_offset) 691 findata_dir=findata_dir,
692 user_id=user_id,
--> 693 start_offset=start_offset,
694 )
695

/build/src/qexec_repo/qexec/research/_api.pyc in inner_get_pricing(symbols, start_date, end_date, symbol_reference_date, frequency, fields, handle_missing, asset_data_dir, findata_dir, user_id, start_offset) 555
556 asset_specific_data = _get_pricing_internal(
--> 557 data_portal, assets, pinched_start, pinched_end, frequency, fields,
558 )
559

/build/src/qexec_repo/qexec/research/trades.pyc in _get_pricing_internal(data_portal, assets, start_date, end_date, frequency, fields) 109 start_date=ensure_timestamp(start_date),
110 end_date=ensure_timestamp(end_date),
--> 111 data_frequency=frequency,
112 )
113

/build/src/qexec_repo/qexec/research/trades.pyc in ohlcv_panel_from_source(data_portal, sids, start_date, end_date, data_frequency, fields) 183 freq,
184 _field,
--> 185 data_frequency,
186 )
187 # For date_indexes which extend past the last available dt, reindex

/build/src/qexec_repo/zipline_repo/zipline/data/data_portal.pyc in get_history_window(self, assets, end_dt, bar_count, frequency, field, data_frequency, ffill) 958 else:
959 df = self._get_history_daily_window(assets, end_dt, bar_count,
--> 960 field, data_frequency)
961 elif frequency == "1m":
962 if field == "price":

/build/src/qexec_repo/zipline_repo/zipline/data/data_portal.pyc in _get_history_daily_window(self, assets, end_dt, bar_count, field_to_use, data_frequency) 802
803 data = self._get_history_daily_window_data(
--> 804 assets, days_for_window, end_dt, field_to_use, data_frequency
805 )
806 return pd.DataFrame(

/build/src/qexec_repo/zipline_repo/zipline/data/data_portal.pyc in _get_history_daily_window_data(self, assets, days_for_window, end_dt, field_to_use, data_frequency) 825 field_to_use,
826 days_for_window,
--> 827 extra_slot=False
828 )
829 else:

/build/src/qexec_repo/zipline_repo/zipline/data/data_portal.pyc in _get_daily_window_data(self, assets, field, days_in_window, extra_slot) 1108 days_in_window,
1109 field,
-> 1110 extra_slot)
1111 if extra_slot:
1112 return_array[:len(return_array) - 1, :] = data

/build/src/qexec_repo/zipline_repo/zipline/data/history_loader.pyc in history(self, assets, dts, field, is_perspective_after) 548 dts,
549 field,
--> 550 is_perspective_after)
551 end_ix = self._calendar.searchsorted(dts[-1])
552

/build/src/qexec_repo/zipline_repo/zipline/data/history_loader.pyc in _ensure_sliding_windows(self, assets, dts, field, is_perspective_after) 430 adj_dts = prefetch_dts
431 prefetch_len = len(prefetch_dts)
--> 432 array = self._array(prefetch_dts, needed_assets, field)
433
434 if field == 'sid':

/build/src/qexec_repo/zipline_repo/zipline/data/history_loader.pyc in _array(self, dts, assets, field) 572 dts[0],
573 dts[-1],
--> 574 assets,
575 )[0]
576

/build/src/qexec_repo/zipline_repo/zipline/data/dispatch_bar_reader.pyc in load_raw_arrays(self, fields, start_dt, end_dt, sids) 118 end_dt,
119 sid_groups[t])
--> 120 for t in asset_types if sid_groups[t]}
121
122 results = []

/build/src/qexec_repo/zipline_repo/zipline/data/dispatch_bar_reader.pyc in ((t,)) 118 end_dt,
119 sid_groups[t])
--> 120 for t in asset_types if sid_groups[t]}
121
122 results = []

/build/src/qexec_repo/zipline_repo/zipline/data/continuous_future_reader.pyc in load_raw_arrays(self, columns, start_date, end_date, assets) 37 start_date,
38 end_date,
---> 39 asset.offset
40 )
41

/build/src/qexec_repo/zipline_repo/zipline/assets/roll_finder.pyc in get_rolls(self, root_symbol, start, end, offset) 97 first = front
98 first_contract = oc.sid_to_contract[first]
---> 99 rolls = [((first_contract >> offset).contract.sid, None)]
100 tc = self.trading_calendar
101 sessions = tc.sessions_in_range(tc.minute_to_session_label(start),

AttributeError: 'NoneType' object has no attribute 'contract'

7 responses

Did you ever figure this one out? I'm getting the same error.

Hi
I do not remember anymore. I think I ended up excluding some futures or offsets, but I forgot based on what criteria.It could be that some offset are incomplete.

Thanks. Think I'll just use a different data source.

Hi
what other datasets are available for futures on quantopian? As far as I know this is the only one

Sorry, not on Quantopian. Meant from Bloomberg.

I see. I guess you have an account with Bloomberg.
Do you fetch the data on Quantopian or run zipline locally on your locally downloaded data?
Now I think I remember I was catching the error and avoiding the symbols/offsets combinations giving problems.
I am not sure that is the quality of the Quantopian data. Since futures are not included in the contest probably the quality of this data is not a high priority

With that little data to use, have to agree that it doesn't seem like a priority....Best of luck with your work.