def _write_data_dicts(self, equities=None, futures=None, exchanges=None, root_symbols=None): AssetDBWriterFromDictionary(equities, futures, exchanges, root_symbols)\ .write_all(self.engine)
def __init__(self, load=None, bm_symbol='^GSPC', exchange_tz="US/Eastern", max_date=None, env_trading_calendar=tradingcalendar, asset_db_path=':memory:'): """ @load is function that returns benchmark_returns and treasury_curves The treasury_curves are expected to be a DataFrame with an index of dates and columns of the curve names, e.g. '10year', '1month', etc. """ self.trading_day = env_trading_calendar.trading_day.copy() # `tc_td` is short for "trading calendar trading days" tc_td = env_trading_calendar.trading_days if max_date: self.trading_days = tc_td[tc_td <= max_date].copy() else: self.trading_days = tc_td.copy() self.first_trading_day = self.trading_days[0] self.last_trading_day = self.trading_days[-1] self.early_closes = env_trading_calendar.get_early_closes( self.first_trading_day, self.last_trading_day) self.open_and_closes = env_trading_calendar.open_and_closes.loc[ self.trading_days] self.prev_environment = self self.bm_symbol = bm_symbol if not load: load = load_market_data self.benchmark_returns, self.treasury_curves = \ load(self.trading_day, self.trading_days, self.bm_symbol) if max_date: tr_c = self.treasury_curves # Mask the treasury curves down to the current date. # In the case of live trading, the last date in the treasury # curves would be the day before the date considered to be # 'today'. self.treasury_curves = tr_c[tr_c.index <= max_date] self.exchange_tz = exchange_tz if isinstance(asset_db_path, string_types): asset_db_path = 'sqlite:///%s' % asset_db_path self.engine = engine = create_engine(asset_db_path) AssetDBWriterFromDictionary().init_db(engine) else: self.engine = engine = asset_db_path if engine is not None: self.asset_finder = AssetFinder(engine) else: self.asset_finder = None
def __init__( self, load=None, bm_symbol='000001', exchange_tz="Asia/Shanghai", min_date=None, max_date=None, env_trading_calendar=tradingcalendar_china, asset_db_path=':memory:' ): """ @load is function that returns benchmark_returns and treasury_curves The treasury_curves are expected to be a DataFrame with an index of dates and columns of the curve names, e.g. '10year', '1month', etc. # load是返回benchmark_returns和treasury_curves的函数.tourasury_curves应该是一个DataFrame, # 其中包含曲线名称的日期和列的索引,例如: '10年','1个月'等 """ self.trading_day = env_trading_calendar.trading_day.copy() # `tc_td` is short for "trading calendar trading days" tc_td = env_trading_calendar.trading_days self.trading_days = tc_td[tc_td.slice_indexer(min_date, max_date)] #print self.trading_day,'trading_days' self.first_trading_day = self.trading_days[0] self.last_trading_day = self.trading_days[-1] #print self.first_trading_day,self.last_trading_day self.early_closes = env_trading_calendar.get_early_closes( self.first_trading_day, self.last_trading_day) self.open_and_closes = env_trading_calendar.open_and_closes.loc[ self.trading_days] self.bm_symbol = bm_symbol if not load: load = load_market_data # 下面的用于基准每日收益情况,以及国债收益率情况 #print self.trading_day #print self.trading_days self.benchmark_returns, self.treasury_curves = \ load(self.trading_day, self.trading_days, self.bm_symbol) #print self.benchmark_returns #raw_input() if max_date: tr_c = self.treasury_curves # Mask the treasury curves down to the current date. # In the case of live trading, the last date in the treasury # curves would be the day before the date considered to be # 'today'. self.treasury_curves = tr_c[tr_c.index <= max_date] self.exchange_tz = exchange_tz if isinstance(asset_db_path, string_types): asset_db_path = 'sqlite:///%s' % asset_db_path self.engine = engine = create_engine(asset_db_path) AssetDBWriterFromDictionary().init_db(engine) else: self.engine = engine = asset_db_path if engine is not None: self.asset_finder = AssetFinder(engine) else: self.asset_finder = None