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 # perf_tracker will be instantiated in __init__ if a sim_params # is passed to the constructor. If not, we instantiate here. if self.perf_tracker is None: self.perf_tracker = PerformanceTracker(sim_params) self.data_gen = self._create_data_generator(source_filter, sim_params) 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 _create_generator(self, sim_params, source_filter=None): """ Create a basic generator setup using the sources 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. """ if not self.initialized: self.initialize(*self.initialize_args, **self.initialize_kwargs) self.initialized = True if self.perf_tracker is None: # HACK: When running with the `run` method, we set perf_tracker to # None so that it will be overwritten here. self.perf_tracker = PerformanceTracker(sim_params) self.portfolio_needs_update = True self.account_needs_update = True self.performance_needs_update = True self.data_gen = self._create_data_generator(source_filter, sim_params) 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 _create_generator(self, sim_params, source_filter=None): """ Create a basic generator setup using the sources 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. """ if not self.initialized: self.initialize(*self.initialize_args, **self.initialize_kwargs) self.initialized = True if self.perf_tracker is None: # HACK: When running with the `run` method, we set perf_tracker to # None so that it will be overwritten here. self.perf_tracker = PerformanceTracker( sim_params=sim_params, env=self.trading_environment ) self.portfolio_needs_update = True self.account_needs_update = True self.performance_needs_update = True self.data_gen = self._create_data_generator(source_filter, sim_params) 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 = []
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
def __init__(self): self.transact = transact_partial(VolumeShareSlippage(), OrderCost()) # 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)
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 = {} # track transactions by sid and by order self.txns_by_sid = defaultdict(list) self.txns_by_order = defaultdict(list) # holding orders that have come in since the last # event. self.new_orders = []
def __init__(self, fill_delay=timedelta(minutes=1)): 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) self.fill_delay = fill_delay
def _create_generator(self, environment): """ Create a basic generator setup using the sources and transforms attached to this algorithm. """ self.date_sorted = date_sorted_sources(*self.sources) self.with_tnfms = sequential_transforms(self.date_sorted, *self.transforms) 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)
def _create_generator(self, environment): """ Create a basic generator setup using the sources and transforms attached to this algorithm. """ 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.grouped_by_date)
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. """ self.data_gen = self._create_data_generator(source_filter, sim_params) 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 _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. """ self.data_gen = self._create_data_generator(source_filter) 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.data_gen)
def _create_generator(self, sim_params, source_filter=None): """ Create a basic generator setup using the sources 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. """ if not self.initialized: self.initialize(*self.initialize_args, **self.initialize_kwargs) self.initialized = True if self.perf_tracker is None: # HACK: When running with the `run` method, we set perf_tracker to # None so that it will be overwritten here. #self.perf_tracker = CustomPerfTracker( self.perf_tracker = PerformanceTracker( sim_params=sim_params, env=self.trading_environment ) self.portfolio_needs_update = True self.account_needs_update = True self.performance_needs_update = True self.data_gen = self._create_data_generator(source_filter, sim_params) # Zipline uses a lot of composition object oriented design. # How does composition help keep the system flexible and allow for object to be # substituted at run-time. # Zipline is a backtester that runs on historical data but it's also # the engine that drives Quantopion's live trading. # What objects might be modified to allow for live trading and greater functionality? # What Are the other key objects? (hint, look at the blotter) self.trading_client = AlgorithmSimulator(self, sim_params) transact_method = transact_partial(self.slippage, self.commission) self.set_transact(transact_method) # The transform method does the heavy lifting of the main zipline event loop return self.trading_client.transform(self.data_gen)
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. """ # Instantiate perf_tracker self.perf_tracker = PerformanceTracker(sim_params) self.portfolio_needs_update = True self.data_gen = self._create_data_generator(source_filter, sim_params) 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()) self.open_orders = defaultdict(list)