MAINT: Add equity to naming of bar data classes.

In preparation of adding futures, add equity to the names of both the
classes and methods for writing bcolz data. Futures data will use a
different minutes per day with a separate reader. This change will allow
both equity and futures fixtures to be side by side.

Also, break out the method which generates the dataframes and trading
days member into fixtures (`EquityMinuteBarData` and
`EquityDailyBarData`) on which the `*BarReader` fixture depends.  This
fixture is separated out to enable reader/writers in different formats
to use the same data setup. (There is internal code which needs to write
minute and daily bar data in a database format.)
This commit is contained in:
Eddie Hebert
2016-06-30 08:21:42 -04:00
parent c89e957905
commit 51eda06323
22 changed files with 349 additions and 278 deletions
+4 -3
View File
@@ -111,7 +111,8 @@ _BundlePayload = namedtuple(
BundleData = namedtuple(
'BundleData',
'asset_finder minute_bar_reader daily_bar_reader adjustment_reader',
'asset_finder equity_minute_bar_reader equity_daily_bar_reader '
'adjustment_reader',
)
BundleCore = namedtuple(
@@ -443,10 +444,10 @@ def _make_bundle_core():
asset_finder=AssetFinder(
asset_db_path(name, timestr, environ=environ),
),
minute_bar_reader=BcolzMinuteBarReader(
equity_minute_bar_reader=BcolzMinuteBarReader(
minute_equity_path(name, timestr, environ=environ),
),
daily_bar_reader=BcolzDailyBarReader(
equity_daily_bar_reader=BcolzDailyBarReader(
daily_equity_path(name, timestr, environ=environ),
),
adjustment_reader=SQLiteAdjustmentReader(
+1 -1
View File
@@ -486,7 +486,7 @@ class DataPortal(object):
daily data backtests or daily history calls in a minute backetest.
If a daily bar reader is not provided but a minute bar reader is,
the minutes will be rolled up to serve the daily requests.
future_minute_reader : BcolzMinuteBarReader, optional
future_minute_reader : BcolzFutureMinuteBarReader, optional
The minute bar reader for futures. This will be used to service
minute data backtests or minute history calls. This can be used
to serve daily calls if no daily bar reader is provided.
+5 -5
View File
@@ -794,7 +794,7 @@ class SQLiteAdjustmentWriter(object):
----------
conn_or_path : str or sqlite3.Connection
A handle to the target sqlite database.
daily_bar_reader : BcolzDailyBarReader
equity_daily_bar_reader : BcolzDailyBarReader
Daily bar reader to use for dividend writes.
overwrite : bool, optional, default=False
If True and conn_or_path is a string, remove any existing files at the
@@ -807,7 +807,7 @@ class SQLiteAdjustmentWriter(object):
def __init__(self,
conn_or_path,
daily_bar_reader,
equity_daily_bar_reader,
calendar,
overwrite=False):
if isinstance(conn_or_path, sqlite3.Connection):
@@ -824,7 +824,7 @@ class SQLiteAdjustmentWriter(object):
else:
raise TypeError("Unknown connection type %s" % type(conn_or_path))
self._daily_bar_reader = daily_bar_reader
self._equity_daily_bar_reader = equity_daily_bar_reader
self._calendar = calendar
def _write(self, tablename, expected_dtypes, frame):
@@ -930,7 +930,7 @@ class SQLiteAdjustmentWriter(object):
ratios = full(len(amounts), nan)
daily_bar_reader = self._daily_bar_reader
equity_daily_bar_reader = self._equity_daily_bar_reader
effective_dates = full(len(amounts), -1, dtype=int64)
calendar = self._calendar
@@ -940,7 +940,7 @@ class SQLiteAdjustmentWriter(object):
day_loc = calendar.get_loc(ex_date, method='bfill')
prev_close_date = calendar[day_loc - 1]
try:
prev_close = daily_bar_reader.spot_price(
prev_close = equity_daily_bar_reader.spot_price(
sid, prev_close_date, 'close')
if prev_close != 0.0:
ratio = 1.0 - amount / prev_close