mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-05 22:34:50 +08:00
fixed missing fields, added a new random source option to test zipline (still buggy).
This commit is contained in:
@@ -128,6 +128,8 @@ class RiskMetrics():
|
||||
'benchmark_volatility' : self.benchmark_volatility,
|
||||
'algo_volatility' : self.algorithm_volatility,
|
||||
'treasury_period_return': self.treasury_period_return,
|
||||
'algorithm_period_return' : self.algorithm_period_returns,
|
||||
'benchmark_period_return' : self.benchmark_period_returns,
|
||||
'sharpe' : self.sharpe,
|
||||
'beta' : self.beta,
|
||||
'alpha' : self.alpha,
|
||||
|
||||
+16
-5
@@ -191,6 +191,10 @@ class SimulatedTrading(object):
|
||||
:py:class:`zipline.simulator.Simulator`
|
||||
- algorithm - optional parameter providing an algorithm. defaults
|
||||
to :py:class:`zipline.test.algorithms.TestAlgorithm`
|
||||
- random - optional parameter to request random trades. if present
|
||||
:py:class:`zipline.sources.RandomEquityTrades` is the source. If
|
||||
not :py:class:`ziplien.sources.SpecificEquityTrades` is the
|
||||
source
|
||||
"""
|
||||
assert isinstance(config, dict)
|
||||
|
||||
@@ -225,11 +229,18 @@ class SimulatedTrading(object):
|
||||
#-------------------
|
||||
sids = [sid]
|
||||
#-------------------
|
||||
trade_source = factory.create_daily_trade_source(
|
||||
sids,
|
||||
trade_count,
|
||||
trading_environment
|
||||
)
|
||||
if config.has_key('random'):
|
||||
trade_source = factory.create_random_trade_source(
|
||||
sids,
|
||||
trade_count,
|
||||
trading_environment
|
||||
)
|
||||
else:
|
||||
trade_source = factory.create_daily_trade_source(
|
||||
sids,
|
||||
trade_count,
|
||||
trading_environment
|
||||
)
|
||||
#-------------------
|
||||
# Create the Algo
|
||||
#-------------------
|
||||
|
||||
+14
-1
@@ -9,7 +9,7 @@ from datetime import datetime, timedelta
|
||||
import zipline.util as qutil
|
||||
import zipline.finance.risk as risk
|
||||
import zipline.protocol as zp
|
||||
from zipline.sources import SpecificEquityTrades
|
||||
from zipline.sources import SpecificEquityTrades, RandomEquityTrades
|
||||
from zipline.finance.trading import TradingEnvironment
|
||||
|
||||
def load_market_data():
|
||||
@@ -152,6 +152,19 @@ def create_returns_from_list(returns, start, trading_calendar):
|
||||
|
||||
return test_range
|
||||
|
||||
def create_random_trade_source(sid, trade_count, trading_environment):
|
||||
# create the source
|
||||
source = RandomEquityTrades(sid, "rand-"+str(sid), trade_count)
|
||||
|
||||
# make the period_end of trading_environment match
|
||||
cur = trading_environment.period_start
|
||||
one_day = timedelta(days = 1)
|
||||
for i in range(trade_count + 2):
|
||||
cur = get_next_trading_dt(cur, one_day, trading_environment)
|
||||
trading_environment.period_end = cur
|
||||
|
||||
return source
|
||||
|
||||
def create_daily_trade_source(sids, trade_count, trading_environment):
|
||||
"""
|
||||
creates trade_count trades for each sid in sids list.
|
||||
|
||||
Reference in New Issue
Block a user