mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-14 11:15:09 +08:00
Merge branch 'master' of github.com:quantopian/zipline
This commit is contained in:
@@ -13,7 +13,17 @@
|
||||
|
||||
set -e
|
||||
|
||||
# stash everything that wasn't just staged
|
||||
# so that we are only testing the staged code
|
||||
git stash -q --keep-index
|
||||
|
||||
# Run flake8 linting
|
||||
flake8 zipline tests
|
||||
# Run unit tests
|
||||
nosetests -x
|
||||
|
||||
# restore unstaged code
|
||||
# N.B. this won't run if linting or unit tests fail
|
||||
# But if either fail, it's probably best to have only the offending
|
||||
# staged commits 'active', anyway.
|
||||
git stash pop -q
|
||||
|
||||
@@ -131,13 +131,13 @@ class TradingAlgorithm(object):
|
||||
self.with_alias_dt = alias_dt(self.with_tnfms)
|
||||
# Group together events with the same dt field. This depends on the
|
||||
# events already being sorted.
|
||||
self.grouped_by_date = groupby(self.with_alias_dt, attrgetter('dt'))
|
||||
self.grouped_by_dt = groupby(self.with_alias_dt, attrgetter('dt'))
|
||||
self.trading_client = tsc(self, sim_params)
|
||||
|
||||
transact_method = transact_partial(self.slippage, self.commission)
|
||||
self.set_transact(transact_method)
|
||||
|
||||
return self.trading_client.simulate(self.grouped_by_date)
|
||||
return self.trading_client.simulate(self.grouped_by_dt)
|
||||
|
||||
def get_generator(self):
|
||||
"""
|
||||
|
||||
@@ -33,8 +33,6 @@ Performance Tracking
|
||||
+-----------------+----------------------------------------------------+
|
||||
| progress | percentage of test completed |
|
||||
+-----------------+----------------------------------------------------+
|
||||
| started_at | datetime in utc marking the start of this test |
|
||||
+-----------------+----------------------------------------------------+
|
||||
| capital_base | The initial capital assumed for this tracker. |
|
||||
+-----------------+----------------------------------------------------+
|
||||
| cumulative_perf | A dictionary representing the cumulative |
|
||||
@@ -133,8 +131,6 @@ omitted).
|
||||
"""
|
||||
|
||||
import logbook
|
||||
import datetime
|
||||
import pytz
|
||||
import math
|
||||
|
||||
import numpy as np
|
||||
@@ -148,20 +144,12 @@ log = logbook.Logger('Performance')
|
||||
|
||||
class PerformanceTracker(object):
|
||||
"""
|
||||
Tracks the performance of the zipline as it is running in
|
||||
the simulator, relays this out to the Deluge broker and then
|
||||
to the client. Visually:
|
||||
|
||||
+--------------------+ Result Stream +--------+
|
||||
| PerformanceTracker | ----------------> | Deluge |
|
||||
+--------------------+ +--------+
|
||||
|
||||
Tracks the performance of the algorithm.
|
||||
"""
|
||||
|
||||
def __init__(self, sim_params):
|
||||
|
||||
self.sim_params = sim_params
|
||||
self.started_at = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
|
||||
|
||||
self.period_start = self.sim_params.period_start
|
||||
self.period_end = self.sim_params.period_end
|
||||
@@ -177,7 +165,6 @@ class PerformanceTracker(object):
|
||||
self.returns = []
|
||||
self.txn_count = 0
|
||||
self.event_count = 0
|
||||
self.last_dict = None
|
||||
self.cumulative_risk_metrics = \
|
||||
risk.RiskMetricsIterative(self.period_start)
|
||||
|
||||
@@ -226,7 +213,7 @@ class PerformanceTracker(object):
|
||||
|
||||
new_snapshot.append(event)
|
||||
|
||||
if len(new_snapshot) > 0:
|
||||
if new_snapshot:
|
||||
yield date, new_snapshot
|
||||
|
||||
def get_portfolio(self):
|
||||
@@ -238,7 +225,6 @@ class PerformanceTracker(object):
|
||||
Returns a dict object of the form described in header comments.
|
||||
"""
|
||||
return {
|
||||
'started_at': self.started_at,
|
||||
'period_start': self.period_start,
|
||||
'period_end': self.period_end,
|
||||
'progress': self.progress,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright 2012 Quantopian, Inc.
|
||||
# Copyright 2013 Quantopian, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import itertools
|
||||
|
||||
from logbook import Logger, Processor
|
||||
from collections import defaultdict
|
||||
@@ -234,16 +234,20 @@ class AlgorithmSimulator(object):
|
||||
"""
|
||||
Main generator work loop.
|
||||
"""
|
||||
# Set the simulation date to be the first event we see.
|
||||
peek_date, peek_snapshot = next(stream_in)
|
||||
self.simulation_dt = peek_date
|
||||
|
||||
# Stitch back together the generator by placing the peeked
|
||||
# event back in front
|
||||
stream = itertools.chain([(peek_date, peek_snapshot)],
|
||||
stream_in)
|
||||
|
||||
# inject the current algo
|
||||
# snapshot time to any log record generated.
|
||||
with self.processor.threadbound():
|
||||
|
||||
for date, snapshot in stream_in:
|
||||
# Set the simulation date to be the first event we see.
|
||||
# This should only occur once, at the start of the test.
|
||||
if self.simulation_dt is None:
|
||||
self.simulation_dt = date
|
||||
|
||||
for date, snapshot in stream:
|
||||
# We're still in the warmup period. Use the event to
|
||||
# update our universe, but don't yield any perf messages,
|
||||
# and don't send a snapshot to handle_data.
|
||||
|
||||
Reference in New Issue
Block a user