mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-02 11:52:39 +08:00
Merge pull request #90 from quantopian/fake_environment
Fake environment
This commit is contained in:
@@ -97,7 +97,7 @@ def load_market_data(bm_symbol='^GSPC'):
|
||||
fp_bm = get_datafile(get_benchmark_filename(bm_symbol), "rb")
|
||||
except IOError:
|
||||
print """
|
||||
data msgpacks aren't distribute with source.
|
||||
data msgpacks aren't distributed with source.
|
||||
Fetching data from Yahoo Finance.
|
||||
""".strip()
|
||||
dump_benchmarks(bm_symbol)
|
||||
@@ -119,7 +119,7 @@ Fetching data from Yahoo Finance.
|
||||
fp_tr = get_datafile('treasury_curves.msgpack', "rb")
|
||||
except IOError:
|
||||
print """
|
||||
data msgpacks aren't distribute with source.
|
||||
data msgpacks aren't distributed with source.
|
||||
Fetching data from data.treasury.gov
|
||||
""".strip()
|
||||
dump_treasury_curves()
|
||||
|
||||
@@ -34,6 +34,7 @@ from zipline.sources import (SpecificEquityTrades,
|
||||
from zipline.gens.utils import create_trade
|
||||
from zipline.finance.trading import SimulationParameters
|
||||
import zipline.finance.trading as trading
|
||||
from zipline.sources.test_source import date_gen
|
||||
|
||||
|
||||
def create_simulation_parameters(year=2006, start=None, end=None,
|
||||
@@ -54,6 +55,36 @@ def create_simulation_parameters(year=2006, start=None, end=None,
|
||||
return sim_params
|
||||
|
||||
|
||||
def create_noop_environment():
|
||||
oneday = timedelta(days=1)
|
||||
start = datetime(2006, 1, 1, tzinfo=pytz.utc)
|
||||
|
||||
bm_returns = []
|
||||
tr_curves = OrderedDict()
|
||||
for day in date_gen(start=start, delta=oneday, count=252):
|
||||
dr = trading.DailyReturn(day, 0.01)
|
||||
bm_returns.append(dr)
|
||||
curve = {
|
||||
'10year': 0.0799,
|
||||
'1month': 0.0799,
|
||||
'1year': 0.0785,
|
||||
'20year': 0.0765,
|
||||
'2year': 0.0794,
|
||||
'30year': 0.0804,
|
||||
'3month': 0.0789,
|
||||
'3year': 0.0796,
|
||||
'5year': 0.0792,
|
||||
'6month': 0.0794,
|
||||
'7year': 0.0804,
|
||||
'tid': 1752
|
||||
}
|
||||
tr_curves[day] = curve
|
||||
|
||||
load_nodata = lambda x: (bm_returns, tr_curves)
|
||||
|
||||
return trading.TradingEnvironment(load=load_nodata)
|
||||
|
||||
|
||||
def create_random_simulation_parameters():
|
||||
trading.environment = trading.TradingEnvironment()
|
||||
treasury_curves = trading.environment.treasury_curves
|
||||
|
||||
@@ -19,10 +19,11 @@ import pytz
|
||||
|
||||
from datetime import datetime
|
||||
from dateutil import rrule
|
||||
from zipline.utils.date_utils import utcnow
|
||||
from delorean import Delorean
|
||||
|
||||
start = datetime(1990, 1, 1, tzinfo=pytz.utc)
|
||||
end = utcnow()
|
||||
end_dln = Delorean(datetime.now(), 'US/Eastern').truncate('day').shift('UTC')
|
||||
end = end_dln.datetime
|
||||
|
||||
|
||||
def get_non_trading_days(start, end):
|
||||
|
||||
@@ -27,10 +27,9 @@ import pandas as pd
|
||||
|
||||
from datetime import datetime
|
||||
from dateutil import rrule
|
||||
from zipline.utils.date_utils import utcnow
|
||||
from zipline.utils.tradingcalendar import end
|
||||
|
||||
start = datetime(2002, 1, 1, tzinfo=pytz.utc)
|
||||
end = utcnow()
|
||||
|
||||
non_trading_rules = []
|
||||
# Weekends
|
||||
|
||||
Reference in New Issue
Block a user