Error fetching current price data from custom Zipline bundle

data.current and data.history functions fail to read price data from Zipline bundle ingested from custom history database.

Steps:

  1. Create custom database
    quantrocket history create-custom-db 'custom-etf-1d' --bar-size '1 day' --columns 'Open:float' 'High:float' 'Low:float' 'Close:float' 'Volume:int'

  2. Insert data to custom database ('Close' field only, other fields are NULL).

  3. Create zipline bundle from custom history DB:

zipline.create_bundle_from_db(code='custom-etf-1d-bundle',
from_db='custom-etf-1d',
calendar='XNYS',
start_date='1993-01-29',
sids=etf_sec['Sid'].to_list(),
fields={
"close": "Close",
"open": "Open",
"high": "High",
"low": "Low",
"volume": "Volume"})

  1. Ingest bundle:
    zipline.ingest_bundle('custom-etf-1d-bundle')

  2. Read data from bundle via pipeline:

pipeline = Pipeline(
columns={
"Close": USEquityPricing.close.latest,
})
bpr = run_pipeline(pipeline, bundle='custom-etf-1d-bundle', start_date="2021-07-12")
bpr.head()

	Close

2021-07-12 00:00:00+00:00 Equity(FIBBG000BDTBL9 [SPY]) 435.520
Equity(FIBBG000BJKYW3 [TLT]) 146.352
2021-07-13 00:00:00+00:00 Equity(FIBBG000BDTBL9 [SPY]) 437.080
Equity(FIBBG000BJKYW3 [TLT]) 146.162
2021-07-14 00:00:00+00:00 Equity(FIBBG000BDTBL9 [SPY]) 435.590

  1. Get current data from bundle via data.current (FAIL!)
    from zipline.research import get_data
    data = get_data("2021-07-12 15:59:00", bundle=bndl)
    data.current(sid('FIBBG000BJKYW3'), 'close')

ERROR LOG:
SidsNotFound Traceback (most recent call last)
in
1 from zipline.research import get_data
2 data = get_data("2021-07-12 15:59:00", bundle=bndl)
----> 3 data.current(sid('FIBBG000BJKYW3'), 'close')

/opt/conda/lib/python3.8/site-packages/zipline/_protocol.pyx in zipline._protocol.check_parameters.call.assert_keywords_and_call()

/opt/conda/lib/python3.8/site-packages/zipline/_protocol.pyx in zipline._protocol.BarData.current()

/opt/conda/lib/python3.8/site-packages/zipline/data/data_portal.py in get_spot_value(self, assets, field, dt, data_frequency)
408
409 if assets_is_scalar:
--> 410 return self._get_single_asset_value(
411 session_label,
412 assets,

/opt/conda/lib/python3.8/site-packages/zipline/data/data_portal.py in _get_single_asset_value(self, session_label, asset, field, dt, data_frequency)
349 return self._get_current_contract(asset, session_label)
350 else:
--> 351 return self._get_daily_spot_value(
352 asset, field, session_label,
353 )

/opt/conda/lib/python3.8/site-packages/zipline/data/data_portal.py in _get_daily_spot_value(self, asset, column, dt)
629 # don't forward fill
630 try:
--> 631 return reader.get_value(asset, dt, column)
632 except NoDataOnDate:
633 return np.nan

/opt/conda/lib/python3.8/site-packages/zipline/data/dispatch_bar_reader.py in get_value(self, sid, dt, field)
96
97 def get_value(self, sid, dt, field):
---> 98 asset = self._asset_finder.retrieve_asset(sid)
99 r = self._readers[type(asset)]
100 return r.get_value(asset, dt, field)

/opt/conda/lib/python3.8/site-packages/zipline/assets/assets.py in retrieve_asset(self, sid, default_none)
421 asset = self._asset_cache[sid]
422 if asset is None and not default_none:
--> 423 raise SidsNotFound(sids=[sid])
424 return asset
425 except KeyError:

SidsNotFound: No asset found for sid: Equity(FIBBG000BJKYW3 [TLT]).

Is “bndl” set as your default bundle? If not, this is expected to fail because your sid() call does not specify a bundle so it is using the default bundle, and you can’t use a sid from one bundle to look up data in another bundle (even if it’s the same sid in both bundles). Try data.current(sid('FIBBG000BJKYW3', bundle='bndl'), 'close').

1 Like