mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-01 22:04:02 +08:00
MAINT: Removes unnecessary benchmark load on some TradingEnvironments
This commit is contained in:
@@ -5,12 +5,12 @@ Test case definitions for history tests.
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
from zipline.finance.trading import TradingEnvironment
|
||||
from zipline.finance.trading import TradingEnvironment, noop_load
|
||||
from zipline.history.history import HistorySpec
|
||||
from zipline.protocol import BarData
|
||||
from zipline.utils.test_utils import to_utc
|
||||
|
||||
_cases_env = TradingEnvironment()
|
||||
_cases_env = TradingEnvironment(load=noop_load)
|
||||
|
||||
|
||||
def mixed_frequency_expected_index(count, frequency):
|
||||
|
||||
+11
-13
@@ -40,7 +40,7 @@ from zipline.errors import (
|
||||
SidAssignmentError,
|
||||
RootSymbolNotFound,
|
||||
)
|
||||
from zipline.finance.trading import TradingEnvironment
|
||||
from zipline.finance.trading import TradingEnvironment, noop_load
|
||||
from zipline.utils.test_utils import (
|
||||
all_subindices,
|
||||
make_rotating_asset_info,
|
||||
@@ -253,7 +253,7 @@ class TestFuture(TestCase):
|
||||
notice_date=pd.Timestamp('2005-12-20', tz='UTC'),
|
||||
expiration_date=pd.Timestamp('2006-01-20', tz='UTC')
|
||||
)
|
||||
env = TradingEnvironment()
|
||||
env = TradingEnvironment(load=noop_load)
|
||||
env.write_data(futures_identifiers=[TestFuture.future,
|
||||
TestFuture.future2])
|
||||
cls.asset_finder = env.asset_finder
|
||||
@@ -334,7 +334,7 @@ class TestFuture(TestCase):
|
||||
class AssetFinderTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.env = TradingEnvironment()
|
||||
self.env = TradingEnvironment(load=noop_load)
|
||||
|
||||
def test_lookup_symbol_delimited(self):
|
||||
as_of = pd.Timestamp('2013-01-01', tz='UTC')
|
||||
@@ -550,7 +550,7 @@ class AssetFinderTestCase(TestCase):
|
||||
df['exchange'][0] = "NASDAQ"
|
||||
df['asset_name'][1] = "Microsoft"
|
||||
df['exchange'][1] = "NYSE"
|
||||
self.env = TradingEnvironment()
|
||||
self.env = TradingEnvironment(load=noop_load)
|
||||
self.env.write_data(equities_df=df)
|
||||
finder = AssetFinder(self.env.engine)
|
||||
self.assertEqual('NASDAQ', finder.retrieve_asset(0).exchange)
|
||||
@@ -729,20 +729,19 @@ class AssetFinderTestCase(TestCase):
|
||||
|
||||
def test_compute_lifetimes(self):
|
||||
num_assets = 4
|
||||
env = TradingEnvironment()
|
||||
trading_day = env.trading_day
|
||||
trading_day = self.env.trading_day
|
||||
first_start = pd.Timestamp('2015-04-01', tz='UTC')
|
||||
|
||||
frame = make_rotating_asset_info(
|
||||
num_assets=num_assets,
|
||||
first_start=first_start,
|
||||
frequency=env.trading_day,
|
||||
frequency=self.env.trading_day,
|
||||
periods_between_starts=3,
|
||||
asset_lifetime=5
|
||||
)
|
||||
|
||||
env.write_data(equities_df=frame)
|
||||
finder = env.asset_finder
|
||||
self.env.write_data(equities_df=frame)
|
||||
finder = self.env.asset_finder
|
||||
|
||||
all_dates = pd.date_range(
|
||||
start=first_start,
|
||||
@@ -790,9 +789,8 @@ class AssetFinderTestCase(TestCase):
|
||||
|
||||
def test_sids(self):
|
||||
# Ensure that the sids property of the AssetFinder is functioning
|
||||
env = TradingEnvironment()
|
||||
env.write_data(equities_identifiers=[1, 2, 3])
|
||||
sids = env.asset_finder.sids
|
||||
self.env.write_data(equities_identifiers=[1, 2, 3])
|
||||
sids = self.env.asset_finder.sids
|
||||
self.assertEqual(3, len(sids))
|
||||
self.assertTrue(1 in sids)
|
||||
self.assertTrue(2 in sids)
|
||||
@@ -834,7 +832,7 @@ class TestFutureChain(TestCase):
|
||||
'expiration_date': pd.Timestamp('2006-10-20', tz='UTC')}
|
||||
}
|
||||
|
||||
env = TradingEnvironment()
|
||||
env = TradingEnvironment(load=noop_load)
|
||||
env.write_data(futures_data=metadata)
|
||||
cls.asset_finder = env.asset_finder
|
||||
|
||||
|
||||
@@ -538,3 +538,14 @@ class SimulationParameters(object):
|
||||
emission_rate=self.emission_rate,
|
||||
first_open=self.first_open,
|
||||
last_close=self.last_close)
|
||||
|
||||
|
||||
def noop_load(*args, **kwargs):
|
||||
"""
|
||||
A method that can be substituted in as the load method in a
|
||||
TradingEnvironment to prevent it from loading benchmarks.
|
||||
|
||||
Accepts any arguments, but returns only a tuple of Nones regardless
|
||||
of input.
|
||||
"""
|
||||
return None, None
|
||||
|
||||
@@ -27,7 +27,9 @@ from zipline.protocol import Event, DATASOURCE_TYPE
|
||||
from zipline.sources import (SpecificEquityTrades,
|
||||
DataFrameSource,
|
||||
DataPanelSource)
|
||||
from zipline.finance.trading import SimulationParameters, TradingEnvironment
|
||||
from zipline.finance.trading import (
|
||||
SimulationParameters, TradingEnvironment, noop_load
|
||||
)
|
||||
from zipline.sources.test_source import create_trade
|
||||
|
||||
|
||||
@@ -40,19 +42,18 @@ __all__ = ['load_from_yahoo', 'load_bars_from_yahoo']
|
||||
|
||||
def create_simulation_parameters(year=2006, start=None, end=None,
|
||||
capital_base=float("1.0e5"),
|
||||
num_days=None, load=None,
|
||||
num_days=None,
|
||||
data_frequency='daily',
|
||||
emission_rate='daily',
|
||||
env=None):
|
||||
"""Construct a complete environment with reasonable defaults"""
|
||||
if env is None:
|
||||
env = TradingEnvironment(load=load)
|
||||
# Construct a complete environment with reasonable defaults
|
||||
env = TradingEnvironment(load=noop_load)
|
||||
if start is None:
|
||||
start = datetime(year, 1, 1, tzinfo=pytz.utc)
|
||||
if end is None:
|
||||
if num_days:
|
||||
start_index = env.trading_days.searchsorted(
|
||||
start)
|
||||
start_index = env.trading_days.searchsorted(start)
|
||||
end = env.trading_days[start_index + num_days - 1]
|
||||
else:
|
||||
end = datetime(year, 12, 31, tzinfo=pytz.utc)
|
||||
@@ -263,7 +264,7 @@ def create_test_df_source(sim_params=None, env=None, bars='daily'):
|
||||
index = sim_params.trading_days
|
||||
else:
|
||||
if env is None:
|
||||
env = TradingEnvironment()
|
||||
env = TradingEnvironment(load=noop_load)
|
||||
|
||||
start = pd.datetime(1990, 1, 3, 0, 0, 0, 0, pytz.utc)
|
||||
end = pd.datetime(1990, 1, 8, 0, 0, 0, 0, pytz.utc)
|
||||
@@ -294,7 +295,7 @@ def create_test_panel_source(sim_params=None, env=None, source_type=None):
|
||||
if sim_params else pd.datetime(1990, 1, 8, 0, 0, 0, 0, pytz.utc)
|
||||
|
||||
if env is None:
|
||||
env = TradingEnvironment()
|
||||
env = TradingEnvironment(load=noop_load)
|
||||
|
||||
index = env.days_in_range(start, end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user