mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-30 12:01:00 +08:00
Fix for slippage time getting out of sync with algo.
Moved grouping by date earlier in the pipeline of generators, prior to any date-dependent state getting involved. Grouping pulls from the pipeline until the start of the next group, which is in the next day. The effect of grouping after slippage but before handle_data is that slippage and the algo are out of sync by a transaction.
This commit is contained in:
@@ -20,6 +20,9 @@ import numpy as np
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from itertools import groupby
|
||||
from operator import attrgetter
|
||||
|
||||
from zipline.sources import DataFrameSource
|
||||
from zipline.utils.factory import create_trading_environment
|
||||
from zipline.transforms.utils import StatefulTransform
|
||||
@@ -95,12 +98,15 @@ class TradingAlgorithm(object):
|
||||
self.date_sorted = date_sorted_sources(*self.sources)
|
||||
self.with_tnfms = sequential_transforms(self.date_sorted,
|
||||
*self.transforms)
|
||||
# Group together events with the same dt field. This depends on the
|
||||
# events already being sorted.
|
||||
self.grouped_by_date = groupby(self.with_tnfms, attrgetter('dt'))
|
||||
self.trading_client = tsc(self, environment)
|
||||
|
||||
transact_method = transact_partial(self.slippage, self.commission)
|
||||
self.set_transact(transact_method)
|
||||
|
||||
return self.trading_client.simulate(self.with_tnfms)
|
||||
return self.trading_client.simulate(self.grouped_by_date)
|
||||
|
||||
def get_generator(self, environment):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user