mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-04 21:53:45 +08:00
TST: Remove random simulation parameters.
For better predictability/ability to reason and step through the test cases, use the same start and end for each run of the test suite.
This commit is contained in:
@@ -44,7 +44,7 @@ from zipline.finance.trading import SimulationParameters
|
||||
from zipline.finance.blotter import Order
|
||||
from zipline.finance.commission import PerShare, PerTrade, PerDollar
|
||||
from zipline.finance.trading import TradingEnvironment
|
||||
from zipline.utils.factory import create_random_simulation_parameters
|
||||
from zipline.utils.factory import create_simulation_parameters
|
||||
from zipline.utils.serialization_utils import (
|
||||
loads_with_persistent_ids, dumps_with_persistent_ids
|
||||
)
|
||||
@@ -262,8 +262,7 @@ class TestSplitPerformance(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.env = TradingEnvironment()
|
||||
self.env.write_data(equities_identifiers=[1])
|
||||
self.sim_params, self.dt, self.end_dt = \
|
||||
create_random_simulation_parameters()
|
||||
self.sim_params = create_simulation_parameters(num_days=2)
|
||||
# start with $10,000
|
||||
self.sim_params.capital_base = 10e3
|
||||
|
||||
@@ -367,11 +366,9 @@ class TestCommissionEvents(unittest.TestCase):
|
||||
self.env.write_data(
|
||||
equities_identifiers=[0, 1, 133]
|
||||
)
|
||||
self.sim_params, self.dt, self.end_dt = \
|
||||
create_random_simulation_parameters()
|
||||
self.sim_params = create_simulation_parameters(num_days=5)
|
||||
|
||||
logger.info("sim_params: %s, dt: %s, end_dt: %s" %
|
||||
(self.sim_params, self.dt, self.end_dt))
|
||||
logger.info("sim_params: %s" % self.sim_params)
|
||||
|
||||
self.sim_params.capital_base = 10e3
|
||||
|
||||
@@ -520,8 +517,7 @@ class TestDividendPerformance(unittest.TestCase):
|
||||
del cls.env
|
||||
|
||||
def setUp(self):
|
||||
self.sim_params, self.dt, self.end_dt = \
|
||||
create_random_simulation_parameters()
|
||||
self.sim_params = create_simulation_parameters(num_days=6)
|
||||
self.sim_params.capital_base = 10e3
|
||||
|
||||
self.benchmark_events = benchmark_events_in_range(self.sim_params,
|
||||
@@ -977,8 +973,7 @@ class TestPositionPerformance(unittest.TestCase):
|
||||
del cls.env
|
||||
|
||||
def setUp(self):
|
||||
self.sim_params, self.dt, self.end_dt = \
|
||||
create_random_simulation_parameters()
|
||||
self.sim_params = create_simulation_parameters(num_days=4)
|
||||
|
||||
self.finder = self.env.asset_finder
|
||||
self.benchmark_events = benchmark_events_in_range(self.sim_params,
|
||||
@@ -2079,7 +2074,7 @@ class TestPerformanceTracker(unittest.TestCase):
|
||||
|
||||
def test_handle_sid_removed_from_universe(self):
|
||||
# post some trades in the market
|
||||
sim_params, _, _ = create_random_simulation_parameters()
|
||||
sim_params = create_simulation_parameters(num_days=5)
|
||||
events = factory.create_trade_history(
|
||||
1,
|
||||
[10, 10, 10, 10, 10],
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
Factory functions to prepare useful data.
|
||||
"""
|
||||
import pytz
|
||||
import random
|
||||
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
@@ -69,38 +68,6 @@ def create_simulation_parameters(year=2006, start=None, end=None,
|
||||
return sim_params
|
||||
|
||||
|
||||
def create_random_simulation_parameters():
|
||||
env = TradingEnvironment()
|
||||
treasury_curves = env.treasury_curves
|
||||
|
||||
for n in range(100):
|
||||
|
||||
random_index = random.randint(
|
||||
0,
|
||||
len(treasury_curves) - 1
|
||||
)
|
||||
|
||||
start_dt = treasury_curves.index[random_index]
|
||||
end_dt = start_dt + timedelta(days=365)
|
||||
|
||||
now = datetime.utcnow().replace(tzinfo=pytz.utc)
|
||||
|
||||
if end_dt <= now:
|
||||
break
|
||||
|
||||
assert end_dt <= now, """
|
||||
failed to find a suitable daterange after 100 attempts. please double
|
||||
check treasury and benchmark data in findb, and re-run the test."""
|
||||
|
||||
sim_params = SimulationParameters(
|
||||
period_start=start_dt,
|
||||
period_end=end_dt,
|
||||
env=env,
|
||||
)
|
||||
|
||||
return sim_params, start_dt, end_dt
|
||||
|
||||
|
||||
def get_next_trading_dt(current, interval, env):
|
||||
next_dt = pd.Timestamp(current).tz_convert(env.exchange_tz)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user