Esempio n. 1
0
  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
Esempio n. 2
0
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)