mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-08 01:20:58 +08:00
TST: Refactors more tests to use WithTradingSchedule
This commit is contained in:
@@ -15,8 +15,6 @@
|
||||
from datetime import timedelta
|
||||
import os
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
from numpy import (
|
||||
arange,
|
||||
array,
|
||||
@@ -45,7 +43,9 @@ from zipline.data.minute_bars import (
|
||||
US_EQUITIES_MINUTES_PER_DAY,
|
||||
BcolzMinuteWriterColumnMismatch
|
||||
)
|
||||
from zipline.utils.calendars import get_calendar, default_nyse_schedule
|
||||
from zipline.utils.calendars import get_calendar
|
||||
|
||||
from zipline.testing.fixtures import WithTradingSchedule, ZiplineTestCase
|
||||
|
||||
# Calendar is set to cover several half days, to check a case where half
|
||||
# days would be read out of order in cases of windows which spanned over
|
||||
@@ -54,10 +54,11 @@ TEST_CALENDAR_START = Timestamp('2014-06-02', tz='UTC')
|
||||
TEST_CALENDAR_STOP = Timestamp('2015-12-31', tz='UTC')
|
||||
|
||||
|
||||
class BcolzMinuteBarTestCase(TestCase):
|
||||
class BcolzMinuteBarTestCase(WithTradingSchedule, ZiplineTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
def init_class_fixtures(cls):
|
||||
super(BcolzMinuteBarTestCase, cls).init_class_fixtures()
|
||||
trading_days = get_calendar('NYSE').trading_days(
|
||||
TEST_CALENDAR_START, TEST_CALENDAR_STOP
|
||||
)
|
||||
@@ -66,10 +67,15 @@ class BcolzMinuteBarTestCase(TestCase):
|
||||
cls.test_calendar_start = cls.market_opens.index[0]
|
||||
cls.test_calendar_stop = cls.market_opens.index[-1]
|
||||
|
||||
def setUp(self):
|
||||
def dir_cleanup(self):
|
||||
self.dir_.cleanup()
|
||||
|
||||
def init_instance_fixtures(self):
|
||||
super(BcolzMinuteBarTestCase, self).init_instance_fixtures()
|
||||
|
||||
self.dir_ = TempDirectory()
|
||||
self.dir_.create()
|
||||
self.add_instance_callback(callback=self.dir_cleanup)
|
||||
self.dest = self.dir_.getpath('minute_bars')
|
||||
os.makedirs(self.dest)
|
||||
self.writer = BcolzMinuteBarWriter(
|
||||
@@ -81,9 +87,6 @@ class BcolzMinuteBarTestCase(TestCase):
|
||||
)
|
||||
self.reader = BcolzMinuteBarReader(self.dest)
|
||||
|
||||
def tearDown(self):
|
||||
self.dir_.cleanup()
|
||||
|
||||
def test_write_one_ohlcv(self):
|
||||
minute = self.market_opens[self.test_calendar_start]
|
||||
sid = 1
|
||||
@@ -798,9 +801,9 @@ class BcolzMinuteBarTestCase(TestCase):
|
||||
data = {sids[0]: data_1, sids[1]: data_2}
|
||||
|
||||
start_minute_loc = \
|
||||
default_nyse_schedule.all_execution_minutes.get_loc(minutes[0])
|
||||
self.trading_schedule.all_execution_minutes.get_loc(minutes[0])
|
||||
minute_locs = [
|
||||
default_nyse_schedule.all_execution_minutes.get_loc(minute)
|
||||
self.trading_schedule.all_execution_minutes.get_loc(minute)
|
||||
- start_minute_loc
|
||||
for minute in minutes
|
||||
]
|
||||
@@ -822,7 +825,7 @@ class BcolzMinuteBarTestCase(TestCase):
|
||||
'close': arange(1, 781),
|
||||
'volume': arange(1, 781)
|
||||
}
|
||||
dts = array(default_nyse_schedule.execution_minutes_for_days_in_range(
|
||||
dts = array(self.trading_schedule.execution_minutes_for_days_in_range(
|
||||
start_day, end_day
|
||||
))
|
||||
self.writer.write_cols(sid, dts, cols)
|
||||
@@ -866,7 +869,7 @@ class BcolzMinuteBarTestCase(TestCase):
|
||||
'close': arange(1, 601),
|
||||
'volume': arange(1, 601)
|
||||
}
|
||||
dts = array(default_nyse_schedule.execution_minutes_for_days_in_range(
|
||||
dts = array(self.trading_schedule.execution_minutes_for_days_in_range(
|
||||
start_day, end_day
|
||||
))
|
||||
self.writer.write_cols(sid, dts, cols)
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
Base class for Pipeline API unittests.
|
||||
"""
|
||||
from functools import wraps
|
||||
from unittest import TestCase
|
||||
|
||||
import numpy as np
|
||||
from numpy import arange, prod
|
||||
@@ -18,10 +17,10 @@ from zipline.testing import (
|
||||
ExplodingObject,
|
||||
tmp_asset_finder,
|
||||
)
|
||||
from zipline.testing.fixtures import ZiplineTestCase, WithTradingSchedule
|
||||
|
||||
from zipline.utils.functional import dzip_exact
|
||||
from zipline.utils.pandas_utils import explode
|
||||
from zipline.utils.calendars import default_nyse_schedule
|
||||
|
||||
|
||||
def with_defaults(**default_funcs):
|
||||
@@ -51,12 +50,14 @@ def with_defaults(**default_funcs):
|
||||
with_default_shape = with_defaults(shape=lambda self: self.default_shape)
|
||||
|
||||
|
||||
class BasePipelineTestCase(TestCase):
|
||||
class BasePipelineTestCase(WithTradingSchedule, ZiplineTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
def init_class_fixtures(cls):
|
||||
super(BasePipelineTestCase, cls).init_class_fixtures()
|
||||
|
||||
cls.__calendar = date_range('2014', '2015',
|
||||
freq=default_nyse_schedule.day)
|
||||
freq=cls.trading_schedule.day)
|
||||
cls.__assets = assets = Int64Index(arange(1, 20))
|
||||
cls.__tmp_finder_ctx = tmp_asset_finder(
|
||||
equities=make_simple_equity_info(
|
||||
@@ -71,10 +72,6 @@ class BasePipelineTestCase(TestCase):
|
||||
include_start_date=False,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.__tmp_finder_ctx.__exit__()
|
||||
|
||||
@property
|
||||
def default_shape(self):
|
||||
"""Default shape for methods that build test data."""
|
||||
|
||||
@@ -85,7 +85,6 @@ from zipline.testing.fixtures import (
|
||||
ZiplineTestCase,
|
||||
)
|
||||
from zipline.utils.memoize import lazyval
|
||||
from zipline.utils.calendars import default_nyse_schedule
|
||||
|
||||
|
||||
class RollingSumDifference(CustomFactor):
|
||||
@@ -827,7 +826,7 @@ class FrameInputTestCase(WithTradingEnvironment, ZiplineTestCase):
|
||||
cls.dates = date_range(
|
||||
cls.start,
|
||||
cls.end,
|
||||
freq=default_nyse_schedule.day,
|
||||
freq=cls.trading_schedule.day,
|
||||
tz='UTC',
|
||||
)
|
||||
cls.assets = cls.asset_finder.retrieve_all(cls.asset_ids)
|
||||
@@ -986,7 +985,7 @@ class SyntheticBcolzTestCase(WithAdjustmentReader,
|
||||
def test_SMA(self):
|
||||
engine = SimplePipelineEngine(
|
||||
lambda column: self.pipeline_loader,
|
||||
default_nyse_schedule.all_execution_days,
|
||||
self.trading_schedule.all_execution_days,
|
||||
self.asset_finder,
|
||||
)
|
||||
window_length = 5
|
||||
@@ -1040,7 +1039,7 @@ class SyntheticBcolzTestCase(WithAdjustmentReader,
|
||||
# valuable.
|
||||
engine = SimplePipelineEngine(
|
||||
lambda column: self.pipeline_loader,
|
||||
default_nyse_schedule.all_execution_days,
|
||||
self.trading_schedule.all_execution_days,
|
||||
self.asset_finder,
|
||||
)
|
||||
window_length = 5
|
||||
@@ -1084,7 +1083,7 @@ class ParameterizedFactorTestCase(WithTradingEnvironment, ZiplineTestCase):
|
||||
@classmethod
|
||||
def init_class_fixtures(cls):
|
||||
super(ParameterizedFactorTestCase, cls).init_class_fixtures()
|
||||
day = default_nyse_schedule.day
|
||||
day = cls.trading_schedule.day
|
||||
|
||||
cls.dates = dates = date_range(
|
||||
'2015-02-01',
|
||||
|
||||
@@ -89,8 +89,8 @@ for_each_factor_dtype = parameterized.expand([
|
||||
|
||||
class FactorTestCase(BasePipelineTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(FactorTestCase, self).setUp()
|
||||
def init_instance_fixtures(self):
|
||||
super(FactorTestCase, self).init_instance_fixtures()
|
||||
self.f = F()
|
||||
|
||||
def test_bad_input(self):
|
||||
|
||||
@@ -75,8 +75,8 @@ class Mask(Filter):
|
||||
|
||||
class FilterTestCase(BasePipelineTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(FilterTestCase, self).setUp()
|
||||
def init_instance_fixtures(self):
|
||||
super(FilterTestCase, self).init_instance_fixtures()
|
||||
self.f = SomeFactor()
|
||||
self.g = SomeOtherFactor()
|
||||
|
||||
|
||||
@@ -13,31 +13,24 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import unittest
|
||||
|
||||
import datetime
|
||||
import numpy as np
|
||||
import pytz
|
||||
import zipline.finance.risk as risk
|
||||
from zipline.utils import factory
|
||||
|
||||
from zipline.finance.trading import SimulationParameters, TradingEnvironment
|
||||
from zipline.utils.calendars import default_nyse_schedule
|
||||
from zipline.testing.fixtures import WithTradingEnvironment, ZiplineTestCase
|
||||
|
||||
from zipline.finance.trading import SimulationParameters
|
||||
from . import answer_key
|
||||
ANSWER_KEY = answer_key.ANSWER_KEY
|
||||
|
||||
|
||||
class TestRisk(unittest.TestCase):
|
||||
class TestRisk(WithTradingEnvironment, ZiplineTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.env = TradingEnvironment()
|
||||
def init_instance_fixtures(self):
|
||||
super(TestRisk, self).init_instance_fixtures()
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
del cls.env
|
||||
|
||||
def setUp(self):
|
||||
start_date = datetime.datetime(
|
||||
year=2006,
|
||||
month=1,
|
||||
@@ -51,7 +44,7 @@ class TestRisk(unittest.TestCase):
|
||||
self.sim_params = SimulationParameters(
|
||||
period_start=start_date,
|
||||
period_end=end_date,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
self.algo_returns_06 = factory.create_returns_from_list(
|
||||
@@ -62,7 +55,7 @@ class TestRisk(unittest.TestCase):
|
||||
self.cumulative_metrics_06 = risk.RiskMetricsCumulative(
|
||||
self.sim_params,
|
||||
treasury_curves=self.env.treasury_curves,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
for dt, returns in answer_key.RETURNS_DATA.iterrows():
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import unittest
|
||||
import datetime
|
||||
import calendar
|
||||
import numpy as np
|
||||
@@ -25,8 +24,8 @@ from six import itervalues
|
||||
import zipline.finance.risk as risk
|
||||
from zipline.utils import factory
|
||||
|
||||
from zipline.finance.trading import SimulationParameters, TradingEnvironment
|
||||
from zipline.utils.calendars import default_nyse_schedule
|
||||
from zipline.finance.trading import SimulationParameters
|
||||
from zipline.testing.fixtures import WithTradingEnvironment, ZiplineTestCase
|
||||
from . import answer_key
|
||||
from . answer_key import AnswerKey
|
||||
|
||||
@@ -35,17 +34,10 @@ ANSWER_KEY = AnswerKey()
|
||||
RETURNS = ANSWER_KEY.RETURNS
|
||||
|
||||
|
||||
class TestRisk(unittest.TestCase):
|
||||
class TestRisk(WithTradingEnvironment, ZiplineTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.env = TradingEnvironment()
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
del cls.env
|
||||
|
||||
def setUp(self):
|
||||
def init_instance_fixtures(self):
|
||||
super(TestRisk, self).init_instance_fixtures()
|
||||
|
||||
start_date = datetime.datetime(
|
||||
year=2006,
|
||||
@@ -60,7 +52,7 @@ class TestRisk(unittest.TestCase):
|
||||
self.sim_params = SimulationParameters(
|
||||
period_start=start_date,
|
||||
period_end=end_date,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
self.algo_returns_06 = factory.create_returns_from_list(
|
||||
@@ -75,7 +67,7 @@ class TestRisk(unittest.TestCase):
|
||||
self.algo_returns_06,
|
||||
self.sim_params,
|
||||
benchmark_returns=self.benchmark_returns_06,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
treasury_curves=self.env.treasury_curves,
|
||||
)
|
||||
|
||||
@@ -96,12 +88,9 @@ class TestRisk(unittest.TestCase):
|
||||
self.sim_params08 = SimulationParameters(
|
||||
period_start=start_08,
|
||||
period_end=end_08,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
return
|
||||
|
||||
def test_factory(self):
|
||||
returns = [0.1] * 100
|
||||
r_objects = factory.create_returns_from_list(returns, self.sim_params)
|
||||
@@ -117,7 +106,7 @@ class TestRisk(unittest.TestCase):
|
||||
returns.index[0],
|
||||
returns.index[-1],
|
||||
returns,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
benchmark_returns=self.env.benchmark_returns,
|
||||
treasury_curves=self.env.treasury_curves,
|
||||
)
|
||||
@@ -145,7 +134,7 @@ class TestRisk(unittest.TestCase):
|
||||
def test_trading_days_06(self):
|
||||
returns = factory.create_returns_from_range(self.sim_params)
|
||||
metrics = risk.RiskReport(returns, self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
treasury_curves=self.env.treasury_curves,
|
||||
benchmark_returns=self.env.benchmark_returns)
|
||||
self.assertEqual([x.num_trading_days for x in metrics.year_periods],
|
||||
@@ -372,7 +361,7 @@ class TestRisk(unittest.TestCase):
|
||||
def test_benchmark_returns_08(self):
|
||||
returns = factory.create_returns_from_range(self.sim_params08)
|
||||
metrics = risk.RiskReport(returns, self.sim_params08,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
treasury_curves=self.env.treasury_curves,
|
||||
benchmark_returns=self.env.benchmark_returns)
|
||||
|
||||
@@ -421,7 +410,7 @@ class TestRisk(unittest.TestCase):
|
||||
def test_trading_days_08(self):
|
||||
returns = factory.create_returns_from_range(self.sim_params08)
|
||||
metrics = risk.RiskReport(returns, self.sim_params08,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
treasury_curves=self.env.treasury_curves,
|
||||
benchmark_returns=self.env.benchmark_returns)
|
||||
self.assertEqual([x.num_trading_days for x in metrics.year_periods],
|
||||
@@ -433,7 +422,7 @@ class TestRisk(unittest.TestCase):
|
||||
def test_benchmark_volatility_08(self):
|
||||
returns = factory.create_returns_from_range(self.sim_params08)
|
||||
metrics = risk.RiskReport(returns, self.sim_params08,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
treasury_curves=self.env.treasury_curves,
|
||||
benchmark_returns=self.env.benchmark_returns)
|
||||
|
||||
@@ -484,7 +473,7 @@ class TestRisk(unittest.TestCase):
|
||||
def test_treasury_returns_06(self):
|
||||
returns = factory.create_returns_from_range(self.sim_params)
|
||||
metrics = risk.RiskReport(returns, self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
treasury_curves=self.env.treasury_curves,
|
||||
benchmark_returns=self.env.benchmark_returns)
|
||||
self.assertEqual([round(x.treasury_period_return, 4)
|
||||
@@ -550,13 +539,13 @@ class TestRisk(unittest.TestCase):
|
||||
sim_params90s = SimulationParameters(
|
||||
period_start=start,
|
||||
period_end=end,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
returns = factory.create_returns_from_range(sim_params90s)
|
||||
returns = returns[:-10] # truncate the returns series to end mid-month
|
||||
metrics = risk.RiskReport(returns, sim_params90s,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
treasury_curves=self.env.treasury_curves,
|
||||
benchmark_returns=self.env.benchmark_returns)
|
||||
total_months = 60
|
||||
@@ -566,11 +555,11 @@ class TestRisk(unittest.TestCase):
|
||||
sim_params = SimulationParameters(
|
||||
period_start=start_date,
|
||||
period_end=start_date.replace(year=(start_date.year + years)),
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
returns = factory.create_returns_from_range(sim_params)
|
||||
metrics = risk.RiskReport(returns, self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
treasury_curves=self.env.treasury_curves,
|
||||
benchmark_returns=self.env.benchmark_returns)
|
||||
total_months = years * 12
|
||||
@@ -659,7 +648,7 @@ class TestRisk(unittest.TestCase):
|
||||
self.algo_returns_06,
|
||||
self.sim_params,
|
||||
benchmark_returns=benchmark_returns,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
treasury_curves=self.env.treasury_curves,
|
||||
)
|
||||
for risk_period in chain.from_iterable(itervalues(report.to_dict())):
|
||||
|
||||
+27
-27
@@ -97,6 +97,7 @@ from zipline.testing.fixtures import (
|
||||
WithSimParams,
|
||||
WithTradingEnvironment,
|
||||
WithTmpDir,
|
||||
WithTradingSchedule,
|
||||
ZiplineTestCase,
|
||||
)
|
||||
from zipline.test_algorithms import (
|
||||
@@ -166,7 +167,6 @@ from zipline.utils.control_flow import nullctx
|
||||
import zipline.utils.events
|
||||
from zipline.utils.events import date_rules, time_rules, Always
|
||||
import zipline.utils.factory as factory
|
||||
from zipline.utils.calendars import default_nyse_schedule
|
||||
|
||||
# Because test cases appear to reuse some resources.
|
||||
|
||||
@@ -953,7 +953,7 @@ def before_trading_start(context, data):
|
||||
period_end=period_end,
|
||||
capital_base=float("1.0e5"),
|
||||
data_frequency='minute',
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
data_portal = create_data_portal(
|
||||
@@ -961,7 +961,7 @@ def before_trading_start(context, data):
|
||||
tempdir,
|
||||
sim_params,
|
||||
equities.index,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
)
|
||||
algo = algo_class(sim_params=sim_params, env=env)
|
||||
algo.run(data_portal)
|
||||
@@ -1554,9 +1554,9 @@ def handle_data(context, data):
|
||||
env=self.env,
|
||||
)
|
||||
trades = factory.create_daily_trade_source(
|
||||
[0], self.sim_params, self.env, default_nyse_schedule)
|
||||
[0], self.sim_params, self.env, self.trading_schedule)
|
||||
data_portal = create_data_portal_from_trade_history(
|
||||
self.env, default_nyse_schedule, tempdir, self.sim_params,
|
||||
self.env, self.trading_schedule, tempdir, self.sim_params,
|
||||
{0: trades})
|
||||
results = test_algo.run(data_portal)
|
||||
|
||||
@@ -1644,7 +1644,7 @@ def handle_data(context, data):
|
||||
params = SimulationParameters(
|
||||
period_start=pd.Timestamp("2007-01-03", tz='UTC'),
|
||||
period_end=pd.Timestamp("2007-01-05", tz='UTC'),
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
# order method shouldn't blow up
|
||||
@@ -2731,7 +2731,7 @@ class TestTradingControls(WithSimParams, WithDataPortal, ZiplineTestCase):
|
||||
tempdir,
|
||||
sim_params,
|
||||
[1],
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
)
|
||||
|
||||
def handle_data(algo, data):
|
||||
@@ -2853,7 +2853,7 @@ class TestTradingControls(WithSimParams, WithDataPortal, ZiplineTestCase):
|
||||
tempdir,
|
||||
self.sim_params,
|
||||
[0],
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
)
|
||||
algo.run(data_portal)
|
||||
|
||||
@@ -2868,7 +2868,7 @@ class TestTradingControls(WithSimParams, WithDataPortal, ZiplineTestCase):
|
||||
tempdir,
|
||||
self.sim_params,
|
||||
[0],
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
)
|
||||
algo = SetAssetDateBoundsAlgorithm(
|
||||
sim_params=self.sim_params,
|
||||
@@ -2888,7 +2888,7 @@ class TestTradingControls(WithSimParams, WithDataPortal, ZiplineTestCase):
|
||||
tempdir,
|
||||
self.sim_params,
|
||||
[0],
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
)
|
||||
algo = SetAssetDateBoundsAlgorithm(
|
||||
sim_params=self.sim_params,
|
||||
@@ -2914,7 +2914,7 @@ class TestAccountControls(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
[100, 100, 100, 300],
|
||||
timedelta(days=1),
|
||||
cls.sim_params,
|
||||
default_nyse_schedule,
|
||||
cls.trading_schedule,
|
||||
),
|
||||
},
|
||||
index=cls.sim_params.trading_days,
|
||||
@@ -3061,7 +3061,7 @@ class TestFutureFlip(WithSimParams, WithDataPortal, ZiplineTestCase):
|
||||
[1e9, 1e9, 1e9],
|
||||
timedelta(days=1),
|
||||
cls.sim_params,
|
||||
default_nyse_schedule,
|
||||
cls.trading_schedule,
|
||||
),
|
||||
},
|
||||
index=cls.sim_params.trading_days,
|
||||
@@ -3071,7 +3071,7 @@ class TestFutureFlip(WithSimParams, WithDataPortal, ZiplineTestCase):
|
||||
def test_flip_algo(self):
|
||||
metadata = {1: {'symbol': 'TEST',
|
||||
'start_date': self.sim_params.trading_days[0],
|
||||
'end_date': default_nyse_schedule.next_execution_day(
|
||||
'end_date': self.trading_schedule.next_execution_day(
|
||||
self.sim_params.trading_days[-1]),
|
||||
'multiplier': 5}}
|
||||
|
||||
@@ -3214,7 +3214,7 @@ class TestOrderCancelation(WithDataPortal,
|
||||
sim_params=SimulationParameters(
|
||||
period_start=self.sim_params.period_start,
|
||||
period_end=self.sim_params.period_end,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
data_frequency=data_frequency,
|
||||
emission_rate='minute' if minute_emission else 'daily'
|
||||
)
|
||||
@@ -3396,7 +3396,7 @@ class TestRemoveData(TestCase):
|
||||
self.assertEqual(algo.data_lengths, self.live_asset_counts)
|
||||
|
||||
|
||||
class TestEquityAutoClose(WithTmpDir, ZiplineTestCase):
|
||||
class TestEquityAutoClose(WithTmpDir, WithTradingSchedule, ZiplineTestCase):
|
||||
"""
|
||||
Tests if delisted equities are properly removed from a portfolio holding
|
||||
positions in said equities.
|
||||
@@ -3404,7 +3404,7 @@ class TestEquityAutoClose(WithTmpDir, ZiplineTestCase):
|
||||
@classmethod
|
||||
def init_class_fixtures(cls):
|
||||
super(TestEquityAutoClose, cls).init_class_fixtures()
|
||||
trading_days = default_nyse_schedule.all_execution_days
|
||||
trading_days = cls.trading_schedule.all_execution_days
|
||||
start_date = pd.Timestamp('2015-01-05', tz='UTC')
|
||||
start_date_loc = trading_days.get_loc(start_date)
|
||||
test_duration = 7
|
||||
@@ -3420,7 +3420,7 @@ class TestEquityAutoClose(WithTmpDir, ZiplineTestCase):
|
||||
num_assets=3,
|
||||
start_date=self.test_days[0],
|
||||
first_end=self.first_asset_expiration,
|
||||
frequency=default_nyse_schedule.day,
|
||||
frequency=self.trading_schedule.day,
|
||||
periods_between_ends=2,
|
||||
auto_close_delta=auto_close_delta,
|
||||
)
|
||||
@@ -3428,10 +3428,10 @@ class TestEquityAutoClose(WithTmpDir, ZiplineTestCase):
|
||||
sids = asset_info.index
|
||||
|
||||
env = self.enter_instance_context(tmp_trading_env(equities=asset_info))
|
||||
market_opens = default_nyse_schedule.schedule.market_open.loc[
|
||||
market_opens = self.trading_schedule.schedule.market_open.loc[
|
||||
self.test_days
|
||||
]
|
||||
market_closes = default_nyse_schedule.schedule.market_close.loc[
|
||||
market_closes = self.trading_schedule.schedule.market_close.loc[
|
||||
self.test_days
|
||||
]
|
||||
|
||||
@@ -3454,12 +3454,12 @@ class TestEquityAutoClose(WithTmpDir, ZiplineTestCase):
|
||||
)
|
||||
reader = BcolzDailyBarReader(path)
|
||||
data_portal = DataPortal(
|
||||
env, default_nyse_schedule,
|
||||
env, self.trading_schedule,
|
||||
first_trading_day=reader.first_trading_day,
|
||||
equity_daily_reader=reader,
|
||||
)
|
||||
elif frequency == 'minute':
|
||||
dates = default_nyse_schedule.execution_minutes_for_days_in_range(
|
||||
dates = self.trading_schedule.execution_minutes_for_days_in_range(
|
||||
self.test_days[0],
|
||||
self.test_days[-1],
|
||||
)
|
||||
@@ -3484,7 +3484,7 @@ class TestEquityAutoClose(WithTmpDir, ZiplineTestCase):
|
||||
)
|
||||
reader = BcolzMinuteBarReader(self.tmpdir.path)
|
||||
data_portal = DataPortal(
|
||||
env, default_nyse_schedule,
|
||||
env, self.trading_schedule,
|
||||
first_trading_day=reader.first_trading_day,
|
||||
equity_minute_reader=reader,
|
||||
)
|
||||
@@ -3510,7 +3510,7 @@ class TestEquityAutoClose(WithTmpDir, ZiplineTestCase):
|
||||
else:
|
||||
final_prices = {
|
||||
asset.sid: trade_data_by_sid[asset.sid].loc[
|
||||
default_nyse_schedule.start_and_end(asset.end_date)[1]
|
||||
self.trading_schedule.start_and_end(asset.end_date)[1]
|
||||
].close
|
||||
for asset in assets
|
||||
}
|
||||
@@ -3582,7 +3582,7 @@ class TestEquityAutoClose(WithTmpDir, ZiplineTestCase):
|
||||
Make sure that after an equity gets delisted, our portfolio holds the
|
||||
correct number of equities and correct amount of cash.
|
||||
"""
|
||||
auto_close_delta = default_nyse_schedule.day * auto_close_lag
|
||||
auto_close_delta = self.trading_schedule.day * auto_close_lag
|
||||
resources = self.make_data(auto_close_delta, 'daily', capital_base)
|
||||
|
||||
assets = resources.assets
|
||||
@@ -3742,7 +3742,7 @@ class TestEquityAutoClose(WithTmpDir, ZiplineTestCase):
|
||||
canceled. Unless an equity is auto closed, any open orders for that
|
||||
equity will persist indefinitely.
|
||||
"""
|
||||
auto_close_delta = default_nyse_schedule.day
|
||||
auto_close_delta = self.trading_schedule.day
|
||||
resources = self.make_data(auto_close_delta, 'daily')
|
||||
env = resources.env
|
||||
assets = resources.assets
|
||||
@@ -3814,7 +3814,7 @@ class TestEquityAutoClose(WithTmpDir, ZiplineTestCase):
|
||||
)
|
||||
|
||||
def test_minutely_delisted_equities(self):
|
||||
resources = self.make_data(default_nyse_schedule.day, 'minute')
|
||||
resources = self.make_data(self.trading_schedule.day, 'minute')
|
||||
|
||||
env = resources.env
|
||||
assets = resources.assets
|
||||
@@ -4002,7 +4002,7 @@ class TestOrderAfterDelist(WithTradingEnvironment, ZiplineTestCase):
|
||||
sim_params=SimulationParameters(
|
||||
period_start=pd.Timestamp("2016-01-06", tz='UTC'),
|
||||
period_end=pd.Timestamp("2016-01-07", tz='UTC'),
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
data_frequency="minute"
|
||||
)
|
||||
)
|
||||
|
||||
@@ -19,7 +19,6 @@ from zipline.testing.fixtures import (
|
||||
ZiplineTestCase,
|
||||
)
|
||||
from zipline.zipline_warnings import ZiplineDeprecationWarning
|
||||
from zipline.utils.calendars import default_nyse_schedule
|
||||
|
||||
simple_algo = """
|
||||
from zipline.api import sid, order
|
||||
@@ -125,7 +124,7 @@ class TestAPIShim(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
def make_minute_bar_data(cls):
|
||||
for sid in cls.sids:
|
||||
yield sid, create_minute_df_for_asset(
|
||||
default_nyse_schedule,
|
||||
cls.trading_schedule,
|
||||
cls.SIM_PARAMS_START,
|
||||
cls.SIM_PARAMS_END,
|
||||
)
|
||||
@@ -134,7 +133,7 @@ class TestAPIShim(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
def make_daily_bar_data(cls):
|
||||
for sid in cls.sids:
|
||||
yield sid, create_daily_df_for_asset(
|
||||
default_nyse_schedule,
|
||||
cls.trading_schedule,
|
||||
cls.SIM_PARAMS_START,
|
||||
cls.SIM_PARAMS_END,
|
||||
)
|
||||
@@ -180,10 +179,10 @@ class TestAPIShim(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
similar) and the new data API(data.current(sid(N), field) and
|
||||
similar) hit the same code paths on the DataPortal.
|
||||
"""
|
||||
test_start_minute = default_nyse_schedule.execution_minutes_for_day(
|
||||
test_start_minute = self.trading_schedule.execution_minutes_for_day(
|
||||
self.sim_params.trading_days[0]
|
||||
)[1]
|
||||
test_end_minute = default_nyse_schedule.execution_minutes_for_day(
|
||||
test_end_minute = self.trading_schedule.execution_minutes_for_day(
|
||||
self.sim_params.trading_days[0]
|
||||
)[-1]
|
||||
bar_data = BarData(
|
||||
@@ -261,7 +260,7 @@ class TestAPIShim(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
period_start=test_start_minute,
|
||||
period_end=test_end_minute,
|
||||
data_frequency="minute",
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
history_algorithm = self.create_algo(
|
||||
@@ -382,7 +381,7 @@ class TestAPIShim(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
capital_base=self.sim_params.capital_base,
|
||||
data_frequency=self.sim_params.data_frequency,
|
||||
emission_rate=self.sim_params.emission_rate,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
algo = self.create_algo(history_algo,
|
||||
@@ -425,7 +424,7 @@ class TestAPIShim(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
period_start=self.sim_params.trading_days[8],
|
||||
period_end=self.sim_params.trading_days[-1],
|
||||
data_frequency="minute",
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
algo = self.create_algo(simple_transforms_algo,
|
||||
|
||||
@@ -82,8 +82,8 @@ from zipline.testing.predicates import assert_equal
|
||||
from zipline.testing.fixtures import (
|
||||
WithAssetFinder,
|
||||
ZiplineTestCase,
|
||||
WithTradingSchedule,
|
||||
)
|
||||
from zipline.utils.calendars import default_nyse_schedule
|
||||
|
||||
|
||||
@contextmanager
|
||||
@@ -396,7 +396,7 @@ class TestFuture(WithAssetFinder, ZiplineTestCase):
|
||||
TestFuture.asset_finder.lookup_future_symbol('XXX99')
|
||||
|
||||
|
||||
class AssetFinderTestCase(ZiplineTestCase):
|
||||
class AssetFinderTestCase(WithTradingSchedule, ZiplineTestCase):
|
||||
asset_finder_type = AssetFinder
|
||||
|
||||
def write_assets(self, **kwargs):
|
||||
@@ -776,7 +776,7 @@ class AssetFinderTestCase(ZiplineTestCase):
|
||||
|
||||
def test_compute_lifetimes(self):
|
||||
num_assets = 4
|
||||
trading_day = default_nyse_schedule.day
|
||||
trading_day = self.trading_schedule.day
|
||||
first_start = pd.Timestamp('2015-04-01', tz='UTC')
|
||||
|
||||
frame = make_rotating_equity_info(
|
||||
|
||||
@@ -28,7 +28,6 @@ from zipline.testing.fixtures import (
|
||||
WithDataPortal,
|
||||
ZiplineTestCase,
|
||||
)
|
||||
from zipline.utils.calendars import default_nyse_schedule
|
||||
|
||||
OHLC = ["open", "high", "low", "close"]
|
||||
OHLCP = OHLC + ["price"]
|
||||
@@ -610,7 +609,7 @@ class TestDailyBarData(WithBarDataChecks,
|
||||
def make_daily_bar_data(cls):
|
||||
for sid in cls.sids:
|
||||
yield sid, create_daily_df_for_asset(
|
||||
default_nyse_schedule,
|
||||
cls.trading_schedule,
|
||||
cls.bcolz_daily_bar_days[0],
|
||||
cls.bcolz_daily_bar_days[-1],
|
||||
interval=2 - sid % 2
|
||||
|
||||
@@ -30,12 +30,13 @@ from zipline.testing import (
|
||||
from zipline.testing.fixtures import (
|
||||
WithDataPortal,
|
||||
WithSimParams,
|
||||
WithTradingSchedule,
|
||||
ZiplineTestCase,
|
||||
)
|
||||
from zipline.utils.calendars import default_nyse_schedule
|
||||
|
||||
|
||||
class TestBenchmark(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
class TestBenchmark(WithDataPortal, WithSimParams, WithTradingSchedule,
|
||||
ZiplineTestCase):
|
||||
START_DATE = pd.Timestamp('2006-01-03', tz='utc')
|
||||
END_DATE = pd.Timestamp('2006-12-29', tz='utc')
|
||||
|
||||
@@ -86,7 +87,7 @@ class TestBenchmark(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
days_to_use = self.sim_params.trading_days[1:]
|
||||
|
||||
source = BenchmarkSource(
|
||||
1, self.env, default_nyse_schedule, days_to_use, self.data_portal
|
||||
1, self.env, self.trading_schedule, days_to_use, self.data_portal
|
||||
)
|
||||
|
||||
# should be the equivalent of getting the price history, then doing
|
||||
@@ -112,7 +113,7 @@ class TestBenchmark(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
BenchmarkSource(
|
||||
3,
|
||||
self.env,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.sim_params.trading_days[1:],
|
||||
self.data_portal
|
||||
)
|
||||
@@ -127,7 +128,7 @@ class TestBenchmark(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
BenchmarkSource(
|
||||
3,
|
||||
self.env,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.sim_params.trading_days[120:],
|
||||
self.data_portal
|
||||
)
|
||||
@@ -141,7 +142,7 @@ class TestBenchmark(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
def test_asset_IPOed_same_day(self):
|
||||
# gotta get some minute data up in here.
|
||||
# add sid 4 for a couple of days
|
||||
minutes = default_nyse_schedule.execution_minutes_for_days_in_range(
|
||||
minutes = self.trading_schedule.execution_minutes_for_days_in_range(
|
||||
self.sim_params.trading_days[0],
|
||||
self.sim_params.trading_days[5]
|
||||
)
|
||||
@@ -192,7 +193,7 @@ class TestBenchmark(WithDataPortal, WithSimParams, ZiplineTestCase):
|
||||
|
||||
with self.assertRaises(InvalidBenchmarkAsset) as exc:
|
||||
BenchmarkSource(
|
||||
4, self.env, default_nyse_schedule,
|
||||
4, self.env, self.trading_schedule,
|
||||
self.sim_params.trading_days, self.data_portal
|
||||
)
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ from pandas.tslib import Timedelta
|
||||
|
||||
from zipline.data.data_portal import DataPortal
|
||||
from zipline.testing.fixtures import WithTradingEnvironment, ZiplineTestCase
|
||||
from zipline.utils.calendars import default_nyse_schedule
|
||||
import pandas as pd
|
||||
|
||||
|
||||
@@ -27,7 +26,7 @@ class TestDataPortal(WithTradingEnvironment, ZiplineTestCase):
|
||||
def init_instance_fixtures(self):
|
||||
super(TestDataPortal, self).init_instance_fixtures()
|
||||
|
||||
self.data_portal = DataPortal(self.env, default_nyse_schedule,
|
||||
self.data_portal = DataPortal(self.env, self.trading_schedule,
|
||||
first_trading_day=None)
|
||||
|
||||
def test_bar_count_for_simple_transforms(self):
|
||||
@@ -42,7 +41,7 @@ class TestDataPortal(WithTradingEnvironment, ZiplineTestCase):
|
||||
# half an hour into july 9, getting a 4-"day" window should get us
|
||||
# all the minutes of 7/6, 7/7, 7/8, and 31 minutes of 7/9
|
||||
|
||||
july_9_dt = default_nyse_schedule.start_and_end(
|
||||
july_9_dt = self.trading_schedule.start_and_end(
|
||||
pd.Timestamp("2015-07-09")
|
||||
)[0] + Timedelta("30 minutes")
|
||||
|
||||
@@ -65,7 +64,7 @@ class TestDataPortal(WithTradingEnvironment, ZiplineTestCase):
|
||||
# half an hour into nov 30, getting a 4-"day" window should get us
|
||||
# all the minutes of 11/24, 11/25, 11/27 (half day!), and 31 minutes
|
||||
# of 11/30
|
||||
nov_30_dt = default_nyse_schedule.start_and_end(
|
||||
nov_30_dt = self.trading_schedule.start_and_end(
|
||||
pd.Timestamp("2015-11-30")
|
||||
)[0] + Timedelta("30 minutes")
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ from zipline.testing.fixtures import (
|
||||
WithSimParams,
|
||||
ZiplineTestCase,
|
||||
)
|
||||
from zipline.utils.calendars import default_nyse_schedule
|
||||
from .resources.fetcher_inputs.fetcher_test_data import (
|
||||
AAPL_CSV_DATA,
|
||||
AAPL_IBM_CSV_DATA,
|
||||
@@ -110,7 +109,7 @@ class FetcherTestCase(WithResponses,
|
||||
)
|
||||
|
||||
results = test_algo.run(FetcherDataPortal(self.env,
|
||||
default_nyse_schedule))
|
||||
self.trading_schedule))
|
||||
|
||||
return results
|
||||
|
||||
@@ -144,7 +143,7 @@ def handle_data(context, data):
|
||||
# the minutely emission packets here. TradingAlgorithm.run() only
|
||||
# returns daily packets.
|
||||
test_algo.data_portal = FetcherDataPortal(self.env,
|
||||
default_nyse_schedule)
|
||||
self.trading_schedule)
|
||||
gen = test_algo.get_generator()
|
||||
perf_packets = list(gen)
|
||||
|
||||
|
||||
+8
-13
@@ -30,7 +30,6 @@ from testfixtures import TempDirectory
|
||||
from zipline.assets.synthetic import make_simple_equity_info
|
||||
from zipline.finance.blotter import Blotter
|
||||
from zipline.finance.execution import MarketOrder, LimitOrder
|
||||
from zipline.finance.trading import TradingEnvironment
|
||||
from zipline.finance.performance import PerformanceTracker
|
||||
from zipline.finance.trading import SimulationParameters
|
||||
from zipline.data.us_equity_pricing import BcolzDailyBarReader
|
||||
@@ -50,10 +49,6 @@ from zipline.testing.fixtures import (
|
||||
)
|
||||
|
||||
import zipline.utils.factory as factory
|
||||
from zipline.utils.calendars import (
|
||||
default_nyse_schedule,
|
||||
get_calendar,
|
||||
)
|
||||
|
||||
DEFAULT_TIMEOUT = 15 # seconds
|
||||
EXTENDED_TIMEOUT = 90
|
||||
@@ -203,7 +198,7 @@ class FinanceTestCase(WithLogger,
|
||||
data_frequency="minute"
|
||||
)
|
||||
|
||||
minutes = default_nyse_schedule.execution_minute_window(
|
||||
minutes = self.trading_schedule.execution_minute_window(
|
||||
sim_params.first_open,
|
||||
int((trade_interval.total_seconds() / 60) * trade_count)
|
||||
+ 100)
|
||||
@@ -221,8 +216,8 @@ class FinanceTestCase(WithLogger,
|
||||
}
|
||||
|
||||
write_bcolz_minute_data(
|
||||
default_nyse_schedule,
|
||||
default_nyse_schedule.execution_days_in_range(minutes[0],
|
||||
self.trading_schedule,
|
||||
self.trading_schedule.execution_days_in_range(minutes[0],
|
||||
minutes[-1]),
|
||||
tempdir.path,
|
||||
iteritems(assets),
|
||||
@@ -231,7 +226,7 @@ class FinanceTestCase(WithLogger,
|
||||
equity_minute_reader = BcolzMinuteBarReader(tempdir.path)
|
||||
|
||||
data_portal = DataPortal(
|
||||
env, default_nyse_schedule,
|
||||
env, self.trading_schedule,
|
||||
first_trading_day=equity_minute_reader.first_trading_day,
|
||||
equity_minute_reader=equity_minute_reader,
|
||||
)
|
||||
@@ -259,7 +254,7 @@ class FinanceTestCase(WithLogger,
|
||||
equity_daily_reader = BcolzDailyBarReader(path)
|
||||
|
||||
data_portal = DataPortal(
|
||||
env, default_nyse_schedule,
|
||||
env, self.trading_schedule,
|
||||
first_trading_day=equity_daily_reader.first_trading_day,
|
||||
equity_daily_reader=equity_daily_reader,
|
||||
)
|
||||
@@ -280,7 +275,7 @@ class FinanceTestCase(WithLogger,
|
||||
else:
|
||||
alternator = 1
|
||||
|
||||
tracker = PerformanceTracker(sim_params, default_nyse_schedule,
|
||||
tracker = PerformanceTracker(sim_params, self.trading_schedule,
|
||||
self.env)
|
||||
|
||||
# replicate what tradesim does by going through every minute or day
|
||||
@@ -399,7 +394,7 @@ class TradingEnvironmentTestCase(WithLogger,
|
||||
period_start=datetime(2008, 1, 1, tzinfo=pytz.utc),
|
||||
period_end=datetime(2008, 12, 31, tzinfo=pytz.utc),
|
||||
capital_base=100000,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
self.assertTrue(sp.last_close.month == 12)
|
||||
@@ -420,7 +415,7 @@ class TradingEnvironmentTestCase(WithLogger,
|
||||
period_start=datetime(2007, 12, 31, tzinfo=pytz.utc),
|
||||
period_end=datetime(2008, 1, 7, tzinfo=pytz.utc),
|
||||
capital_base=100000,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
expected_trading_days = (
|
||||
|
||||
+28
-29
@@ -24,7 +24,6 @@ from zipline.testing import (
|
||||
str_to_seconds,
|
||||
MockDailyBarReader,
|
||||
)
|
||||
from zipline.utils.calendars import default_nyse_schedule
|
||||
from zipline.testing.fixtures import (
|
||||
WithBcolzMinuteBarReader,
|
||||
WithDataPortal,
|
||||
@@ -79,7 +78,7 @@ class WithHistory(WithDataPortal):
|
||||
@classmethod
|
||||
def init_class_fixtures(cls):
|
||||
super(WithHistory, cls).init_class_fixtures()
|
||||
cls.trading_days = default_nyse_schedule.execution_days_in_range(
|
||||
cls.trading_days = cls.trading_schedule.execution_days_in_range(
|
||||
start=cls.TRADING_START_DT,
|
||||
end=cls.TRADING_END_DT
|
||||
)
|
||||
@@ -456,14 +455,14 @@ class MinuteEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
for sid in sids:
|
||||
asset = cls.asset_finder.retrieve_asset(sid)
|
||||
data[sid] = create_minute_df_for_asset(
|
||||
default_nyse_schedule,
|
||||
cls.trading_schedule,
|
||||
asset.start_date,
|
||||
asset.end_date,
|
||||
start_val=2,
|
||||
)
|
||||
|
||||
data[1] = create_minute_df_for_asset(
|
||||
default_nyse_schedule,
|
||||
cls.trading_schedule,
|
||||
pd.Timestamp('2014-01-03', tz='utc'),
|
||||
pd.Timestamp('2016-01-30', tz='utc'),
|
||||
start_val=2,
|
||||
@@ -510,7 +509,7 @@ class MinuteEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
))
|
||||
asset3 = cls.asset_finder.retrieve_asset(3)
|
||||
data[3] = create_minute_df_for_asset(
|
||||
default_nyse_schedule,
|
||||
cls.trading_schedule,
|
||||
asset3.start_date,
|
||||
asset3.end_date,
|
||||
start_val=2,
|
||||
@@ -540,7 +539,7 @@ class MinuteEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
capital_base=float('1.0e5'),
|
||||
data_frequency='minute',
|
||||
emission_rate='daily',
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
test_algo = TradingAlgorithm(
|
||||
@@ -679,8 +678,8 @@ class MinuteEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
def test_minute_before_assets_trading(self):
|
||||
# since asset2 and asset3 both started trading on 1/5/2015, let's do
|
||||
# some history windows that are completely before that
|
||||
minutes = default_nyse_schedule.execution_minutes_for_day(
|
||||
default_nyse_schedule.previous_execution_day(pd.Timestamp(
|
||||
minutes = self.trading_schedule.execution_minutes_for_day(
|
||||
self.trading_schedule.previous_execution_day(pd.Timestamp(
|
||||
'2015-01-05', tz='UTC'
|
||||
))
|
||||
)[0:60]
|
||||
@@ -729,7 +728,7 @@ class MinuteEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
# 10 minutes
|
||||
asset = self.env.asset_finder.retrieve_asset(sid)
|
||||
|
||||
minutes = default_nyse_schedule.execution_minutes_for_day(
|
||||
minutes = self.trading_schedule.execution_minutes_for_day(
|
||||
pd.Timestamp('2015-01-05', tz='UTC')
|
||||
)[0:60]
|
||||
|
||||
@@ -740,8 +739,8 @@ class MinuteEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
|
||||
def test_minute_midnight(self):
|
||||
midnight = pd.Timestamp('2015-01-06', tz='UTC')
|
||||
last_minute = default_nyse_schedule.start_and_end(
|
||||
default_nyse_schedule.previous_execution_day(midnight)
|
||||
last_minute = self.trading_schedule.start_and_end(
|
||||
self.trading_schedule.previous_execution_day(midnight)
|
||||
)[1]
|
||||
|
||||
midnight_bar_data = \
|
||||
@@ -760,7 +759,7 @@ class MinuteEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
def test_minute_after_asset_stopped(self):
|
||||
# SHORT_ASSET's last day was 2015-01-06
|
||||
# get some history windows that straddle the end
|
||||
minutes = default_nyse_schedule.execution_minutes_for_day(
|
||||
minutes = self.trading_schedule.execution_minutes_for_day(
|
||||
pd.Timestamp('2015-01-07', tz='UTC')
|
||||
)[0:60]
|
||||
|
||||
@@ -855,7 +854,7 @@ class MinuteEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
# before any of the adjustments, last 10 minutes of jan 5
|
||||
window1 = self.data_portal.get_history_window(
|
||||
[asset],
|
||||
default_nyse_schedule.start_and_end(jan5)[1],
|
||||
self.trading_schedule.start_and_end(jan5)[1],
|
||||
10,
|
||||
'1m',
|
||||
'close'
|
||||
@@ -1104,21 +1103,21 @@ class MinuteEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
|
||||
def test_minute_different_lifetimes(self):
|
||||
# at trading start, only asset1 existed
|
||||
day = default_nyse_schedule.next_execution_day(self.TRADING_START_DT)
|
||||
day = self.trading_schedule.next_execution_day(self.TRADING_START_DT)
|
||||
|
||||
asset1_minutes = \
|
||||
default_nyse_schedule.execution_minutes_for_days_in_range(
|
||||
self.trading_schedule.execution_minutes_for_days_in_range(
|
||||
start=self.ASSET1.start_date,
|
||||
end=self.ASSET1.end_date
|
||||
)
|
||||
|
||||
asset1_idx = asset1_minutes.searchsorted(
|
||||
default_nyse_schedule.start_and_end(day)[0]
|
||||
self.trading_schedule.start_and_end(day)[0]
|
||||
)
|
||||
|
||||
window = self.data_portal.get_history_window(
|
||||
[self.ASSET1, self.ASSET2],
|
||||
default_nyse_schedule.start_and_end(day)[0],
|
||||
self.trading_schedule.start_and_end(day)[0],
|
||||
100,
|
||||
'1m',
|
||||
'close'
|
||||
@@ -1137,7 +1136,7 @@ class MinuteEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
# trading_start is 2/3/2014
|
||||
# get a history window that starts before that, and ends after that
|
||||
self.data_portal.set_first_trading_day(self.TRADING_START_DT)
|
||||
first_day_minutes = default_nyse_schedule.execution_minutes_for_day(
|
||||
first_day_minutes = self.trading_schedule.execution_minutes_for_day(
|
||||
self.TRADING_START_DT
|
||||
)
|
||||
exp_msg = (
|
||||
@@ -1157,7 +1156,7 @@ class MinuteEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
|
||||
# January 2015 has both daily and minute data for ASSET2
|
||||
day = pd.Timestamp('2015-01-07', tz='UTC')
|
||||
minutes = default_nyse_schedule.execution_minutes_for_day(day)
|
||||
minutes = self.trading_schedule.execution_minutes_for_day(day)
|
||||
|
||||
# minute data, baseline:
|
||||
# Jan 5: 2 to 391
|
||||
@@ -1221,7 +1220,7 @@ class MinuteEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
|
||||
# January 2015 has both daily and minute data for ASSET2
|
||||
day = pd.Timestamp('2015-01-08', tz='UTC')
|
||||
minutes = default_nyse_schedule.execution_minutes_for_day(day)
|
||||
minutes = self.trading_schedule.execution_minutes_for_day(day)
|
||||
|
||||
# minute data, baseline:
|
||||
# Jan 5: 2 to 391
|
||||
@@ -1340,8 +1339,8 @@ class DailyEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
@classmethod
|
||||
def create_df_for_asset(cls, start_day, end_day, interval=1,
|
||||
force_zeroes=False):
|
||||
days = default_nyse_schedule.execution_days_in_range(start_day,
|
||||
end_day)
|
||||
days = cls.trading_schedule.execution_days_in_range(start_day,
|
||||
end_day)
|
||||
days_count = len(days)
|
||||
|
||||
# default to 2 because the low array subtracts 1, and we don't
|
||||
@@ -1370,7 +1369,7 @@ class DailyEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
def test_daily_before_assets_trading(self):
|
||||
# asset2 and asset3 both started trading in 2015
|
||||
|
||||
days = default_nyse_schedule.execution_days_in_range(
|
||||
days = self.trading_schedule.execution_days_in_range(
|
||||
start=pd.Timestamp('2014-12-15', tz='UTC'),
|
||||
end=pd.Timestamp('2014-12-18', tz='UTC'),
|
||||
)
|
||||
@@ -1408,9 +1407,9 @@ class DailyEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
# get the first 30 days of 2015
|
||||
jan5 = pd.Timestamp('2015-01-04')
|
||||
|
||||
days = default_nyse_schedule.execution_days_in_range(
|
||||
days = self.trading_schedule.execution_days_in_range(
|
||||
start=jan5,
|
||||
end=default_nyse_schedule.add_execution_days(30, jan5)
|
||||
end=self.trading_schedule.add_execution_days(30, jan5)
|
||||
)
|
||||
|
||||
for idx, day in enumerate(days):
|
||||
@@ -1453,7 +1452,7 @@ class DailyEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
def test_daily_after_asset_stopped(self):
|
||||
# SHORT_ASSET trades on 1/5, 1/6, that's it.
|
||||
|
||||
days = default_nyse_schedule.execution_days_in_range(
|
||||
days = self.trading_schedule.execution_days_in_range(
|
||||
start=pd.Timestamp('2015-01-07', tz='UTC'),
|
||||
end=pd.Timestamp('2015-01-08', tz='UTC')
|
||||
)
|
||||
@@ -1646,7 +1645,7 @@ class DailyEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
# get a history window that starts before that, and ends after that
|
||||
|
||||
self.data_portal.set_first_trading_day(self.TRADING_START_DT)
|
||||
second_day = default_nyse_schedule.next_execution_day(
|
||||
second_day = self.trading_schedule.next_execution_day(
|
||||
self.TRADING_START_DT
|
||||
)
|
||||
|
||||
@@ -1675,7 +1674,7 @@ class DailyEquityHistoryTestCase(WithHistory, ZiplineTestCase):
|
||||
|
||||
# Use a minute to force minute mode.
|
||||
first_minute = \
|
||||
default_nyse_schedule.schedule.market_open[self.TRADING_START_DT]
|
||||
self.trading_schedule.schedule.market_open[self.TRADING_START_DT]
|
||||
|
||||
with self.assertRaisesRegexp(HistoryWindowStartsBeforeData, exp_msg):
|
||||
self.data_portal.get_history_window(
|
||||
@@ -1805,7 +1804,7 @@ class MinuteToDailyAggregationTestCase(WithBcolzMinuteBarReader,
|
||||
# Set up a fresh data portal for each test, since order of calling
|
||||
# needs to be tested.
|
||||
self.equity_daily_aggregator = DailyHistoryAggregator(
|
||||
default_nyse_schedule.schedule.market_open,
|
||||
self.trading_schedule.schedule.market_open,
|
||||
self.bcolz_minute_bar_reader,
|
||||
)
|
||||
|
||||
|
||||
+55
-53
@@ -57,6 +57,7 @@ from zipline.testing.fixtures import (
|
||||
WithSimParams,
|
||||
WithTmpDir,
|
||||
WithTradingEnvironment,
|
||||
WithTradingSchedule,
|
||||
ZiplineTestCase,
|
||||
)
|
||||
from zipline.utils.calendars import default_nyse_schedule
|
||||
@@ -279,7 +280,7 @@ class TestSplitPerformance(WithSimParams, WithTmpDir, ZiplineTestCase):
|
||||
# if multiple positions all have splits at the same time, verify that
|
||||
# the total leftover cash is correct
|
||||
perf_tracker = perf.PerformanceTracker(self.sim_params,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.env)
|
||||
|
||||
asset1 = self.asset_finder.retrieve_asset(1)
|
||||
@@ -309,14 +310,14 @@ class TestSplitPerformance(WithSimParams, WithTmpDir, ZiplineTestCase):
|
||||
[100, 100],
|
||||
oneday,
|
||||
self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
# 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,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.tmpdir,
|
||||
self.sim_params,
|
||||
{1: events},
|
||||
@@ -421,7 +422,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
after = factory.get_next_trading_dt(
|
||||
before,
|
||||
timedelta(days=1),
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
)
|
||||
self.assertEqual(after.hour, 13)
|
||||
|
||||
@@ -433,7 +434,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
[100, 100, 100, 100, 100, 100],
|
||||
oneday,
|
||||
self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
dbpath = self.instance_tmpdir.getpath('adjustments.sqlite')
|
||||
@@ -441,7 +442,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
writer = SQLiteAdjustmentWriter(
|
||||
dbpath,
|
||||
MockDailyBarReader(),
|
||||
default_nyse_schedule.all_execution_days,
|
||||
self.trading_schedule.all_execution_days,
|
||||
)
|
||||
splits = mergers = create_empty_splits_mergers_frame()
|
||||
dividends = pd.DataFrame({
|
||||
@@ -456,7 +457,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
adjustment_reader = SQLiteAdjustmentReader(dbpath)
|
||||
data_portal = create_data_portal_from_trade_history(
|
||||
self.env,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.instance_tmpdir,
|
||||
self.sim_params,
|
||||
{1: events},
|
||||
@@ -499,7 +500,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
[100, 100, 100, 100, 100, 100],
|
||||
oneday,
|
||||
self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
dbpath = self.instance_tmpdir.getpath('adjustments.sqlite')
|
||||
@@ -507,7 +508,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
writer = SQLiteAdjustmentWriter(
|
||||
dbpath,
|
||||
MockDailyBarReader(),
|
||||
default_nyse_schedule.all_execution_days,
|
||||
self.trading_schedule.all_execution_days,
|
||||
)
|
||||
splits = mergers = create_empty_splits_mergers_frame()
|
||||
dividends = pd.DataFrame({
|
||||
@@ -533,7 +534,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
|
||||
data_portal = create_data_portal_from_trade_history(
|
||||
self.env,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.instance_tmpdir,
|
||||
self.sim_params,
|
||||
events,
|
||||
@@ -574,7 +575,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
[100, 100, 100, 100, 100, 100],
|
||||
oneday,
|
||||
self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
dbpath = self.instance_tmpdir.getpath('adjustments.sqlite')
|
||||
@@ -582,7 +583,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
writer = SQLiteAdjustmentWriter(
|
||||
dbpath,
|
||||
MockDailyBarReader(),
|
||||
default_nyse_schedule.all_execution_days,
|
||||
self.trading_schedule.all_execution_days,
|
||||
)
|
||||
splits = mergers = create_empty_splits_mergers_frame()
|
||||
dividends = pd.DataFrame({
|
||||
@@ -598,7 +599,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
|
||||
data_portal = create_data_portal_from_trade_history(
|
||||
self.env,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.instance_tmpdir,
|
||||
self.sim_params,
|
||||
{1: events},
|
||||
@@ -636,7 +637,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
[100, 100, 100, 100, 100, 100],
|
||||
oneday,
|
||||
self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
dbpath = self.instance_tmpdir.getpath('adjustments.sqlite')
|
||||
@@ -644,7 +645,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
writer = SQLiteAdjustmentWriter(
|
||||
dbpath,
|
||||
MockDailyBarReader(),
|
||||
default_nyse_schedule.all_execution_days,
|
||||
self.trading_schedule.all_execution_days,
|
||||
)
|
||||
splits = mergers = create_empty_splits_mergers_frame()
|
||||
dividends = pd.DataFrame({
|
||||
@@ -660,7 +661,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
|
||||
data_portal = create_data_portal_from_trade_history(
|
||||
self.env,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.instance_tmpdir,
|
||||
self.sim_params,
|
||||
{1: events},
|
||||
@@ -699,14 +700,14 @@ class TestDividendPerformance(WithSimParams,
|
||||
[100, 100, 100, 100, 100, 100],
|
||||
oneday,
|
||||
self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
dbpath = self.instance_tmpdir.getpath('adjustments.sqlite')
|
||||
|
||||
writer = SQLiteAdjustmentWriter(
|
||||
dbpath,
|
||||
MockDailyBarReader(),
|
||||
default_nyse_schedule.all_execution_days,
|
||||
self.trading_schedule.all_execution_days,
|
||||
)
|
||||
splits = mergers = create_empty_splits_mergers_frame()
|
||||
|
||||
@@ -723,7 +724,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
|
||||
data_portal = create_data_portal_from_trade_history(
|
||||
self.env,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.instance_tmpdir,
|
||||
self.sim_params,
|
||||
{1: events},
|
||||
@@ -760,21 +761,21 @@ class TestDividendPerformance(WithSimParams,
|
||||
[100, 100, 100, 100, 100, 100],
|
||||
oneday,
|
||||
self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
pay_date = self.sim_params.first_open
|
||||
# find pay date that is much later.
|
||||
for i in range(30):
|
||||
pay_date = factory.get_next_trading_dt(pay_date, oneday,
|
||||
default_nyse_schedule)
|
||||
self.trading_schedule)
|
||||
|
||||
dbpath = self.instance_tmpdir.getpath('adjustments.sqlite')
|
||||
|
||||
writer = SQLiteAdjustmentWriter(
|
||||
dbpath,
|
||||
MockDailyBarReader(),
|
||||
default_nyse_schedule.all_execution_days,
|
||||
self.trading_schedule.all_execution_days,
|
||||
)
|
||||
splits = mergers = create_empty_splits_mergers_frame()
|
||||
dividends = pd.DataFrame({
|
||||
@@ -790,7 +791,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
|
||||
data_portal = create_data_portal_from_trade_history(
|
||||
self.env,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.instance_tmpdir,
|
||||
self.sim_params,
|
||||
{1: events},
|
||||
@@ -828,7 +829,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
[100, 100, 100, 100, 100, 100],
|
||||
oneday,
|
||||
self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
dbpath = self.instance_tmpdir.getpath('adjustments.sqlite')
|
||||
@@ -836,7 +837,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
writer = SQLiteAdjustmentWriter(
|
||||
dbpath,
|
||||
MockDailyBarReader(),
|
||||
default_nyse_schedule.all_execution_days,
|
||||
self.trading_schedule.all_execution_days,
|
||||
)
|
||||
splits = mergers = create_empty_splits_mergers_frame()
|
||||
dividends = pd.DataFrame({
|
||||
@@ -852,7 +853,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
|
||||
data_portal = create_data_portal_from_trade_history(
|
||||
self.env,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.instance_tmpdir,
|
||||
self.sim_params,
|
||||
{1: events},
|
||||
@@ -887,7 +888,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
[100, 100, 100, 100, 100, 100],
|
||||
oneday,
|
||||
self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
dbpath = self.instance_tmpdir.getpath('adjustments.sqlite')
|
||||
@@ -895,7 +896,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
writer = SQLiteAdjustmentWriter(
|
||||
dbpath,
|
||||
MockDailyBarReader(),
|
||||
default_nyse_schedule.all_execution_days,
|
||||
self.trading_schedule.all_execution_days,
|
||||
)
|
||||
splits = mergers = create_empty_splits_mergers_frame()
|
||||
dividends = pd.DataFrame({
|
||||
@@ -911,7 +912,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
|
||||
data_portal = create_data_portal_from_trade_history(
|
||||
self.env,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.instance_tmpdir,
|
||||
self.sim_params,
|
||||
{1: events},
|
||||
@@ -944,7 +945,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
[100, 100, 100, 100, 100],
|
||||
oneday,
|
||||
self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
dbpath = self.instance_tmpdir.getpath('adjustments.sqlite')
|
||||
@@ -952,7 +953,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
writer = SQLiteAdjustmentWriter(
|
||||
dbpath,
|
||||
MockDailyBarReader(),
|
||||
default_nyse_schedule.all_execution_days,
|
||||
self.trading_schedule.all_execution_days,
|
||||
)
|
||||
splits = mergers = create_empty_splits_mergers_frame()
|
||||
dividends = pd.DataFrame({
|
||||
@@ -962,7 +963,7 @@ class TestDividendPerformance(WithSimParams,
|
||||
'ex_date': np.array([events[-2].dt], dtype='datetime64[ns]'),
|
||||
'record_date': np.array([events[0].dt], dtype='datetime64[ns]'),
|
||||
'pay_date': np.array(
|
||||
[default_nyse_schedule.next_execution_day(events[-1].dt)],
|
||||
[self.trading_schedule.next_execution_day(events[-1].dt)],
|
||||
dtype='datetime64[ns]'),
|
||||
})
|
||||
writer.write(splits, mergers, dividends)
|
||||
@@ -977,11 +978,11 @@ class TestDividendPerformance(WithSimParams,
|
||||
)
|
||||
|
||||
sim_params.period_end = events[-1].dt
|
||||
sim_params.update_internal_from_trading_schedule(default_nyse_schedule)
|
||||
sim_params.update_internal_from_trading_schedule(self.trading_schedule)
|
||||
|
||||
data_portal = create_data_portal_from_trade_history(
|
||||
self.env,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.instance_tmpdir,
|
||||
sim_params,
|
||||
{1: events},
|
||||
@@ -1021,7 +1022,8 @@ class TestDividendPerformanceHolidayStyle(TestDividendPerformance):
|
||||
END_DATE = pd.Timestamp('2003-12-08', tz='utc')
|
||||
|
||||
|
||||
class TestPositionPerformance(WithInstanceTmpDir, ZiplineTestCase):
|
||||
class TestPositionPerformance(WithInstanceTmpDir, WithTradingSchedule,
|
||||
ZiplineTestCase):
|
||||
def create_environment_stuff(self,
|
||||
num_days=4,
|
||||
sids=[1, 2],
|
||||
@@ -1070,7 +1072,7 @@ class TestPositionPerformance(WithInstanceTmpDir, ZiplineTestCase):
|
||||
[100, 100, 100, 100],
|
||||
oneday,
|
||||
self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
trades_2 = factory.create_trade_history(
|
||||
@@ -1079,12 +1081,12 @@ class TestPositionPerformance(WithInstanceTmpDir, ZiplineTestCase):
|
||||
[100, 100, 100, 100],
|
||||
oneday,
|
||||
self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
data_portal = create_data_portal_from_trade_history(
|
||||
self.env,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.instance_tmpdir,
|
||||
self.sim_params,
|
||||
{1: trades_1, 2: trades_2}
|
||||
@@ -1176,12 +1178,12 @@ class TestPositionPerformance(WithInstanceTmpDir, ZiplineTestCase):
|
||||
[100, 100, 100, 100],
|
||||
oneday,
|
||||
self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
data_portal = create_data_portal_from_trade_history(
|
||||
self.env,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.instance_tmpdir,
|
||||
self.sim_params,
|
||||
{1: trades})
|
||||
@@ -1268,12 +1270,12 @@ class TestPositionPerformance(WithInstanceTmpDir, ZiplineTestCase):
|
||||
[100, 100, 100, 100],
|
||||
oneday,
|
||||
self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
data_portal = create_data_portal_from_trade_history(
|
||||
self.env,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.instance_tmpdir,
|
||||
self.sim_params,
|
||||
{1: trades})
|
||||
@@ -1384,14 +1386,14 @@ single short-sale transaction"""
|
||||
[100, 100, 100, 100, 100, 100],
|
||||
oneday,
|
||||
self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
trades_1 = trades[:-2]
|
||||
|
||||
data_portal = create_data_portal_from_trade_history(
|
||||
self.env,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.instance_tmpdir,
|
||||
self.sim_params,
|
||||
{1: trades})
|
||||
@@ -1618,12 +1620,12 @@ cost of sole txn in test"
|
||||
[100, 100, 100, 100],
|
||||
oneday,
|
||||
sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
data_portal = create_data_portal_from_trade_history(
|
||||
self.env,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.instance_tmpdir,
|
||||
self.sim_params,
|
||||
{3: trades}
|
||||
@@ -1738,12 +1740,12 @@ single short-sale transaction"""
|
||||
[100, 100, 100, 100, 100, 100],
|
||||
oneday,
|
||||
self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
data_portal = create_data_portal_from_trade_history(
|
||||
self.env,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.instance_tmpdir,
|
||||
self.sim_params,
|
||||
{3: trades}
|
||||
@@ -1983,12 +1985,12 @@ trade after cover"""
|
||||
[100, 100, 100, 100, 100, 100, 100, 100, 100, 100],
|
||||
oneday,
|
||||
self.sim_params,
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
data_portal = create_data_portal_from_trade_history(
|
||||
self.env,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.instance_tmpdir,
|
||||
self.sim_params,
|
||||
{1: trades})
|
||||
@@ -2070,14 +2072,14 @@ shares in position"
|
||||
[100, 100, 100, 100, 100],
|
||||
oneday,
|
||||
self.sim_params,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
)
|
||||
trades = factory.create_trade_history(*history_args)
|
||||
transactions = factory.create_txn_history(*history_args)[:4]
|
||||
|
||||
data_portal = create_data_portal_from_trade_history(
|
||||
self.env,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
self.instance_tmpdir,
|
||||
self.sim_params,
|
||||
{1: trades})
|
||||
@@ -2196,7 +2198,7 @@ shares in position"
|
||||
[200, -100, -100, 100, -300, 100, 500, 400],
|
||||
oneday,
|
||||
self.sim_params,
|
||||
default_nyse_schedule,
|
||||
self.trading_schedule,
|
||||
)
|
||||
cost_bases = [10, 10, 0, 8, 9, 9, 13, 13.5]
|
||||
|
||||
|
||||
@@ -12,13 +12,16 @@ from zipline.testing import (
|
||||
tmp_trading_env,
|
||||
tmp_dir,
|
||||
)
|
||||
from zipline.testing.fixtures import WithLogger, ZiplineTestCase
|
||||
from zipline.testing.fixtures import (
|
||||
WithLogger,
|
||||
WithTradingSchedule,
|
||||
ZiplineTestCase,
|
||||
)
|
||||
from zipline.utils import factory
|
||||
from zipline.utils.security_list import (
|
||||
SecurityListSet,
|
||||
load_from_directory,
|
||||
)
|
||||
from zipline.utils.calendars import default_nyse_schedule
|
||||
|
||||
LEVERAGED_ETFS = load_from_directory('leveraged_etf_list')
|
||||
|
||||
@@ -64,7 +67,7 @@ class IterateRLAlgo(TradingAlgorithm):
|
||||
self.found = True
|
||||
|
||||
|
||||
class SecurityListTestCase(WithLogger, ZiplineTestCase):
|
||||
class SecurityListTestCase(WithLogger, WithTradingSchedule, ZiplineTestCase):
|
||||
|
||||
@classmethod
|
||||
def init_class_fixtures(cls):
|
||||
@@ -88,7 +91,7 @@ class SecurityListTestCase(WithLogger, ZiplineTestCase):
|
||||
cls.sim_params = factory.create_simulation_parameters(
|
||||
start=start,
|
||||
num_days=4,
|
||||
trading_schedule=default_nyse_schedule
|
||||
trading_schedule=cls.trading_schedule
|
||||
)
|
||||
|
||||
cls.sim_params2 = sp2 = factory.create_simulation_parameters(
|
||||
@@ -111,7 +114,7 @@ class SecurityListTestCase(WithLogger, ZiplineTestCase):
|
||||
tempdir=cls.tempdir,
|
||||
sim_params=cls.sim_params,
|
||||
sids=range(0, 5),
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=cls.trading_schedule,
|
||||
)
|
||||
|
||||
cls.data_portal2 = create_data_portal(
|
||||
@@ -119,7 +122,7 @@ class SecurityListTestCase(WithLogger, ZiplineTestCase):
|
||||
tempdir=cls.tempdir2,
|
||||
sim_params=cls.sim_params2,
|
||||
sids=range(0, 5),
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=cls.trading_schedule,
|
||||
)
|
||||
|
||||
def test_iterate_over_restricted_list(self):
|
||||
@@ -222,7 +225,7 @@ class SecurityListTestCase(WithLogger, ZiplineTestCase):
|
||||
self.tempdir,
|
||||
sim_params=sim_params,
|
||||
sids=range(0, 5),
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
algo = RestrictedAlgoWithoutCheck(symbol='BZQ',
|
||||
@@ -274,7 +277,7 @@ class SecurityListTestCase(WithLogger, ZiplineTestCase):
|
||||
new_tempdir,
|
||||
sim_params,
|
||||
range(0, 5),
|
||||
trading_schedule=default_nyse_schedule,
|
||||
trading_schedule=self.trading_schedule,
|
||||
)
|
||||
|
||||
algo = RestrictedAlgoWithoutCheck(
|
||||
|
||||
@@ -82,7 +82,8 @@ class USEquityHistoryLoader(with_metaclass(ABCMeta)):
|
||||
"""
|
||||
FIELDS = ('open', 'high', 'low', 'close', 'volume')
|
||||
|
||||
def __init__(self, trading_schedule, reader, adjustment_reader, sid_cache_size=1000):
|
||||
def __init__(self, trading_schedule, reader, adjustment_reader,
|
||||
sid_cache_size=1000):
|
||||
self.trading_schedule = trading_schedule
|
||||
self._reader = reader
|
||||
self._adjustments_reader = adjustment_reader
|
||||
|
||||
@@ -306,10 +306,10 @@ class PerformanceTracker(object):
|
||||
)
|
||||
stock_dividends = adjustment_reader.\
|
||||
get_stock_dividends_with_ex_date(
|
||||
held_sids,
|
||||
next_trading_day,
|
||||
self.asset_finder
|
||||
)
|
||||
held_sids,
|
||||
next_trading_day,
|
||||
self.asset_finder
|
||||
)
|
||||
|
||||
position_tracker.earn_dividends(
|
||||
cash_dividends,
|
||||
|
||||
@@ -26,7 +26,6 @@ from zipline.utils.calendars import default_nyse_schedule
|
||||
log = logbook.Logger('Trading')
|
||||
|
||||
|
||||
|
||||
class TradingEnvironment(object):
|
||||
"""
|
||||
The financial simulations in zipline depend on information
|
||||
@@ -107,7 +106,6 @@ class TradingEnvironment(object):
|
||||
else:
|
||||
self.asset_finder = None
|
||||
|
||||
|
||||
def write_data(self, **kwargs):
|
||||
"""Write data into the asset_db.
|
||||
|
||||
|
||||
@@ -20,8 +20,6 @@ from abc import (
|
||||
)
|
||||
from six import with_metaclass
|
||||
|
||||
from zipline.utils.memoize import remember_last
|
||||
|
||||
from .exchange_calendar import get_calendar
|
||||
from .calendar_helpers import (
|
||||
next_scheduled_day,
|
||||
|
||||
Reference in New Issue
Block a user