MAINT: Standardize reader get value methods.

The daily/session bar reader's `spot_price` took the same parameters and
returned the same kind of output as the minute bar reader's `get_value`.

Standardize on one method to make a common interface, which may be
formally factored out in a later patch; to help enable writing reader
implementations or mixins which can be agnostic to the bar frequency.
This commit is contained in:
Eddie Hebert
2016-08-24 12:46:36 -04:00
parent 20f9241252
commit a3c1f4ce36
10 changed files with 38 additions and 40 deletions
+2 -2
View File
@@ -521,7 +521,7 @@ class DataPortal(object):
elif column in OHLCV_FIELDS:
# don't forward fill
try:
val = reader.spot_price(asset, dt, column)
val = reader.get_value(asset, dt, column)
if val == -1:
if column == "volume":
return 0
@@ -535,7 +535,7 @@ class DataPortal(object):
found_dt = dt
while True:
try:
value = reader.spot_price(
value = reader.get_value(
asset, found_dt, "close"
)
if value != -1:
+1 -1
View File
@@ -476,7 +476,7 @@ class MinuteResampleSessionBarReader(SessionBarReader):
def load_raw_arrays(self, columns, start_dt, end_dt, assets):
return self._get_resampled(columns, start_dt, end_dt, assets).values
def spot_price(self, sid, session, colname):
def get_value(self, sid, session, colname):
# WARNING: This will need caching or other optimization if used in a
# tight loop.
# This was developed to complete interface, but has not been tuned
+1 -1
View File
@@ -43,7 +43,7 @@ class SessionBarReader(with_metaclass(ABCMeta)):
pass
@abstractmethod
def spot_price(self, sid, session, colname):
def get_value(self, sid, session, colname):
"""
Retrieve the value at the given coordinates.
+3 -5
View File
@@ -686,7 +686,7 @@ class BcolzDailyBarReader(SessionBarReader):
day, sid))
return ix
def spot_price(self, sid, day, colname):
def get_value(self, sid, day, colname):
"""
Parameters
----------
@@ -787,7 +787,7 @@ class PanelBarReader(SessionBarReader):
list(columns)
].reindex(major_axis=cal[cal.slice_indexer(start_dt, end_dt)]).values.T
def spot_price(self, sid, dt, colname):
def get_value(self, sid, dt, colname):
"""
Parameters
----------
@@ -809,8 +809,6 @@ class PanelBarReader(SessionBarReader):
"""
return self.panel.loc[sid, dt, colname]
get_value = spot_price
def get_last_traded_dt(self, sid, dt):
"""
Parameters
@@ -985,7 +983,7 @@ class SQLiteAdjustmentWriter(object):
day_loc = calendar.get_loc(ex_date, method='bfill')
prev_close_date = calendar[day_loc - 1]
try:
prev_close = equity_daily_bar_reader.spot_price(
prev_close = equity_daily_bar_reader.get_value(
sid, prev_close_date, 'close')
if prev_close != 0.0:
ratio = 1.0 - amount / prev_close