Skip to content

Commit

Permalink
Merge pull request #1586 from quantopian/fix-continuous-future-daily-…
Browse files Browse the repository at this point in the history
…get-value

BUG: Fix bad attribute lookup on session continuous future reader.
  • Loading branch information
ehebert committed Nov 8, 2016
2 parents b5d4df6 + 512e62b commit fa6e4fe
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
26 changes: 25 additions & 1 deletion tests/test_continuous_futures.py
Expand Up @@ -222,7 +222,7 @@ def test_current_contract(self):
'Auto close at beginning of session so FOG16 is now '
'the current contract.')

def test_get_spot_value_contract_daily(self):
def test_get_value_contract_daily(self):
cf_primary = self.asset_finder.create_continuous_future(
'FO', 0, 'calendar')

Expand All @@ -246,6 +246,30 @@ def test_get_spot_value_contract_daily(self):
'Auto close at beginning of session so FOG16 is now '
'the current contract.')

def test_get_value_close_daily(self):
cf_primary = self.asset_finder.create_continuous_future(
'FO', 0, 'calendar')

value = self.data_portal.get_spot_value(
cf_primary,
'close',
pd.Timestamp('2016-01-26', tz='UTC'),
'daily',
)

self.assertEqual(value, 105011.44)

value = self.data_portal.get_spot_value(
cf_primary,
'close',
pd.Timestamp('2016-01-27', tz='UTC'),
'daily',
)

self.assertEqual(value, 115021.44,
'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(
'FO', 0, 'volume')
Expand Down
2 changes: 1 addition & 1 deletion zipline/data/continuous_future_reader.py
Expand Up @@ -135,7 +135,7 @@ def get_value(self, continuous_future, dt, field):
If the given dt is not a valid market minute (in minute mode) or
session (in daily mode) according to this reader's tradingcalendar.
"""
rf = self._roll_finders[continuous_future.roll]
rf = self._roll_finders[continuous_future.roll_style]
sid = (rf.get_contract_center(continuous_future.root_symbol,
dt,
continuous_future.offset))
Expand Down
2 changes: 1 addition & 1 deletion zipline/data/resample.py
Expand Up @@ -541,7 +541,7 @@ def get_value(self, sid, session, colname):
# This was developed to complete interface, but has not been tuned
# for real world use.
start, end = self._calendar.open_and_close_for_session(session)
return self._get_resampled([colname], start, end, [sid])[0]
return self._get_resampled([colname], start, end, [sid])[0][0][0]

@lazyval
def sessions(self):
Expand Down

0 comments on commit fa6e4fe

Please sign in to comment.