def __init__(self, data_source): self._data_source = data_source try: self.get_risk_free_rate = data_source.get_risk_free_rate except AttributeError: pass InstrumentMixin.__init__(self, data_source.get_all_instruments()) TradingDatesMixin.__init__(self, data_source.get_trading_calendar())
def __init__(self, data_source, price_board): self._data_source = data_source self._price_board = price_board try: self.get_risk_free_rate = data_source.get_risk_free_rate except AttributeError: pass InstrumentMixin.__init__(self, data_source.get_all_instruments()) try: trading_calendars = data_source.get_trading_calendars() except NotImplementedError: # forward compatible trading_calendars = { TRADING_CALENDAR_TYPE.EXCHANGE: data_source.get_trading_calendar() } TradingDatesMixin.__init__(self, trading_calendars)
def __init__(self, path = '~/'): data_path = os.path.join(path, ".rqalpha") data_bundle_path = os.path.join(os.path.expanduser(data_path), "bundle") if not os.path.isdir(data_bundle_path ): print("not exist this file", data_bundle_path) exit(-1) data_source = BaseDataSource(data_bundle_path) self.data_source_ = data_source Instru = InstrumentMixin(data_source._instruments._instruments) self.sym_inst_ = Instru self.insts_ = data_source._instruments._instruments
if not os.path.exists(path_market): os.makedirs(path_market) scu = SCU(path=path) stocks = scu.stock_codes_remove_no_stock_basic() stocks = scu.add_allstock_xshg_xshe(stocks) #rqa.update_bundle() rqalpha_path = r"~/.rqalpha" data_bundle_path = os.path.join(os.path.expanduser(rqalpha_path), "bundle") if not os.path.isdir(data_bundle_path): print("not exist this file", data_bundle_path) exit(-1) data_source = BaseDataSource(data_bundle_path) Instru = InstrumentMixin(data_source._instruments._instruments) # for stock_code in stocks: # print('procesing...',stock_code) # stock_data = pd.DataFrame(data_source._all_day_bars_of(Instru.instruments(stock_code))) # stock_data.datetime = stock_data.datetime.apply(lambda x: datetime.strptime(str(x)[:-6],'%Y%m%d')) # stock_data.to_csv(os.path.join(path_market,stock_code[:-5]+'.csv'),index=False) date_time = date(2019, 9, 5) bars = data_source.history_bars(instrument = Instru.instruments('603032.XSHG'), bar_count = 100, frequency = '1d', fields = 'close', dt = date_time, skip_suspended=False, adjust_orig = date_time) bar_series = pd.Series(bars) bar_pct = bar_series.pct_change() bar_means = np.mean(bar_pct) bar_vars = np.var(bar_pct)
path = '../../../data/' path_market = os.path.join(path, 'trade_market') if not os.path.exists(path_market): os.makedirs(path_market) scu = SCU(path=path) stocks = scu.stock_codes_remove_no_stock_basic() stocks = scu.add_allstock_xshg_xshe(stocks) #rqa.update_bundle() rqalpha_path = "~/.rqalpha" data_bundle_path = os.path.join(os.path.expanduser(rqalpha_path), "bundle") data = BaseDataSource(data_bundle_path) Instru = InstrumentMixin(data._instruments._instruments) for stock_code in stocks: print('procesing...', stock_code) stock_data = pd.DataFrame( data._all_day_bars_of(Instru.instruments(stock_code))) stock_data.datetime = stock_data.datetime.apply( lambda x: datetime.strptime(str(x)[:-6], '%Y%m%d')) stock_data.to_csv(os.path.join(path_market, stock_code[:-5] + '.csv'), index=False) sec_name = [] sec_index = [] for k, v in Instru._sym_id_map.items(): sec_name.append(k) sec_index.append(v)