Merge pull request #22 from quantopian/integration

Integration
This commit is contained in:
fawce
2012-04-02 07:39:18 -07:00
3 changed files with 36 additions and 6 deletions
+2
View File
@@ -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,
+20 -5
View File
@@ -173,6 +173,7 @@ class SimulatedTrading(object):
self.trading_client.set_algorithm(self.algorithm)
@staticmethod
def create_test_zipline(**config):
@@ -191,6 +192,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 +230,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
#-------------------
@@ -287,6 +299,9 @@ class SimulatedTrading(object):
def get_cumulative_performance(self):
return self.trading_client.perf.cumulative_performance.to_dict()
def publish_to(self, result_socket):
self.trading_client.perf.publish_to(result_socket)
def allocate_sockets(self, n):
"""
+14 -1
View File
@@ -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.