def test_remote_data_service_daily_quited(): ds = RemoteDataService() # test daily res, msg = ds.daily('600832.SH', fields="", start_date=20140828, end_date=20170831, adjust_mode=None) assert msg == '0,' assert res.shape == (175, 13)
def my_globals(request): ds = RemoteDataService() df, msg = ds.daily("000001.SH, 600030.SH, 000300.SH", start_date=20170801, end_date=20170820, fields="open,high,low,close,vwap,preclose") multi_index_names = ['trade_date', 'symbol'] df_multi = df.set_index(multi_index_names, drop=False) df_multi.sort_index(axis=0, level=multi_index_names, inplace=True) dfx = df_multi.loc[pd.IndexSlice[:, :], pd.IndexSlice['close']].unstack() dfy = df_multi.loc[pd.IndexSlice[:, :], pd.IndexSlice['open']].unstack() parser = Parser() request.function.func_globals.update({'parser': parser, 'dfx': dfx, 'dfy': dfy})
def run_strategy(): start_date = 20150501 end_date = 20171030 index = '399975.SZ' ds = RemoteDataService() ds.init_from_config() symbol_list = ds.get_index_comp(index, start_date, start_date) # add the benchmark index to the last position of symbol_list symbol_list.append(index) props = { "symbol": ','.join(symbol_list), "start_date": start_date, "end_date": end_date, "bar_type": "1d", "init_balance": 1e7, "std multiplier": 1.5, "m": 10, "n": 60, "commission_rate": 2E-4 } tapi = BacktestTradeApi() ins = EventBacktestInstance() strat = SectorRolling() pm = PortfolioManager() context = model.Context(data_api=ds, trade_api=tapi, instance=ins, strategy=strat, pm=pm) ins.init_from_config(props) ins.run() ins.save_results(folder_path=result_dir_path) ta = ana.EventAnalyzer() ta.initialize(data_server_=ds, file_folder=result_dir_path) df_bench, _ = ds.daily(index, start_date=start_date, end_date=end_date) ta.data_benchmark = df_bench.set_index('trade_date').loc[:, ['close']] ta.do_analyze(result_dir=result_dir_path, selected_sec=props['symbol'].split(',')[:2])
def test_remote_data_service_daily(): ds = RemoteDataService() # test daily res, msg = ds.daily('rb1710.SHF,600662.SH', fields="", start_date=20170828, end_date=20170831, adjust_mode=None) assert msg == '0,' rb = res.loc[res.loc[:, 'symbol'] == 'rb1710.SHF', :] stk = res.loc[res.loc[:, 'symbol'] == '600662.SH', :] assert set(rb.columns) == {'close', 'code', 'high', 'low', 'oi', 'open', 'settle', 'symbol', 'trade_date', 'trade_status', 'turnover', 'volume', 'vwap'} assert rb.shape == (4, 13) assert rb.loc[:, 'volume'].values[0] == 189616 assert stk.loc[:, 'volume'].values[0] == 7174813
dfx = df_multi.loc[pd.IndexSlice[:, :], pd.IndexSlice['close']].unstack() dfy = df_multi.loc[pd.IndexSlice[:, :], pd.IndexSlice['open']].unstack() parser = Parser() request.function.func_globals.update({ 'parser': parser, 'dfx': dfx, 'dfy': dfy }) if __name__ == "__main__": ds = RemoteDataService() df, msg = ds.daily("000001.SH, 600030.SH, 000300.SH", start_date=20170801, end_date=20170820, fields="open,high,low,close,vwap,preclose") ds.api.close() multi_index_names = ['trade_date', 'symbol'] df_multi = df.set_index(multi_index_names, drop=False) df_multi.sort_index(axis=0, level=multi_index_names, inplace=True) dfx = df_multi.loc[pd.IndexSlice[:, :], pd.IndexSlice['close']].unstack() dfy = df_multi.loc[pd.IndexSlice[:, :], pd.IndexSlice['open']].unstack() parser = Parser() g = globals() g = {k: v for k, v in g.items() if k.startswith('test_') and callable(v)}