{"description":"实验创建于2021/12/6","graph":{"edges":[{"to_node_id":"-227:instruments","from_node_id":"-216:data"}],"nodes":[{"node_id":"-216","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2021-10-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2022-10-01","type":"Literal","bound_global_parameter":null},{"name":"market","value":"CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"000001.SZA","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":0,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"-216"}],"output_ports":[{"name":"data","node_id":"-216"}],"cacheable":true,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"-227","module_id":"BigQuantSpace.hftrade.hftrade-v2","parameters":[{"name":"start_date","value":"","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 print(\"initialize\") \n context.ins = context.instruments[0]#从传入参数中获取需要交易的合约\n context.order_num = 4000#下单手数\n context.set_universe(context.ins)#设置需要处理的合约\n context.last_grid = 0 # 储存前一个网格所处区间,用来和最新网格所处区间作比较\n context.closetime_day = \"14:58\"#日内策略白盘平仓时间,一般14:58\n context.set_stock_t1(0)\n context.set_commission(PerOrder(buy_cost=0, sell_cost=0, min_cost=0))\n \n \n \n\n","type":"Literal","bound_global_parameter":null},{"name":"before_trading_start","value":"# 交易引擎:每个单位时间开盘前调用一次。\ndef bigquant_run(context, data):\n context.subscribe(context.ins) #注册合约\n\n # 记录上一次交易时网格范围的变化情况(例如从4区到5区,记为4,5)\n context.grid_change_last = [0,0]\n # 以前一日的收盘价为中枢价格\n context.center = data.history(context.ins,[\"close\"],1,\"1d\").iat[0,0]\n \n ","type":"Literal","bound_global_parameter":null},{"name":"handle_tick","value":"# 交易引擎:tick数据处理函数,每个tick执行一次\ndef bigquant_run(context, data):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"handle_data","value":"def bigquant_run(context, data):\n cur_date = data.current_dt\n cur_hm = cur_date.strftime('%H:%M') #time \n \n # 分别获取持仓\n position = context.get_position(context.ins)\n \n # 获取当前价格\n price = data.current(context.ins, \"close\")\n\n cash = context.portfolio.cash\n cash_num = context.order_num * price\n \n# #尾盘平仓\n# if cur_hm>=context.closetime_day and cur_hm<=\"15:00\" :\n# if(position.current_qty != 0):\n# rv = context.order_target_percent(context.ins, 0, None, order_type=OrderType.MARKET)\n# msg = \"{} 尾盘平仓 for {} 最新价={} 下单函数返回={}\".format(str(data.current_dt),context.ins,str(price),str(rv))\n# context.write_log(msg, stdout=1) #输出关键日志\n# #尾盘不开新仓,直接返回\n# return\n \n # 设置网格和当前价格所处的网格区域\n band = np.arange(0.9, 1.011, 0.001)* context.center\n #band = np.array([0.982, 0.984, 0.986, 0.988, 0.990, 0.992, 0.994, 0.996, 0.998, 1, 1.002, 1.004, 1.006, 1.008, 1.01, 1.012, 1.014, 1.016, 1.018]) * context.center\n grid = pd.cut([price], band, labels=np.arange(1,len(band)))[0]\n # 如果价格超出网格设置范围,则提示调节网格宽度和数量\n# print(position)\n# print(position.current_qty)\n# print('*'*100)\n# print(price)\n# print('#'*100)\n# if np.isnan(grid):\n# context.write_log(\"价格波动超过网格范围,可适当调节网格宽度和数量\", stdout=1) #输出关键日志\n # 如果新的价格所处网格区间和前一个价格所处的网格区间不同,说明触碰到了网格线,需要进行交易\n # 如果新网格大于前一天的网格,做空或平多\n if context.last_grid < grid:\n # 记录新旧格子范围(按照大小排序)\n grid_change_new = [context.last_grid,grid]\n # 几种例外:\n # 当last_grid = 0 时是初始阶段,不构成信号\n # 如果此时grid = 3,说明当前价格仅在开盘价之下的3区域中,没有突破网格线\n # 如果此时grid = 4,说明当前价格仅在开盘价之上的4区域中,没有突破网格线\n if context.last_grid == 0:\n context.last_grid = grid\n return\n if context.last_grid != 0:\n # 如果前一次开仓是4-5,这一次是5-4,算是没有突破,不成交\n if grid_change_new != context.grid_change_last:\n # 更新前一次的数据\n context.last_grid = grid\n context.grid_change_last = grid_change_new\n # 如果有仓位\n if position.current_qty != 0:\n rv = context.order_target_percent(context.ins, 0, None, order_type=OrderType.MARKET)\n# msg = \"{} 平仓 for {} 最新价={} 下单函数返回={}\".format(str(data.current_dt),context.ins,str(price),str(rv))\n# context.write_log(msg, stdout=1) #输出关键日志\n \n \n # 如果新网格小于前一天的网格,开仓\n if context.last_grid > grid:\n # 记录新旧格子范围(按照大小排序)\n grid_change_new = [grid,context.last_grid]\n # 几种例外:\n # 当last_grid = 0 时是初始阶段,不构成信号\n # 如果此时grid = 3,说明当前价格仅在开盘价之下的3区域中,没有突破网格线\n # 如果此时grid = 4,说明当前价格仅在开盘价之上的4区域中,没有突破网格线\n if context.last_grid == 0:\n context.last_grid = grid\n return\n if context.last_grid != 0:\n # 如果前一次开仓是4-5,这一次是5-4,算是没有突破,不成交\n if grid_change_new != context.grid_change_last:\n # 更新前一次的数据\n context.last_grid = grid\n context.grid_change_last = grid_change_new\n \n if cash > cash_num+1000:\n rv = context.order(context.ins, context.order_num, price, order_type=OrderType.MARKET)\n # msg = \"{} 开仓 for {} 最新价={} 下单函数返回={} 可用现金{}\".format(str(data.current_dt),context.ins,str(price),str(rv),str(context.portfolio.cash))\n # context.write_log(msg, stdout=1) #输出关键日志\n \n # 设计一个止盈条件:当持仓量达到10手,全部平仓\n if position.current_qty == 10*context.order_num:\n context.write_log('触发止盈,全部平仓', stdout=1) #输出关键日志\n if(position.current_qty != 0):\n rv = context.order_target_percent(context.ins, 0, None, order_type=OrderType.MARKET)\n# msg = \"{} 止盈 for {} 最新价={} 下单函数返回={}\".format(str(data.current_dt),context.ins,str(price),str(rv))\n# context.write_log(msg, stdout=1) #输出关键日志\n \n","type":"Literal","bound_global_parameter":null},{"name":"handle_trade","value":"# 交易引擎:成交回报处理函数,每个成交发生时执行一次\ndef bigquant_run(context, data):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"handle_order","value":"# 交易引擎:委托回报处理函数,每个委托变化时执行一次\ndef bigquant_run(context, data):\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":"90000","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":"volume_limit","value":1,"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":"close","type":"Literal","bound_global_parameter":null},{"name":"benchmark","value":"000001.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":"-227"},{"name":"options_data","node_id":"-227"},{"name":"history_ds","node_id":"-227"},{"name":"benchmark_ds","node_id":"-227"}],"output_ports":[{"name":"raw_perf","node_id":"-227"}],"cacheable":false,"seq_num":2,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-216' Position='257,66,200,200'/><node_position Node='-227' Position='185.7496337890625,206,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
[2022-10-21 14:43:37.074889] INFO: moduleinvoker: instruments.v2 开始运行..
[2022-10-21 14:43:37.114406] INFO: moduleinvoker: instruments.v2 运行完成[0.039529s].
[2022-10-21 14:43:37.140218] INFO: moduleinvoker: hfbacktest.v1 开始运行..
[2022-10-21 14:43:37.146781] INFO: hfbacktest: biglearning V1.4.19
[2022-10-21 14:43:37.148746] INFO: hfbacktest: bigtrader v1.9.8 2022-10-10
[2022-10-21 14:43:37.170820] INFO: moduleinvoker: cached.v2 开始运行..
[2022-10-21 14:43:37.182053] INFO: moduleinvoker: 命中缓存
[2022-10-21 14:43:37.183796] INFO: moduleinvoker: cached.v2 运行完成[0.012982s].
[2022-10-21 14:43:37.228349] INFO: moduleinvoker: cached.v2 开始运行..
[2022-10-21 14:43:38.941682] INFO: moduleinvoker: cached.v2 运行完成[1.71334s].
[2022-10-21 14:44:47.265574] INFO: hfbacktest: backtest done, raw_perf_ds:DataSource(31c9cd85db114cf298087af73f33c9b8T)
[2022-10-21 14:45:00.965495] INFO: moduleinvoker: hfbacktest.v1 运行完成[83.825288s].
[2022-10-21 14:45:00.967917] INFO: moduleinvoker: hftrade.v2 运行完成[83.84653s].
- 收益率-2.49%
- 年化收益率-2.48%
- 基准收益率-15.81%
- 阿尔法0.04
- 贝塔0.46
- 夏普比率-0.29
- 胜率0.41
- 盈亏比0.52
- 收益波动率15.16%
- 信息比率0.06
- 最大回撤14.64%
bigcharts-data-start/{"__type":"tabs","__id":"bigchart-6275e8fdcbf5456cbce0e35047e6ea38"}/bigcharts-data-end