quantopian / zipline

Zipline, a Pythonic Algorithmic Trading Library
https://www.zipline.io
Apache License 2.0
17.28k stars 4.67k forks source link

create_continuous_future did not matching my volume #2812

Open yinjin1314 opened 3 years ago

yinjin1314 commented 3 years ago

Hello, i ingest the future data and they are good at datapotal,but the create_continuous_future in volume are strange,Please help..thank you.

bundle_name = 'future_data3' trading_calendar = get_calendar('XSHG')

bundle_data = bundles.load(bundle_name)

data = DataPortal(asset_finder= bundle_data.asset_finder, trading_calendar = trading_calendar, first_trading_day = bundle_data.equity_daily_bar_reader.first_trading_day, equity_minute_reader=None, equity_daily_reader=bundle_data.equity_daily_bar_reader, future_daily_reader=bundle_data.equity_daily_bar_reader, adjustment_reader=bundle_data.adjustment_reader)

continuous_future = bundle_data.asset_finder.create_continuous_future history = data.get_history_window

cl_contracts = [ bundle_data.asset_finder.lookup_future_symbol(x) for x in ['CUF16', 'CUG16', 'CUH16', 'CUJ16', 'CUK16', 'CUM16'] ]

start_dt = pd.Timestamp('2015-10-16', tz='UTC', offset='C') end_dt = pd.Timestamp('2016-5-16', tz='UTC', offset='C') end_loc = trading_calendar.closes.index.get_loc(end_dt) start_loc = trading_calendar.closes.index.get_loc(start_dt)

cl_consecutive_contract_volume = history( assets=cl_contracts, end_dt=end_dt, bar_count=end_loc - start_loc, frequency='1d', field='volume', data_frequency='daily' )

cl = continuous_future('CU', offset=0, roll_style='volume', adjustment='mul') ​ cl_continuous_volume = history( assets=[cl], end_dt=end_dt, bar_count=end_loc - start_loc, frequency='1d', field='volume', data_frequency='daily' ) cl_volume_history = pd.concat([cl_consecutive_contract_volume, cl_continuous_volume], axis=1) cl_volume_history.plot(style={cl: 'k--'}, figsize=(10,6)); 下载

Sutyke commented 3 years ago

Hey, quantopian stopped supporting this development, community forked this zipline repo and continues zipline-trader development, check out new release of zipline-trader 1.6.0 https://zipline-trader.readthedocs.io/en/latest/ maybe somebody would be able to help you there.