复制链接
克隆策略

深度学习在期货高频上的应用

策略思想:

使用最近50分钟的价格、成交量、持仓量数据预测未来50分钟的涨跌幅。

交易标的:

股指期货 IF1906

模型算法:

LSTM深度学习算法

模型标注:

未来50分钟收益率

模型因子:

mean(open_intl,5)/amount
mean(open_intl,10)/amount
mean(open_intl,20)/amount
mean(open_intl,30)/amount
mean(open_intl,50)/amount
close/shift(close,30)
close/shift(close,20)
close/shift(close,10)
close/shift(close,5)
mean(amount,30)
max(high,10)/close 
open_intl
sum(open_intl,10)/amount 
amount/open_intl
mean(amount/open_intl,5)
mean(amount/open_intl,10)
mean(open_intl,5)

交易信号:

当预测值大于0.2时并且没有多仓,进场做多。
当预测值小于0.2时平掉所持有的多仓。

    {"description":"实验创建于2017/11/15","graph":{"edges":[{"to_node_id":"-264:options_data","from_node_id":"-214:data_1"},{"to_node_id":"-316:inputs","from_node_id":"-210:data"},{"to_node_id":"-218:inputs","from_node_id":"-210:data"},{"to_node_id":"-1474:inputs","from_node_id":"-218:data"},{"to_node_id":"-320:input_model","from_node_id":"-316:data"},{"to_node_id":"-332:trained_model","from_node_id":"-320:data"},{"to_node_id":"-214:input_1","from_node_id":"-332:data"},{"to_node_id":"-364:features","from_node_id":"-2295:data"},{"to_node_id":"-316:outputs","from_node_id":"-259:data"},{"to_node_id":"-293:input_1","from_node_id":"-620:data"},{"to_node_id":"-264:instruments","from_node_id":"-620:data"},{"to_node_id":"-1481:inputs","from_node_id":"-1403:data"},{"to_node_id":"-1403:inputs","from_node_id":"-1474:data"},{"to_node_id":"-259:inputs","from_node_id":"-1481:data"},{"to_node_id":"-364:input_data","from_node_id":"-293:data_1"},{"to_node_id":"-373:input_data","from_node_id":"-364:data"},{"to_node_id":"-379:input_data","from_node_id":"-364:data"},{"to_node_id":"-384:input_data","from_node_id":"-373:data"},{"to_node_id":"-395:input_data","from_node_id":"-379:data"},{"to_node_id":"-3633:input_data","from_node_id":"-384:data"},{"to_node_id":"-399:input_data","from_node_id":"-395:data"},{"to_node_id":"-214:input_2","from_node_id":"-395:data"},{"to_node_id":"-332:input_data","from_node_id":"-399:data"},{"to_node_id":"-399:features","from_node_id":"-406:data"},{"to_node_id":"-3633:features","from_node_id":"-406:data"},{"to_node_id":"-320:training_data","from_node_id":"-3633:data"}],"nodes":[{"node_id":"-214","module_id":"BigQuantSpace.cached.cached-v3","parameters":[{"name":"run","value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n predictions = input_1.read_pickle()\n pred_result = predictions.reshape(predictions.shape[0]) \n dt = input_2.read_df()['date']\n pred_df = pd.Series(pred_result, index=dt)\n ds = DataSource.write_df(pred_df)\n return Outputs(data_1=ds)\n","type":"Literal","bound_global_parameter":null},{"name":"post_run","value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","type":"Literal","bound_global_parameter":null},{"name":"input_ports","value":"","type":"Literal","bound_global_parameter":null},{"name":"params","value":"{}","type":"Literal","bound_global_parameter":null},{"name":"output_ports","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_1","node_id":"-214"},{"name":"input_2","node_id":"-214"},{"name":"input_3","node_id":"-214"}],"output_ports":[{"name":"data_1","node_id":"-214"},{"name":"data_2","node_id":"-214"},{"name":"data_3","node_id":"-214"}],"cacheable":true,"seq_num":2,"comment":"模型预测结果输出","comment_collapsed":false},{"node_id":"-210","module_id":"BigQuantSpace.dl_layer_input.dl_layer_input-v1","parameters":[{"name":"shape","value":"50,17","type":"Literal","bound_global_parameter":null},{"name":"batch_shape","value":"","type":"Literal","bound_global_parameter":null},{"name":"dtype","value":"float32","type":"Literal","bound_global_parameter":null},{"name":"sparse","value":"False","type":"Literal","bound_global_parameter":null},{"name":"name","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"inputs","node_id":"-210"}],"output_ports":[{"name":"data","node_id":"-210"}],"cacheable":false,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-218","module_id":"BigQuantSpace.dl_layer_lstm.dl_layer_lstm-v1","parameters":[{"name":"units","value":"32","type":"Literal","bound_global_parameter":null},{"name":"activation","value":"linear","type":"Literal","bound_global_parameter":null},{"name":"user_activation","value":"","type":"Literal","bound_global_parameter":null},{"name":"recurrent_activation","value":"hard_sigmoid","type":"Literal","bound_global_parameter":null},{"name":"user_recurrent_activation","value":"","type":"Literal","bound_global_parameter":null},{"name":"use_bias","value":"True","type":"Literal","bound_global_parameter":null},{"name":"kernel_initializer","value":"glorot_uniform","type":"Literal","bound_global_parameter":null},{"name":"user_kernel_initializer","value":"","type":"Literal","bound_global_parameter":null},{"name":"recurrent_initializer","value":"Orthogonal","type":"Literal","bound_global_parameter":null},{"name":"user_recurrent_initializer","value":"","type":"Literal","bound_global_parameter":null},{"name":"bias_initializer","value":"Ones","type":"Literal","bound_global_parameter":null},{"name":"user_bias_initializer","value":"","type":"Literal","bound_global_parameter":null},{"name":"unit_forget_bias","value":"True","type":"Literal","bound_global_parameter":null},{"name":"kernel_regularizer","value":"None","type":"Literal","bound_global_parameter":null},{"name":"kernel_regularizer_l1","value":0,"type":"Literal","bound_global_parameter":null},{"name":"kernel_regularizer_l2","value":0,"type":"Literal","bound_global_parameter":null},{"name":"user_kernel_regularizer","value":"","type":"Literal","bound_global_parameter":null},{"name":"recurrent_regularizer","value":"None","type":"Literal","bound_global_parameter":null},{"name":"recurrent_regularizer_l1","value":0,"type":"Literal","bound_global_parameter":null},{"name":"recurrent_regularizer_l2","value":0,"type":"Literal","bound_global_parameter":null},{"name":"user_recurrent_regularizer","value":"","type":"Literal","bound_global_parameter":null},{"name":"bias_regularizer","value":"None","type":"Literal","bound_global_parameter":null},{"name":"bias_regularizer_l1","value":0,"type":"Literal","bound_global_parameter":null},{"name":"bias_regularizer_l2","value":0,"type":"Literal","bound_global_parameter":null},{"name":"user_bias_regularizer","value":"","type":"Literal","bound_global_parameter":null},{"name":"activity_regularizer","value":"None","type":"Literal","bound_global_parameter":null},{"name":"activity_regularizer_l1","value":0,"type":"Literal","bound_global_parameter":null},{"name":"activity_regularizer_l2","value":0,"type":"Literal","bound_global_parameter":null},{"name":"user_activity_regularizer","value":"","type":"Literal","bound_global_parameter":null},{"name":"kernel_constraint","value":"None","type":"Literal","bound_global_parameter":null},{"name":"user_kernel_constraint","value":"","type":"Literal","bound_global_parameter":null},{"name":"recurrent_constraint","value":"None","type":"Literal","bound_global_parameter":null},{"name":"user_recurrent_constraint","value":"","type":"Literal","bound_global_parameter":null},{"name":"bias_constraint","value":"None","type":"Literal","bound_global_parameter":null},{"name":"user_bias_constraint","value":"","type":"Literal","bound_global_parameter":null},{"name":"dropout","value":"0","type":"Literal","bound_global_parameter":null},{"name":"recurrent_dropout","value":0,"type":"Literal","bound_global_parameter":null},{"name":"return_sequences","value":"True","type":"Literal","bound_global_parameter":null},{"name":"implementation","value":"0","type":"Literal","bound_global_parameter":null},{"name":"name","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"inputs","node_id":"-218"}],"output_ports":[{"name":"data","node_id":"-218"}],"cacheable":false,"seq_num":4,"comment":"","comment_collapsed":true},{"node_id":"-316","module_id":"BigQuantSpace.dl_model_init.dl_model_init-v1","parameters":[],"input_ports":[{"name":"inputs","node_id":"-316"},{"name":"outputs","node_id":"-316"}],"output_ports":[{"name":"data","node_id":"-316"}],"cacheable":false,"seq_num":5,"comment":"","comment_collapsed":true},{"node_id":"-320","module_id":"BigQuantSpace.dl_model_train.dl_model_train-v1","parameters":[{"name":"optimizer","value":"RMSprop","type":"Literal","bound_global_parameter":null},{"name":"user_optimizer","value":"","type":"Literal","bound_global_parameter":null},{"name":"loss","value":"mean_squared_error","type":"Literal","bound_global_parameter":null},{"name":"user_loss","value":"","type":"Literal","bound_global_parameter":null},{"name":"metrics","value":"mse","type":"Literal","bound_global_parameter":null},{"name":"batch_size","value":"256","type":"Literal","bound_global_parameter":null},{"name":"epochs","value":"5","type":"Literal","bound_global_parameter":null},{"name":"earlystop","value":"","type":"Literal","bound_global_parameter":null},{"name":"custom_objects","value":"# 用户的自定义层需要写到字典中,比如\n# {\n# \"MyLayer\": MyLayer\n# }\nbigquant_run = {\n \n}\n","type":"Literal","bound_global_parameter":null},{"name":"n_gpus","value":"0","type":"Literal","bound_global_parameter":null},{"name":"verbose","value":"1:输出进度条记录","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_model","node_id":"-320"},{"name":"training_data","node_id":"-320"},{"name":"validation_data","node_id":"-320"}],"output_ports":[{"name":"data","node_id":"-320"}],"cacheable":true,"seq_num":6,"comment":"","comment_collapsed":true},{"node_id":"-332","module_id":"BigQuantSpace.dl_model_predict.dl_model_predict-v1","parameters":[{"name":"batch_size","value":"128","type":"Literal","bound_global_parameter":null},{"name":"n_gpus","value":"0","type":"Literal","bound_global_parameter":null},{"name":"verbose","value":"0:不显示","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"trained_model","node_id":"-332"},{"name":"input_data","node_id":"-332"}],"output_ports":[{"name":"data","node_id":"-332"}],"cacheable":true,"seq_num":7,"comment":"","comment_collapsed":true},{"node_id":"-2295","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"mean(open_intl,5)/amount\nmean(open_intl,10)/amount\nmean(open_intl,20)/amount\nmean(open_intl,30)/amount\nmean(open_intl,50)/amount\nclose/shift(close,30)\nclose/shift(close,20)\nclose/shift(close,10)\nclose/shift(close,5)\nmean(amount,30)\nmax(high,10)/close \nopen_intl\nsum(open_intl,10)/amount \namount/open_intl\nmean(amount/open_intl,5)\nmean(amount/open_intl,10)\nmean(open_intl,5)\nlabel= shift(close,-50)/close-1\n\n\n","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-2295"}],"output_ports":[{"name":"data","node_id":"-2295"}],"cacheable":true,"seq_num":8,"comment":"","comment_collapsed":true},{"node_id":"-259","module_id":"BigQuantSpace.dl_layer_dense.dl_layer_dense-v1","parameters":[{"name":"units","value":"1","type":"Literal","bound_global_parameter":null},{"name":"activation","value":"linear","type":"Literal","bound_global_parameter":null},{"name":"user_activation","value":"","type":"Literal","bound_global_parameter":null},{"name":"use_bias","value":"True","type":"Literal","bound_global_parameter":null},{"name":"kernel_initializer","value":"glorot_uniform","type":"Literal","bound_global_parameter":null},{"name":"user_kernel_initializer","value":"","type":"Literal","bound_global_parameter":null},{"name":"bias_initializer","value":"Zeros","type":"Literal","bound_global_parameter":null},{"name":"user_bias_initializer","value":"","type":"Literal","bound_global_parameter":null},{"name":"kernel_regularizer","value":"None","type":"Literal","bound_global_parameter":null},{"name":"kernel_regularizer_l1","value":0,"type":"Literal","bound_global_parameter":null},{"name":"kernel_regularizer_l2","value":0,"type":"Literal","bound_global_parameter":null},{"name":"user_kernel_regularizer","value":"","type":"Literal","bound_global_parameter":null},{"name":"bias_regularizer","value":"None","type":"Literal","bound_global_parameter":null},{"name":"bias_regularizer_l1","value":0,"type":"Literal","bound_global_parameter":null},{"name":"bias_regularizer_l2","value":0,"type":"Literal","bound_global_parameter":null},{"name":"user_bias_regularizer","value":"","type":"Literal","bound_global_parameter":null},{"name":"activity_regularizer","value":"None","type":"Literal","bound_global_parameter":null},{"name":"activity_regularizer_l1","value":0,"type":"Literal","bound_global_parameter":null},{"name":"activity_regularizer_l2","value":0,"type":"Literal","bound_global_parameter":null},{"name":"user_activity_regularizer","value":"","type":"Literal","bound_global_parameter":null},{"name":"kernel_constraint","value":"None","type":"Literal","bound_global_parameter":null},{"name":"user_kernel_constraint","value":"","type":"Literal","bound_global_parameter":null},{"name":"bias_constraint","value":"None","type":"Literal","bound_global_parameter":null},{"name":"user_bias_constraint","value":"","type":"Literal","bound_global_parameter":null},{"name":"name","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"inputs","node_id":"-259"}],"output_ports":[{"name":"data","node_id":"-259"}],"cacheable":false,"seq_num":9,"comment":"","comment_collapsed":true},{"node_id":"-620","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2019-04-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2019-06-22","type":"Literal","bound_global_parameter":null},{"name":"market","value":"CN_FUTURE","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"IF1906.CFX\n ","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":0,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"-620"}],"output_ports":[{"name":"data","node_id":"-620"}],"cacheable":true,"seq_num":24,"comment":"证券标的及起始截止时间","comment_collapsed":false},{"node_id":"-1403","module_id":"BigQuantSpace.dl_layer_lstm.dl_layer_lstm-v1","parameters":[{"name":"units","value":"32","type":"Literal","bound_global_parameter":null},{"name":"activation","value":"sigmoid","type":"Literal","bound_global_parameter":null},{"name":"user_activation","value":"","type":"Literal","bound_global_parameter":null},{"name":"recurrent_activation","value":"hard_sigmoid","type":"Literal","bound_global_parameter":null},{"name":"user_recurrent_activation","value":"","type":"Literal","bound_global_parameter":null},{"name":"use_bias","value":"True","type":"Literal","bound_global_parameter":null},{"name":"kernel_initializer","value":"glorot_uniform","type":"Literal","bound_global_parameter":null},{"name":"user_kernel_initializer","value":"","type":"Literal","bound_global_parameter":null},{"name":"recurrent_initializer","value":"Orthogonal","type":"Literal","bound_global_parameter":null},{"name":"user_recurrent_initializer","value":"","type":"Literal","bound_global_parameter":null},{"name":"bias_initializer","value":"Zeros","type":"Literal","bound_global_parameter":null},{"name":"user_bias_initializer","value":"","type":"Literal","bound_global_parameter":null},{"name":"unit_forget_bias","value":"True","type":"Literal","bound_global_parameter":null},{"name":"kernel_regularizer","value":"None","type":"Literal","bound_global_parameter":null},{"name":"kernel_regularizer_l1","value":0,"type":"Literal","bound_global_parameter":null},{"name":"kernel_regularizer_l2","value":0,"type":"Literal","bound_global_parameter":null},{"name":"user_kernel_regularizer","value":"","type":"Literal","bound_global_parameter":null},{"name":"recurrent_regularizer","value":"None","type":"Literal","bound_global_parameter":null},{"name":"recurrent_regularizer_l1","value":0,"type":"Literal","bound_global_parameter":null},{"name":"recurrent_regularizer_l2","value":0,"type":"Literal","bound_global_parameter":null},{"name":"user_recurrent_regularizer","value":"","type":"Literal","bound_global_parameter":null},{"name":"bias_regularizer","value":"None","type":"Literal","bound_global_parameter":null},{"name":"bias_regularizer_l1","value":0,"type":"Literal","bound_global_parameter":null},{"name":"bias_regularizer_l2","value":0,"type":"Literal","bound_global_parameter":null},{"name":"user_bias_regularizer","value":"","type":"Literal","bound_global_parameter":null},{"name":"activity_regularizer","value":"None","type":"Literal","bound_global_parameter":null},{"name":"activity_regularizer_l1","value":0,"type":"Literal","bound_global_parameter":null},{"name":"activity_regularizer_l2","value":0,"type":"Literal","bound_global_parameter":null},{"name":"user_activity_regularizer","value":"","type":"Literal","bound_global_parameter":null},{"name":"kernel_constraint","value":"None","type":"Literal","bound_global_parameter":null},{"name":"user_kernel_constraint","value":"","type":"Literal","bound_global_parameter":null},{"name":"recurrent_constraint","value":"None","type":"Literal","bound_global_parameter":null},{"name":"user_recurrent_constraint","value":"","type":"Literal","bound_global_parameter":null},{"name":"bias_constraint","value":"None","type":"Literal","bound_global_parameter":null},{"name":"user_bias_constraint","value":"","type":"Literal","bound_global_parameter":null},{"name":"dropout","value":0,"type":"Literal","bound_global_parameter":null},{"name":"recurrent_dropout","value":0,"type":"Literal","bound_global_parameter":null},{"name":"return_sequences","value":"False","type":"Literal","bound_global_parameter":null},{"name":"implementation","value":"0","type":"Literal","bound_global_parameter":null},{"name":"name","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"inputs","node_id":"-1403"}],"output_ports":[{"name":"data","node_id":"-1403"}],"cacheable":false,"seq_num":25,"comment":"","comment_collapsed":true},{"node_id":"-1474","module_id":"BigQuantSpace.dl_layer_dropout.dl_layer_dropout-v1","parameters":[{"name":"rate","value":"0.2","type":"Literal","bound_global_parameter":null},{"name":"noise_shape","value":"","type":"Literal","bound_global_parameter":null},{"name":"seed","value":"0","type":"Literal","bound_global_parameter":null},{"name":"name","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"inputs","node_id":"-1474"}],"output_ports":[{"name":"data","node_id":"-1474"}],"cacheable":false,"seq_num":10,"comment":"","comment_collapsed":true},{"node_id":"-1481","module_id":"BigQuantSpace.dl_layer_dropout.dl_layer_dropout-v1","parameters":[{"name":"rate","value":"0.1","type":"Literal","bound_global_parameter":null},{"name":"noise_shape","value":"","type":"Literal","bound_global_parameter":null},{"name":"seed","value":"0","type":"Literal","bound_global_parameter":null},{"name":"name","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"inputs","node_id":"-1481"}],"output_ports":[{"name":"data","node_id":"-1481"}],"cacheable":false,"seq_num":11,"comment":"","comment_collapsed":true},{"node_id":"-293","module_id":"BigQuantSpace.cached.cached-v3","parameters":[{"name":"run","value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n \n start_date=input_1.read_pickle()['start_date']\n end_date=input_1.read_pickle()['end_date']\n ins=input_1.read_pickle()['instruments']\n df = DataSource('bar1m_CN_FUTURE').read(instruments=ins,start_date=start_date,end_date=end_date) #bar1m_IF1906.CFE\n \n df['adjust_factor']=1.0\n data_1 = DataSource.write_df(df)\n return Outputs(data_1=data_1, data_2=None, data_3=None)\n\n ","type":"Literal","bound_global_parameter":null},{"name":"post_run","value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","type":"Literal","bound_global_parameter":null},{"name":"input_ports","value":"","type":"Literal","bound_global_parameter":null},{"name":"params","value":"{}","type":"Literal","bound_global_parameter":null},{"name":"output_ports","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_1","node_id":"-293"},{"name":"input_2","node_id":"-293"},{"name":"input_3","node_id":"-293"}],"output_ports":[{"name":"data_1","node_id":"-293"},{"name":"data_2","node_id":"-293"},{"name":"data_3","node_id":"-293"}],"cacheable":true,"seq_num":20,"comment":"","comment_collapsed":true},{"node_id":"-364","module_id":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","parameters":[{"name":"date_col","value":"date","type":"Literal","bound_global_parameter":null},{"name":"instrument_col","value":"instrument","type":"Literal","bound_global_parameter":null},{"name":"drop_na","value":"False","type":"Literal","bound_global_parameter":null},{"name":"remove_extra_columns","value":"False","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"{}","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-364"},{"name":"features","node_id":"-364"}],"output_ports":[{"name":"data","node_id":"-364"}],"cacheable":true,"seq_num":12,"comment":"","comment_collapsed":true},{"node_id":"-373","module_id":"BigQuantSpace.filter.filter-v3","parameters":[{"name":"expr","value":"date<'2019-06-01'","type":"Literal","bound_global_parameter":null},{"name":"output_left_data","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-373"}],"output_ports":[{"name":"data","node_id":"-373"},{"name":"left_data","node_id":"-373"}],"cacheable":true,"seq_num":16,"comment":"","comment_collapsed":true},{"node_id":"-379","module_id":"BigQuantSpace.filter.filter-v3","parameters":[{"name":"expr","value":"date>='2019-06-01'","type":"Literal","bound_global_parameter":null},{"name":"output_left_data","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-379"}],"output_ports":[{"name":"data","node_id":"-379"},{"name":"left_data","node_id":"-379"}],"cacheable":true,"seq_num":21,"comment":"","comment_collapsed":true},{"node_id":"-384","module_id":"BigQuantSpace.dropnan.dropnan-v1","parameters":[],"input_ports":[{"name":"input_data","node_id":"-384"}],"output_ports":[{"name":"data","node_id":"-384"}],"cacheable":true,"seq_num":28,"comment":"去掉为nan的数据","comment_collapsed":true},{"node_id":"-395","module_id":"BigQuantSpace.dropnan.dropnan-v1","parameters":[],"input_ports":[{"name":"input_data","node_id":"-395"}],"output_ports":[{"name":"data","node_id":"-395"}],"cacheable":true,"seq_num":13,"comment":"去掉为nan的数据","comment_collapsed":true},{"node_id":"-399","module_id":"BigQuantSpace.dl_convert_to_bin.dl_convert_to_bin-v2","parameters":[{"name":"window_size","value":"50","type":"Literal","bound_global_parameter":null},{"name":"feature_clip","value":"5","type":"Literal","bound_global_parameter":null},{"name":"flatten","value":"False","type":"Literal","bound_global_parameter":null},{"name":"window_along_col","value":"instrument","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-399"},{"name":"features","node_id":"-399"}],"output_ports":[{"name":"data","node_id":"-399"}],"cacheable":true,"seq_num":17,"comment":"","comment_collapsed":true},{"node_id":"-406","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"mean(open_intl,5)/amount\nmean(open_intl,10)/amount\nmean(open_intl,20)/amount\nmean(open_intl,30)/amount\nmean(open_intl,50)/amount\nclose/shift(close,30)\nclose/shift(close,20)\nclose/shift(close,10)\nclose/shift(close,5)\nmean(amount,30)\nmax(high,10)/close \nopen_intl\nsum(open_intl,10)/amount \namount/open_intl\nmean(amount/open_intl,5)\nmean(amount/open_intl,10)\nmean(open_intl,5)","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-406"}],"output_ports":[{"name":"data","node_id":"-406"}],"cacheable":true,"seq_num":15,"comment":"","comment_collapsed":true},{"node_id":"-3633","module_id":"BigQuantSpace.dl_convert_to_bin.dl_convert_to_bin-v2","parameters":[{"name":"window_size","value":"50","type":"Literal","bound_global_parameter":null},{"name":"feature_clip","value":"5","type":"Literal","bound_global_parameter":null},{"name":"flatten","value":"False","type":"Literal","bound_global_parameter":null},{"name":"window_along_col","value":"instrument","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-3633"},{"name":"features","node_id":"-3633"}],"output_ports":[{"name":"data","node_id":"-3633"}],"cacheable":true,"seq_num":14,"comment":"","comment_collapsed":true},{"node_id":"-264","module_id":"BigQuantSpace.hftrade.hftrade-v2","parameters":[{"name":"start_date","value":"2019-06-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"initialize","value":"# 交易引擎:初始化函数,只执行一次\ndef bigquant_run(context):\n # 加载预测数据\n context.prediction = context.options['data'].read_df()\n","type":"Literal","bound_global_parameter":null},{"name":"before_trading_start","value":"# 交易引擎:每个单位时间开盘前调用一次。\ndef bigquant_run(context, data):\n # 盘前处理,订阅行情等\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"handle_tick","value":"# 交易引擎:tick数据处理函数,每个tick执行一次\ndef bigquant_run(context, tick):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"handle_data","value":"# 交易引擎:bar数据处理函数,每个时间单位执行一次\ndef bigquant_run(context, data):\n # 按日期过滤得到今日的预测数据\n try:\n prediction = context.prediction[data.current_dt]\n except KeyError as e:\n return\n instrument = context.instruments[0]\n cur_position = context.get_position(instrument, Direction.LONG)\n # 交易逻辑\n if prediction > 0.2 and cur_position.current_qty == 0:\n context.order_target(instrument, 1)\n print(data.current_dt, '买入!')\n \n elif prediction < -0.2 and cur_position.current_qty > 0:\n context.order_target(instrument, 0)\n print(data.current_dt, '卖出!')\n","type":"Literal","bound_global_parameter":null},{"name":"handle_trade","value":"# 交易引擎:成交回报处理函数,每个成交发生时执行一次\ndef bigquant_run(context, trade):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"handle_order","value":"# 交易引擎:委托回报处理函数,每个委托变化时执行一次\ndef bigquant_run(context, order):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"after_trading","value":"# 交易引擎:盘后处理函数,每日盘后执行一次\ndef bigquant_run(context, data):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"capital_base","value":1000000,"type":"Literal","bound_global_parameter":null},{"name":"frequency","value":"minute","type":"Literal","bound_global_parameter":null},{"name":"price_type","value":"真实价格","type":"Literal","bound_global_parameter":null},{"name":"product_type","value":"期货","type":"Literal","bound_global_parameter":null},{"name":"before_start_days","value":"0","type":"Literal","bound_global_parameter":null},{"name":"order_price_field_buy","value":"open","type":"Literal","bound_global_parameter":null},{"name":"order_price_field_sell","value":"open","type":"Literal","bound_global_parameter":null},{"name":"benchmark","value":"000300.HIX","type":"Literal","bound_global_parameter":null},{"name":"plot_charts","value":"True","type":"Literal","bound_global_parameter":null},{"name":"disable_cache","value":"False","type":"Literal","bound_global_parameter":null},{"name":"replay_bdb","value":"False","type":"Literal","bound_global_parameter":null},{"name":"show_debug_info","value":"False","type":"Literal","bound_global_parameter":null},{"name":"backtest_only","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-264"},{"name":"options_data","node_id":"-264"},{"name":"history_ds","node_id":"-264"},{"name":"benchmark_ds","node_id":"-264"}],"output_ports":[{"name":"raw_perf","node_id":"-264"}],"cacheable":false,"seq_num":19,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-214' Position='846.3192138671875,665.2431640625,200,200'/><node_position Node='-210' Position='22,-89,200,200'/><node_position Node='-218' Position='9,25,200,200'/><node_position Node='-316' Position='19,474,200,200'/><node_position Node='-320' Position='312.52984619140625,523.2377319335938,200,200'/><node_position Node='-332' Position='394,616,200,200'/><node_position Node='-2295' Position='673,-332,200,200'/><node_position Node='-259' Position='15,376,200,200'/><node_position Node='-620' Position='342,-341,200,200'/><node_position Node='-1403' Position='17,197,200,200'/><node_position Node='-1474' Position='14,109,200,200'/><node_position Node='-1481' Position='14,275,200,200'/><node_position Node='-293' Position='524,-250,200,200'/><node_position Node='-364' Position='527,-191,200,200'/><node_position Node='-373' Position='421,-68,200,200'/><node_position Node='-379' Position='794,-62,200,200'/><node_position Node='-384' Position='392,106,200,200'/><node_position Node='-395' Position='786,39,200,200'/><node_position Node='-399' Position='961,378,200,200'/><node_position Node='-406' Position='656,163,200,200'/><node_position Node='-3633' Position='401,326,200,200'/><node_position Node='-264' Position='723.2852172851562,783.7241821289062,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [28]:
    # 本代码由可视化策略环境自动生成 2022年6月24日 09:49
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m20_run_bigquant_run(input_1, input_2, input_3):
         
        start_date=input_1.read_pickle()['start_date']
        end_date=input_1.read_pickle()['end_date']
        ins=input_1.read_pickle()['instruments']
        df = DataSource('bar1m_CN_FUTURE').read(instruments=ins,start_date=start_date,end_date=end_date) #bar1m_IF1906.CFE
        
        df['adjust_factor']=1.0
        data_1 = DataSource.write_df(df)
        return Outputs(data_1=data_1, data_2=None, data_3=None)
    
     
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m20_post_run_bigquant_run(outputs):
        return outputs
    
    # 用户的自定义层需要写到字典中,比如
    # {
    #   "MyLayer": MyLayer
    # }
    m6_custom_objects_bigquant_run = {
        
    }
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m2_run_bigquant_run(input_1, input_2, input_3):
        predictions = input_1.read_pickle()
        pred_result = predictions.reshape(predictions.shape[0]) 
        dt = input_2.read_df()['date']
        pred_df = pd.Series(pred_result, index=dt)
        ds = DataSource.write_df(pred_df)
        return Outputs(data_1=ds)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m2_post_run_bigquant_run(outputs):
        return outputs
    
    # 交易引擎:初始化函数,只执行一次
    def m19_initialize_bigquant_run(context):
         # 加载预测数据
        context.prediction = context.options['data'].read_df()
    
    # 交易引擎:每个单位时间开盘前调用一次。
    def m19_before_trading_start_bigquant_run(context, data):
        # 盘前处理,订阅行情等
        pass
    
    # 交易引擎:tick数据处理函数,每个tick执行一次
    def m19_handle_tick_bigquant_run(context, tick):
        pass
    
    # 交易引擎:bar数据处理函数,每个时间单位执行一次
    def m19_handle_data_bigquant_run(context, data):
        # 按日期过滤得到今日的预测数据
        try:
            prediction = context.prediction[data.current_dt]
        except KeyError as e:
            return
        instrument = context.instruments[0]
        cur_position = context.get_position(instrument, Direction.LONG)
        # 交易逻辑
        if prediction > 0.2 and cur_position.current_qty == 0:
            context.order_target(instrument, 1)
            print(data.current_dt, '买入!')
            
        elif prediction < -0.2 and cur_position.current_qty > 0:
            context.order_target(instrument, 0)
            print(data.current_dt, '卖出!')
    
    # 交易引擎:成交回报处理函数,每个成交发生时执行一次
    def m19_handle_trade_bigquant_run(context, trade):
        pass
    
    # 交易引擎:委托回报处理函数,每个委托变化时执行一次
    def m19_handle_order_bigquant_run(context, order):
        pass
    
    # 交易引擎:盘后处理函数,每日盘后执行一次
    def m19_after_trading_bigquant_run(context, data):
        pass
    
    
    m3 = M.dl_layer_input.v1(
        shape='50,17',
        batch_shape='',
        dtype='float32',
        sparse=False,
        name=''
    )
    
    m4 = M.dl_layer_lstm.v1(
        inputs=m3.data,
        units=32,
        activation='linear',
        recurrent_activation='hard_sigmoid',
        use_bias=True,
        kernel_initializer='glorot_uniform',
        recurrent_initializer='Orthogonal',
        bias_initializer='Ones',
        unit_forget_bias=True,
        kernel_regularizer='None',
        kernel_regularizer_l1=0,
        kernel_regularizer_l2=0,
        recurrent_regularizer='None',
        recurrent_regularizer_l1=0,
        recurrent_regularizer_l2=0,
        bias_regularizer='None',
        bias_regularizer_l1=0,
        bias_regularizer_l2=0,
        activity_regularizer='None',
        activity_regularizer_l1=0,
        activity_regularizer_l2=0,
        kernel_constraint='None',
        recurrent_constraint='None',
        bias_constraint='None',
        dropout=0,
        recurrent_dropout=0,
        return_sequences=True,
        implementation='0',
        name=''
    )
    
    m10 = M.dl_layer_dropout.v1(
        inputs=m4.data,
        rate=0.2,
        noise_shape='',
        seed=0,
        name=''
    )
    
    m25 = M.dl_layer_lstm.v1(
        inputs=m10.data,
        units=32,
        activation='sigmoid',
        recurrent_activation='hard_sigmoid',
        use_bias=True,
        kernel_initializer='glorot_uniform',
        recurrent_initializer='Orthogonal',
        bias_initializer='Zeros',
        unit_forget_bias=True,
        kernel_regularizer='None',
        kernel_regularizer_l1=0,
        kernel_regularizer_l2=0,
        recurrent_regularizer='None',
        recurrent_regularizer_l1=0,
        recurrent_regularizer_l2=0,
        bias_regularizer='None',
        bias_regularizer_l1=0,
        bias_regularizer_l2=0,
        activity_regularizer='None',
        activity_regularizer_l1=0,
        activity_regularizer_l2=0,
        kernel_constraint='None',
        recurrent_constraint='None',
        bias_constraint='None',
        dropout=0,
        recurrent_dropout=0,
        return_sequences=False,
        implementation='0',
        name=''
    )
    
    m11 = M.dl_layer_dropout.v1(
        inputs=m25.data,
        rate=0.1,
        noise_shape='',
        seed=0,
        name=''
    )
    
    m9 = M.dl_layer_dense.v1(
        inputs=m11.data,
        units=1,
        activation='linear',
        use_bias=True,
        kernel_initializer='glorot_uniform',
        bias_initializer='Zeros',
        kernel_regularizer='None',
        kernel_regularizer_l1=0,
        kernel_regularizer_l2=0,
        bias_regularizer='None',
        bias_regularizer_l1=0,
        bias_regularizer_l2=0,
        activity_regularizer='None',
        activity_regularizer_l1=0,
        activity_regularizer_l2=0,
        kernel_constraint='None',
        bias_constraint='None',
        name=''
    )
    
    m5 = M.dl_model_init.v1(
        inputs=m3.data,
        outputs=m9.data
    )
    
    m8 = M.input_features.v1(
        features="""mean(open_intl,5)/amount
    mean(open_intl,10)/amount
    mean(open_intl,20)/amount
    mean(open_intl,30)/amount
    mean(open_intl,50)/amount
    close/shift(close,30)
    close/shift(close,20)
    close/shift(close,10)
    close/shift(close,5)
    mean(amount,30)
    max(high,10)/close 
    open_intl
    sum(open_intl,10)/amount 
    amount/open_intl
    mean(amount/open_intl,5)
    mean(amount/open_intl,10)
    mean(open_intl,5)
    label= shift(close,-50)/close-1
    
    
    """
    )
    
    m24 = M.instruments.v2(
        start_date='2019-04-01',
        end_date='2019-06-22',
        market='CN_FUTURE',
        instrument_list="""IF1906.CFX
     """,
        max_count=0
    )
    
    m20 = M.cached.v3(
        input_1=m24.data,
        run=m20_run_bigquant_run,
        post_run=m20_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m12 = M.derived_feature_extractor.v3(
        input_data=m20.data_1,
        features=m8.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m16 = M.filter.v3(
        input_data=m12.data,
        expr='date<\'2019-06-01\'',
        output_left_data=False
    )
    
    m28 = M.dropnan.v1(
        input_data=m16.data
    )
    
    m21 = M.filter.v3(
        input_data=m12.data,
        expr='date>=\'2019-06-01\'',
        output_left_data=False
    )
    
    m13 = M.dropnan.v1(
        input_data=m21.data
    )
    
    m15 = M.input_features.v1(
        features="""mean(open_intl,5)/amount
    mean(open_intl,10)/amount
    mean(open_intl,20)/amount
    mean(open_intl,30)/amount
    mean(open_intl,50)/amount
    close/shift(close,30)
    close/shift(close,20)
    close/shift(close,10)
    close/shift(close,5)
    mean(amount,30)
    max(high,10)/close 
    open_intl
    sum(open_intl,10)/amount 
    amount/open_intl
    mean(amount/open_intl,5)
    mean(amount/open_intl,10)
    mean(open_intl,5)"""
    )
    
    m17 = M.dl_convert_to_bin.v2(
        input_data=m13.data,
        features=m15.data,
        window_size=50,
        feature_clip=5,
        flatten=False,
        window_along_col='instrument'
    )
    
    m14 = M.dl_convert_to_bin.v2(
        input_data=m28.data,
        features=m15.data,
        window_size=50,
        feature_clip=5,
        flatten=False,
        window_along_col='instrument'
    )
    
    m6 = M.dl_model_train.v1(
        input_model=m5.data,
        training_data=m14.data,
        optimizer='RMSprop',
        loss='mean_squared_error',
        metrics='mse',
        batch_size=256,
        epochs=5,
        custom_objects=m6_custom_objects_bigquant_run,
        n_gpus=0,
        verbose='1:输出进度条记录'
    )
    
    m7 = M.dl_model_predict.v1(
        trained_model=m6.data,
        input_data=m17.data,
        batch_size=128,
        n_gpus=0,
        verbose='0:不显示'
    )
    
    m2 = M.cached.v3(
        input_1=m7.data,
        input_2=m13.data,
        run=m2_run_bigquant_run,
        post_run=m2_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m19 = M.hftrade.v2(
        instruments=m24.data,
        options_data=m2.data_1,
        start_date='2019-06-01',
        end_date='',
        initialize=m19_initialize_bigquant_run,
        before_trading_start=m19_before_trading_start_bigquant_run,
        handle_tick=m19_handle_tick_bigquant_run,
        handle_data=m19_handle_data_bigquant_run,
        handle_trade=m19_handle_trade_bigquant_run,
        handle_order=m19_handle_order_bigquant_run,
        after_trading=m19_after_trading_bigquant_run,
        capital_base=1000000,
        frequency='minute',
        price_type='真实价格',
        product_type='期货',
        before_start_days='0',
        order_price_field_buy='open',
        order_price_field_sell='open',
        benchmark='000300.HIX',
        plot_charts=True,
        disable_cache=False,
        replay_bdb=False,
        show_debug_info=False,
        backtest_only=False
    )
    
    DataSource(377e2da754ed497d95178968d56aeabfT)
    
    2019-06-03 09:31:00 买入!
    2019-06-03 09:45:00 卖出!
    2019-06-03 09:50:00 买入!
    2019-06-03 09:59:00 卖出!
    2019-06-03 10:08:00 买入!
    
    • 收益率6.04%
    • 年化收益率187.61%
    • 基准收益率5.56%
    • 阿尔法0.0
    • 贝塔1.08
    • 夏普比率4.64
    • 胜率0.5
    • 盈亏比1.87
    • 收益波动率22.67%
    • 最大回撤2.26%
    bigcharts-data-start/{"__type":"tabs","__id":"bigchart-c1d9af158b4044eea185410f7ef5167b"}/bigcharts-data-end