Skip to content

Commit

Permalink
MAINT: DataPortal env -> asset_finder
Browse files Browse the repository at this point in the history
  • Loading branch information
jfkirk authored and Jean Bredeche committed Jun 8, 2016
1 parent 53fcdde commit 2a8f69f
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 62 deletions.
3 changes: 1 addition & 2 deletions tests/data/test_minute_bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
US_EQUITIES_MINUTES_PER_DAY,
BcolzMinuteWriterColumnMismatch
)
from zipline.utils.calendars import get_calendar

from zipline.testing.fixtures import (
WithInstanceTmpDir,
Expand All @@ -63,7 +62,7 @@ class BcolzMinuteBarTestCase(WithTradingSchedule, WithInstanceTmpDir,
@classmethod
def init_class_fixtures(cls):
super(BcolzMinuteBarTestCase, cls).init_class_fixtures()
trading_days = get_calendar('NYSE').trading_days(
trading_days = cls.trading_schedule.trading_sessions(
TEST_CALENDAR_START, TEST_CALENDAR_STOP
)
cls.market_opens = trading_days.market_open
Expand Down
4 changes: 2 additions & 2 deletions tests/finance/test_slippage.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_volume_share_slippage(self):
with tmp_bcolz_minute_bar_reader(self.trading_schedule, days, assets) \
as reader:
data_portal = DataPortal(
self.env, self.trading_schedule,
self.env.asset_finder, self.trading_schedule,
first_trading_day=reader.first_trading_day,
equity_minute_reader=reader,
)
Expand Down Expand Up @@ -484,7 +484,7 @@ def test_orders_stop(self, name, order_data, event_data, expected):
with tmp_bcolz_minute_bar_reader(self.trading_schedule, days, assets) \
as reader:
data_portal = DataPortal(
self.env, self.trading_schedule,
self.env.asset_finder, self.trading_schedule,
first_trading_day=reader.first_trading_day,
equity_minute_reader=reader,
)
Expand Down
18 changes: 9 additions & 9 deletions tests/test_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ def test_minute_data(self, algo_class):
)

data_portal = create_data_portal(
env,
env.asset_finder,
tempdir,
sim_params,
equities.index,
Expand Down Expand Up @@ -1556,8 +1556,8 @@ def handle_data(context, data):
trades = factory.create_daily_trade_source(
[0], self.sim_params, self.env, self.trading_schedule)
data_portal = create_data_portal_from_trade_history(
self.env, self.trading_schedule, tempdir, self.sim_params,
{0: trades})
self.env.asset_finder, self.trading_schedule, tempdir,
self.sim_params, {0: trades})
results = test_algo.run(data_portal)

all_txns = [
Expand Down Expand Up @@ -2727,7 +2727,7 @@ def test_set_max_order_count(self):
)

data_portal = create_data_portal(
env,
env.asset_finder,
tempdir,
sim_params,
[1],
Expand Down Expand Up @@ -2849,7 +2849,7 @@ def test_asset_date_bounds(self):
env=env,
)
data_portal = create_data_portal(
env,
env.asset_finder,
tempdir,
self.sim_params,
[0],
Expand All @@ -2864,7 +2864,7 @@ def test_asset_date_bounds(self):
with TempDirectory() as tempdir, \
tmp_trading_env(equities=metadata) as env:
data_portal = create_data_portal(
env,
env.asset_finder,
tempdir,
self.sim_params,
[0],
Expand All @@ -2884,7 +2884,7 @@ def test_asset_date_bounds(self):
with TempDirectory() as tempdir, \
tmp_trading_env(equities=metadata) as env:
data_portal = create_data_portal(
env,
env.asset_finder,
tempdir,
self.sim_params,
[0],
Expand Down Expand Up @@ -3454,7 +3454,7 @@ def make_data(self, auto_close_delta, frequency,
)
reader = BcolzDailyBarReader(path)
data_portal = DataPortal(
env, self.trading_schedule,
env.asset_finder, self.trading_schedule,
first_trading_day=reader.first_trading_day,
equity_daily_reader=reader,
)
Expand Down Expand Up @@ -3484,7 +3484,7 @@ def make_data(self, auto_close_delta, frequency,
)
reader = BcolzMinuteBarReader(self.tmpdir.path)
data_portal = DataPortal(
env, self.trading_schedule,
env.asset_finder, self.trading_schedule,
first_trading_day=reader.first_trading_day,
equity_minute_reader=reader,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def test_asset_IPOed_same_day(self):
)
with tmp_reader as reader:
data_portal = DataPortal(
self.env, self.trading_schedule,
self.env.asset_finder, self.trading_schedule,
first_trading_day=reader.first_trading_day,
equity_minute_reader=reader,
equity_daily_reader=self.bcolz_daily_bar_reader,
Expand Down
3 changes: 2 additions & 1 deletion tests/test_data_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class TestDataPortal(WithTradingEnvironment, ZiplineTestCase):
def init_instance_fixtures(self):
super(TestDataPortal, self).init_instance_fixtures()

self.data_portal = DataPortal(self.env, self.trading_schedule,
self.data_portal = DataPortal(self.env.asset_finder,
self.trading_schedule,
first_trading_day=None)

def test_bar_count_for_simple_transforms(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_finance.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def transaction_sim(self, **params):
equity_minute_reader = BcolzMinuteBarReader(tempdir.path)

data_portal = DataPortal(
env, self.trading_schedule,
env.asset_finder, self.trading_schedule,
first_trading_day=equity_minute_reader.first_trading_day,
equity_minute_reader=equity_minute_reader,
)
Expand Down Expand Up @@ -254,7 +254,7 @@ def transaction_sim(self, **params):
equity_daily_reader = BcolzDailyBarReader(path)

data_portal = DataPortal(
env, self.trading_schedule,
env.asset_finder, self.trading_schedule,
first_trading_day=equity_daily_reader.first_trading_day,
equity_daily_reader=equity_daily_reader,
)
Expand Down
40 changes: 20 additions & 20 deletions tests/test_perf_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def test_split_long_position(self):
# set up a long position in sid 1
# 100 shares at $20 apiece = $2000 position
data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.tmpdir,
self.sim_params,
Expand Down Expand Up @@ -456,7 +456,7 @@ def test_long_position_receives_dividend(self):
writer.write(splits, mergers, dividends)
adjustment_reader = SQLiteAdjustmentReader(dbpath)
data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.instance_tmpdir,
self.sim_params,
Expand Down Expand Up @@ -533,7 +533,7 @@ def test_long_position_receives_stock_dividend(self):
adjustment_reader = SQLiteAdjustmentReader(dbpath)

data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.instance_tmpdir,
self.sim_params,
Expand Down Expand Up @@ -598,7 +598,7 @@ def test_long_position_purchased_on_ex_date_receives_no_dividend(self):
adjustment_reader = SQLiteAdjustmentReader(dbpath)

data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.instance_tmpdir,
self.sim_params,
Expand Down Expand Up @@ -660,7 +660,7 @@ def test_selling_before_dividend_payment_still_gets_paid(self):
adjustment_reader = SQLiteAdjustmentReader(dbpath)

data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.instance_tmpdir,
self.sim_params,
Expand Down Expand Up @@ -723,7 +723,7 @@ def test_buy_and_sell_before_ex(self):
adjustment_reader = SQLiteAdjustmentReader(dbpath)

data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.instance_tmpdir,
self.sim_params,
Expand Down Expand Up @@ -790,7 +790,7 @@ def test_ending_before_pay_date(self):
adjustment_reader = SQLiteAdjustmentReader(dbpath)

data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.instance_tmpdir,
self.sim_params,
Expand Down Expand Up @@ -852,7 +852,7 @@ def test_short_position_pays_dividend(self):
adjustment_reader = SQLiteAdjustmentReader(dbpath)

data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.instance_tmpdir,
self.sim_params,
Expand Down Expand Up @@ -911,7 +911,7 @@ def test_no_position_receives_no_dividend(self):
adjustment_reader = SQLiteAdjustmentReader(dbpath)

data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.instance_tmpdir,
self.sim_params,
Expand Down Expand Up @@ -981,7 +981,7 @@ def test_no_dividend_at_simulation_end(self):
sim_params.update_internal_from_trading_schedule(self.trading_schedule)

data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.instance_tmpdir,
sim_params,
Expand Down Expand Up @@ -1085,7 +1085,7 @@ def test_long_short_positions(self):
)

data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.instance_tmpdir,
self.sim_params,
Expand Down Expand Up @@ -1182,7 +1182,7 @@ def test_levered_long_position(self):
)

data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.instance_tmpdir,
self.sim_params,
Expand Down Expand Up @@ -1274,7 +1274,7 @@ def test_long_position(self):
)

data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.instance_tmpdir,
self.sim_params,
Expand Down Expand Up @@ -1392,7 +1392,7 @@ def test_short_position(self):
trades_1 = trades[:-2]

data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.instance_tmpdir,
self.sim_params,
Expand Down Expand Up @@ -1624,7 +1624,7 @@ def test_long_future_position(self):
)

data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.instance_tmpdir,
self.sim_params,
Expand Down Expand Up @@ -1744,7 +1744,7 @@ def test_short_future_position(self):
)

data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.instance_tmpdir,
self.sim_params,
Expand Down Expand Up @@ -1989,7 +1989,7 @@ def test_covering_short(self):
)

data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.instance_tmpdir,
self.sim_params,
Expand Down Expand Up @@ -2078,7 +2078,7 @@ def test_cost_basis_calc(self):
transactions = factory.create_txn_history(*history_args)[:4]

data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.instance_tmpdir,
self.sim_params,
Expand Down Expand Up @@ -2238,7 +2238,7 @@ def test_capital_change_intra_period(self):
)

data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.instance_tmpdir,
self.sim_params,
Expand Down Expand Up @@ -2283,7 +2283,7 @@ def test_capital_change_inter_period(self):
)

data_portal = create_data_portal_from_trade_history(
self.env,
self.env.asset_finder,
self.trading_schedule,
self.instance_tmpdir,
self.sim_params,
Expand Down
8 changes: 4 additions & 4 deletions tests/test_security_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ def init_class_fixtures(cls):
cls.tempdir2 = cls.enter_class_context(tmp_dir())

cls.data_portal = create_data_portal(
env=cls.env,
asset_finder=cls.env.asset_finder,
tempdir=cls.tempdir,
sim_params=cls.sim_params,
sids=range(0, 5),
trading_schedule=cls.trading_schedule,
)

cls.data_portal2 = create_data_portal(
env=cls.env2,
asset_finder=cls.env2.asset_finder,
tempdir=cls.tempdir2,
sim_params=cls.sim_params2,
sids=range(0, 5),
Expand Down Expand Up @@ -221,7 +221,7 @@ def test_algo_with_rl_violation_after_knowledge_date(self):
LEVERAGED_ETFS.keys())[0] + timedelta(days=7), num_days=5)

data_portal = create_data_portal(
self.env,
self.env.asset_finder,
self.tempdir,
sim_params=sim_params,
sids=range(0, 5),
Expand Down Expand Up @@ -273,7 +273,7 @@ def test_algo_without_rl_violation_after_delete(self):
add_security_data([], ['BZQ'])

data_portal = create_data_portal(
env,
env.asset_finder,
new_tempdir,
sim_params,
range(0, 5),
Expand Down
2 changes: 1 addition & 1 deletion zipline/_protocol.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ cdef class BarData:
view = self._views[asset]
except KeyError:
try:
asset = self.data_portal.env.asset_finder.retrieve_asset(asset)
asset = self.data_portal.asset_finder.retrieve_asset(asset)
except ValueError:
# assume fetcher
pass
Expand Down
4 changes: 2 additions & 2 deletions zipline/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def run(self, data=None, overwrite_sim_params=True):
copy_panel.items, copy_panel.major_axis[0],
)
self._assets_from_source = (
self.trading_environment.asset_finder.retrieve_all(
self.asset_finder.retrieve_all(
copy_panel.items
)
)
Expand All @@ -641,7 +641,7 @@ def run(self, data=None, overwrite_sim_params=True):
copy_panel,
)
self.data_portal = DataPortal(
self.trading_environment,
self.asset_finder,
self.trading_schedule,
first_trading_day=equity_daily_reader.first_trading_day,
equity_daily_reader=equity_daily_reader,
Expand Down
Loading

0 comments on commit 2a8f69f

Please sign in to comment.