def __init__(self, engine, user, strategy, name, symbols, time_frame, id=None, parent=None): """ 信号对象,每一个信号即为策略代码中不以init为名的任意最外层函数,订阅某些品种的行情数据,运行于特定时间框架下。 通过两个EventPacker(事件打包器)接受StrategyEngine中的DataCache(数据中转器)发出的行情事件来管理Bar数据的结构。 :param engine:挂载运行的策略引擎 :param symbols:所订阅行情数据的品种列表 :param time_frame:所订阅行情数据的事件框架 :param id:不需要传入,由SignalFactory自动管理。 """ Runnable.__init__(self) APIInterface.__init__(self) ConfigInterface.__init__(self, parent=parent) self._id = id self._user = user self._strategy = strategy self._name = name self._event_update = Event.create_event_type('SignalUpdate.%s.%s.%s' % (self._user, self._strategy, self._name), priority=1).get_id() self._event_completed = Event.create_event_type( 'SignalCompleted.%s.%s.%s' % (self._user, self._strategy, self._name), priority=2).get_id() self._update = SymbolBarUpdateEventsPacker(engine, symbols, time_frame, self._event_update) self._completed = SymbolBarCompletedEventsPacker(engine, symbols, time_frame, self._event_completed) self._parameters = OrderedDict() self._symbols = symbols self._time_frame = time_frame self._engine = engine self._handler = None self._generator = None self._gene_instance = None self._bar_num = 0 # 暂时使用在LocalsInjector中改写的方式 self._environment = None
def __init__(self, generator=None, signal=None): Runnable.__init__(self) self.__signal = signal self.__generator = generator self.__cache = {} self.__map = {} self.__count = 0
def __init__(self, engine, code, parent=None): """Constructor""" super().__init__() LoggerInterface.__init__(self, parent=parent) APIInterface.__init__(self) Runnable.__init__(self) ConfigInterface.__init__(self, parent=parent) self.__id = self.next_auto_inc() self.user = self.config.user self.user_dir = UserDirectory(User(self.config.user)) self.__strategy_code = StrategyCode(self.config.name, code) self.__code_parser = None self.engine = proxy(engine) self.time_frame = self.config.time_frame self.symbols = self.config.symbols self.start_time = self.config.start_time self.end_time = self.config.end_time self.capital_base = self.config.capital_base self.handlers = {} self.signal_factory = SignalFactory() self.signals = {} self.system_functions = {} self.series_storage = {} self.printer = FilePrinter(self.config.user, self.config.name, self.engine) self.__context = {} self._setting() self.logger_name = "Strategy"
def __init__(self): LoggerInterface.__init__(self) ConfigInterface.__init__(self) Runnable.__init__(self) self.__code = None self.__strategy = None self.__strategy_engine = None self.__tb_data_generator = None self.__rt_data_generator = None self.__strategy_parameters = None self.__initialized = False self.logger_name = 'RuntimeSignal'
def __init__(self, engine, parent=None): LoggerInterface.__init__(self, parent=parent) Runnable.__init__(self) APIInterface.__init__(self) ConfigInterface.__init__(self, parent=parent) self._engine = proxy(engine) # 避免循环引用 self._tick_cache = {} self._running = False self._data_view = QuotationDataView() self._symbol_pool = {} self.current_time = None # 目前数据运行到的时间,用于计算回测进度 self._min_time_frame = None self._count = 0 self.logger_name = "QuotationManager"
def __init__(self, engine, user, strategy, name, symbols, time_frame, id=None, parent=None): """ 信号对象,每一个信号即为策略代码中不以init为名的任意最外层函数,订阅某些品种的行情数据,运行于特定时间框架下。 通过两个EventPacker(事件打包器)接受StrategyEngine中的DataCache(数据中转器)发出的行情事件来管理Bar数据的结构。 :param engine:挂载运行的策略引擎 :param symbols:所订阅行情数据的品种列表 :param time_frame:所订阅行情数据的事件框架 :param id:不需要传入,由SignalFactory自动管理。 """ Runnable.__init__(self) APIInterface.__init__(self) ConfigInterface.__init__(self, parent=parent) self._id = id self._user = user self._strategy = strategy self._name = name self._event_update = Event.create_event_type( 'SignalUpdate.%s.%s.%s' % (self._user, self._strategy, self._name), priority=1).get_id() self._event_completed = Event.create_event_type( 'SignalCompleted.%s.%s.%s' % (self._user, self._strategy, self._name), priority=2).get_id() self._update = SymbolBarUpdateEventsPacker(engine, symbols, time_frame, self._event_update) self._completed = SymbolBarCompletedEventsPacker( engine, symbols, time_frame, self._event_completed) self._parameters = OrderedDict() self._symbols = symbols self._time_frame = time_frame self._engine = engine self._handler = None self._generator = None self._gene_instance = None self._bar_num = 0 # 暂时使用在LocalsInjector中改写的方式 self._environment = None
def __init__(self, parent=None): """Constructor""" LoggerInterface.__init__(self, parent=parent) Runnable.__init__(self) ConfigInterface.__init__(self, parent=parent) APIInterface.__init__(self) self.__event_engine = EventEngine(parent=self) # 事件处理引擎 self.__quotation_manager = QuotationManager(self, parent=self) # 行情数据管理器 if self.config.running_mode == RunningMode.backtest: self.__account_manager = BfAccountManager(parent=self) # 账户管理 else: self.__account_manager = FDTAccountManager(parent=self) self.mongo_user = MongoUser(self.config.user) self.__trading_manager = TradingManager(self, self.__quotation_manager, self.__account_manager, parent=self) # 交易管理器 if self.config.running_mode == RunningMode.backtest: self.__account_manager.set_trading_manager(self.__trading_manager) self.__strategys = {} # 策略管理器 self.__profit_records = [] # 保存账户净值的列表 self.logger_name = "StrategyEngine"
def __init__(self, parent=None): LoggerInterface.__init__(self, parent=parent) Runnable.__init__(self) self.factory = DataClientFactory(parent=self)