mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-08 04:00:31 +08:00
BUG: Allows 'contract' in get_spot_value with daily frequency (#1582)
Also removes duplicate check in test_current_contract.
This commit is contained in:
@@ -32,6 +32,7 @@ from zipline.assets.continuous_futures import OrderedContracts
|
||||
from zipline.data.minute_bars import FUTURES_MINUTES_PER_DAY
|
||||
from zipline.testing.fixtures import (
|
||||
WithCreateBarData,
|
||||
WithDataPortal,
|
||||
WithBcolzFutureMinuteBarReader,
|
||||
WithSimParams,
|
||||
ZiplineTestCase,
|
||||
@@ -39,6 +40,7 @@ from zipline.testing.fixtures import (
|
||||
|
||||
|
||||
class ContinuousFuturesTestCase(WithCreateBarData,
|
||||
WithDataPortal,
|
||||
WithSimParams,
|
||||
WithBcolzFutureMinuteBarReader,
|
||||
ZiplineTestCase):
|
||||
@@ -220,10 +222,29 @@ class ContinuousFuturesTestCase(WithCreateBarData,
|
||||
'Auto close at beginning of session so FOG16 is now '
|
||||
'the current contract.')
|
||||
|
||||
bar_data = self.create_bardata(
|
||||
lambda: pd.Timestamp('2016-01-27', tz='UTC'))
|
||||
contract = bar_data.current(cf_primary, 'contract')
|
||||
self.assertEqual(contract.symbol, 'FOG16')
|
||||
def test_get_spot_value_contract_daily(self):
|
||||
cf_primary = self.asset_finder.create_continuous_future(
|
||||
'FO', 0, 'calendar')
|
||||
|
||||
contract = self.data_portal.get_spot_value(
|
||||
cf_primary,
|
||||
'contract',
|
||||
pd.Timestamp('2016-01-26', tz='UTC'),
|
||||
'daily',
|
||||
)
|
||||
|
||||
self.assertEqual(contract.symbol, 'FOF16')
|
||||
|
||||
contract = self.data_portal.get_spot_value(
|
||||
cf_primary,
|
||||
'contract',
|
||||
pd.Timestamp('2016-01-27', tz='UTC'),
|
||||
'daily',
|
||||
)
|
||||
|
||||
self.assertEqual(contract.symbol, 'FOG16',
|
||||
'Auto close at beginning of session so FOG16 is now '
|
||||
'the current contract.')
|
||||
|
||||
def test_current_contract_volume_roll(self):
|
||||
cf_primary = self.asset_finder.create_continuous_future(
|
||||
|
||||
@@ -464,7 +464,10 @@ class DataPortal(object):
|
||||
return None
|
||||
|
||||
if data_frequency == "daily":
|
||||
return self._get_daily_spot_value(asset, field, session_label)
|
||||
if field == "contract":
|
||||
return self._get_current_contract(asset, session_label)
|
||||
else:
|
||||
return self._get_daily_spot_value(asset, field, session_label)
|
||||
else:
|
||||
if field == "last_traded":
|
||||
return self.get_last_traded_dt(asset, dt, 'minute')
|
||||
|
||||
Reference in New Issue
Block a user