def _create_generator(self, sim_params, source_filter=None): """ Create a basic generator setup using the sources and transforms attached to this algorithm. ::source_filter:: is a method that receives events in date sorted order, and returns True for those events that should be processed by the zipline, and False for those that should be skipped. """ sim_params.data_frequency = self.data_frequency self.data_gen = self._create_data_generator(source_filter, sim_params) # if live execution is active instantiate perf_tracker with # the portfolio downloaded from IB if self.asset_type == self.asset_types.EQUITY: self.perf_tracker = PerformanceTracker(sim_params) elif self.asset_type == self.asset_types.FUTURES: self.perf_tracker = FuturesPerformanceTracker(sim_params) else: self.perf_tracker = PerformanceTracker(sim_params) if self.live_execution: self._init_positions() self.trading_client = AlgorithmSimulator(self, sim_params) transact_method = transact_partial(self.slippage, self.commission) self.set_transact(transact_method) return self.trading_client.transform(self.data_gen)
def __init__(self): self.transact = transact_partial(VolumeShareSlippage(), PerShare()) # these orders are aggregated by sid self.open_orders = defaultdict(list) # keep a dict of orders by their own id self.orders = {} # holding orders that have come in since the last # event. self.new_orders = [] self.current_dt = None self.max_shares = int(1e+11)