def save_dataview(): data_config = { "remote.data.address": "tcp://data.tushare.org:8910", "remote.data.username": "******", "remote.data.password": "******" #QuantOs API令牌 } ds = RemoteDataService() ds.init_from_config(data_config) dv = DataView() props = { 'start_date': 20140101, 'end_date': 20180101, 'universe': '000300.SH', #'universe': '000300.SH'表示标的股票池取的是沪深300 'fields': "pb,pe,ps,float_mv,sw1,roe", #'fields'表示取的数据,pb,pe,ps分别表示市净率,市盈率,市销率;float_mv代表流通市值,sw1表示申万1级行业分类的数据 'freq': 1 } dv.init_from_config(props, ds) dv.prepare_data() dv.save_dataview(dataview_folder) # 保存数据文件到指定路径,方便下次直接加载
def save_dataview(): data_config = { "remote.data.address": "tcp://data.quantOS.org:8910", "remote.data.username": "******", "remote.data.password": "******" } ds = RemoteDataService() ds.init_from_config(data_config) dv = DataView() props = { 'start_date': 20140101, 'end_date': 20180101, 'universe': '000300.SH', 'fields': "volume,pb,pe,ps,roe,float_mv,sw1", 'freq': 1, 'timeout': 180 } dv.init_from_config(props, ds) dv.prepare_data() dv.save_dataview(dataview_folder) # 保存数据文件到指定路径,方便下次直接加载
def test_write(): ds = RemoteDataService() ds.init_from_config(data_config) dv = DataView() secs = '600030.SH,000063.SZ,000001.SZ' props = { 'start_date': 20160601, 'end_date': 20170601, 'symbol': secs, 'fields': 'open,close,high,low,volume,pb,net_assets,pcf_ncf', 'freq': 1 } dv.init_from_config(props, data_api=ds) dv.prepare_data() assert dv.data_d.shape == (281, 48) assert dv.dates.shape == (281, ) # TODO """ PerformanceWarning: your performance may suffer as PyTables will pickle object types that it cannot map directly to c-types [inferred_type->mixed,key->block1_values] [items->[('000001.SZ', 'int_income'), ('000001.SZ', 'less_handling_chrg_comm_exp'), ('000001.SZ', 'net_int_income'), ('000001.SZ', 'oper_exp'), ('000001.SZ', 'symbol'), ('000063.SZ', 'int_income'), ('000063.SZ', 'less_handling_chrg_comm_exp'), ('000063.SZ', 'net_int_income'), ('000063.SZ', 'oper_exp'), ('000063.SZ', 'symbol'), ('600030.SH', 'int_income'), ('600030.SH', 'less_handling_chrg_comm_exp'), ('600030.SH', 'net_int_income'), ('600030.SH', 'oper_exp'), ('600030.SH', 'symbol')]] """ dv.save_dataview(folder_path=daily_path)
def test_q(): ds = RemoteDataService() ds.init_from_config(data_config) dv = DataView() secs = '600030.SH,000063.SZ,000001.SZ' props = { 'start_date': 20160609, 'end_date': 20170601, 'symbol': secs, 'fields': ('open,close,' + 'pb,net_assets,' + 'total_oper_rev,oper_exp,' + 'cash_paid_invest,' + 'capital_stk,' + 'roe'), 'freq': 1 } dv.init_from_config(props, data_api=ds) dv.prepare_data() dv.save_dataview(folder_path=quarterly_path)
print(group2_code.tail() ) #value="industry1_code"表示以industry2_name为分类标准,不过返回的code类型(类别代号) group3 = dp.daily_sec_industry(api, symbols, start, end, source='zz', value="industry1_name") print(group3.tail()) #source='zz'表示以中证为分类标准,只是分类标准不同而已 group3_code = dp.daily_sec_industry(api, symbols, start, end, source='zz', value="industry1_code") print(group3_code.tail() ) #source='zz'表示以中证为分类标准,只是分类标准不同而已,industry1_code返回的是类别代号(code类型) #3_添加数据保存 dv = DataView() dataview_folder = 'G:/data/hs300' #档案地址 dv.load_dataview(dataview_folder) #加载档案地址 dv.append_df(group, 'group') #将group列加入dv中,后面的'group'为列名 dv.save_dataview('G:/data/hs300') #保存 #获取数据 print(dv.get_ts('group').tail()) A = dv.get_ts('group') #这样看的更清楚点
add_data=True) Factor8 = dv.add_formula('Factor8', '-Ts_Sum(Max(a,0),20)', is_quarterly=False, add_data=True) Factor9 = dv.add_formula('Factor9', '-ps-pb-0.1*pe', is_quarterly=False, add_data=True) Factor10 = dv.add_formula('Factor10', '-BullPower*volume', is_quarterly=False, add_data=True) dv.save_dataview(dataview_folder) alpha_signal = [ 'Factor1', 'Factor2', 'Factor3', 'Factor4', 'Factor5', 'Factor6', 'Factor7', 'Factor8', 'Factor9', 'Factor10' ] for a in alpha_signal: print((dv.get_ts(a)).shape) import matplotlib.pyplot as plt from jaqs_fxdayu.research import SignalDigger from jaqs_fxdayu.util import dp def limit_up_down(): # 定义可买卖条件——未停牌、未涨跌停
"eyJhbGciOiJIUzI1NiJ9.eyJjcmVhdGVfdGltZSI6IjE1NjM5NDc0MzYwMzEiLCJpc3MiOiJhdXRoMCIsImlkIjoiMTc2NjUxMzk1OTcifQ.crFpJTlrqcduHE7zEMms2XhAoggttMLlFSkGWAzyNhY" } # step 2 ds = RemoteDataService() ds.init_from_config(data_config) dv = DataView() sub_period = [(20190130, 20190630)] file_name = ['data'] universe = '000300.SH' # step 3 for i in range(len(sub_period)): props = { 'start_date': sub_period[i][0], 'end_date': sub_period[i][1], 'universe': universe, 'fields': "pb,pe,oper_exp,sw1", 'report_type': '408003000', 'freq': 1 } dv.init_from_config(props, ds) dv.prepare_data() dv.save_dataview('C:/Users/Lenovo/PycharmProjects/my_factor/' + file_name[i] + '_' + universe[0:6]) print(sub_period[i], 'finished')
is_quarterly=False, add_data=True) can_enter = np.logical_and(dv.get_ts('up_limit') < 1, ~mask_sus) # 未涨停未停牌 can_exit = np.logical_and(dv.get_ts('down_limit') < 1, ~mask_sus) # 未跌停未停牌 return can_enter, can_exit mask = mask_index_member() can_enter, can_exit = limit_up_down() #step2: #用append_df的方法将slope_df添加至本地(dataview数据集里) print(dv.fields) #查看dv中取得的数据 dv.append_df(field_name="Union", df=Union, is_quarterly=False ) #用append_df方法将"Union"添加至本地(dataview数据集里),其新名称为df=(Union) dv.append_df(field_name="Intersection", df=Intersection, is_quarterly=False) dv.save_dataview('G:/data/hs300_2') #保存,若不运行,则下次重新运行不会有Union和Intersection #step3:新因子分析: from jaqs_fxdayu.research import SignalDigger import matplotlib.pyplot as plt from jaqs_fxdayu.research.signaldigger.analysis import analysis obj = SignalDigger(output_folder='G:/data', output_format='pdf') def draw_analysis( signal="Union", benchmark_price=None): #同样类似于第二章SignalDigger处理因子的方式,不过这里是定义函数 obj.process_signal_before_analysis( signal=dv.get_ts(signal), price=dv.get_ts("close_adj"),