克隆策略

    {"description":"实验创建于2021/10/9","graph":{"edges":[{"to_node_id":"-60:instruments","from_node_id":"-44:data"},{"to_node_id":"-5527:instruments","from_node_id":"-44:data"},{"to_node_id":"-5527:history_ds","from_node_id":"-60:data"}],"nodes":[{"node_id":"-44","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2015-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2021-10-10","type":"Literal","bound_global_parameter":null},{"name":"market","value":"CN_FUND","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"#日经\n513520.HOF\n#德国指数\n513030.HOF\n#纳斯达克\n159941.ZOF\n#黄金\n518880.HOF\n#恒生\n159920.ZOF\n#沪深300\n510300.HOF\n#国债\n511010.HOF","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":0,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"-44"}],"output_ports":[{"name":"data","node_id":"-44"}],"cacheable":true,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"-60","module_id":"BigQuantSpace.use_datasource.use_datasource-v1","parameters":[{"name":"datasource_id","value":"bar1d_CN_FUND","type":"Literal","bound_global_parameter":null},{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-60"},{"name":"features","node_id":"-60"}],"output_ports":[{"name":"data","node_id":"-60"}],"cacheable":true,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-5527","module_id":"BigQuantSpace.trade.trade-v4","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 #context.ranker_prediction = context.options['data'].read_df()\n\n # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数\n context.set_commission(PerOrder(buy_cost=0.00015, sell_cost=0.00015, min_cost=0))\n #国债放大持有仓位倍数\n context.DEBT = 4\n #每标的购买资金\n context.max_cash_per_instrument = context.portfolio.portfolio_value/(len(context.instruments)-1+context.DEBT)\n","type":"Literal","bound_global_parameter":null},{"name":"handle_data","value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n \n today = data.current_dt.strftime('%Y-%m-%d')\n # 获取当前持仓\n positions = {e.symbol: p.amount for e, p in context.portfolio.positions.items()}\n #买入并持有\n #每标的购买资金\n for instrument in context.instruments:\n if instrument not in positions.keys():\n cash = context.max_cash_per_instrument\n if instrument=='511010.HOF':\n cash = context.max_cash_per_instrument * context.DEBT\n context.order_value(context.symbol(instrument), cash)\n \n \n \n \n\n \n ","type":"Literal","bound_global_parameter":null},{"name":"prepare","value":"# 回测引擎:准备数据,只执行一次\ndef bigquant_run(context):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"before_trading_start","value":"# 回测引擎:每个单位时间开始前调用一次,即每日开盘前调用一次。\ndef bigquant_run(context, data):\n pass\n","type":"Literal","bound_global_parameter":null},{"name":"volume_limit","value":0.025,"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":"capital_base","value":1000000,"type":"Literal","bound_global_parameter":null},{"name":"auto_cancel_non_tradable_orders","value":"True","type":"Literal","bound_global_parameter":null},{"name":"data_frequency","value":"daily","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":"plot_charts","value":"True","type":"Literal","bound_global_parameter":null},{"name":"backtest_only","value":"False","type":"Literal","bound_global_parameter":null},{"name":"benchmark","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-5527"},{"name":"options_data","node_id":"-5527"},{"name":"history_ds","node_id":"-5527"},{"name":"benchmark_ds","node_id":"-5527"},{"name":"trading_calendar","node_id":"-5527"}],"output_ports":[{"name":"raw_perf","node_id":"-5527"}],"cacheable":false,"seq_num":4,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-44' Position='-39.946388244628906,86.71751403808594,200,200'/><node_position Node='-60' Position='-34.96495056152344,208.92578125,200,200'/><node_position Node='-5527' Position='-99.11338937282562,331.4907531738281,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [14]:
    # 本代码由可视化策略环境自动生成 2021年11月11日 21:51
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # 回测引擎:初始化函数,只执行一次
    def m4_initialize_bigquant_run(context):
        # 加载预测数据
        #context.ranker_prediction = context.options['data'].read_df()
    
        # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数
        context.set_commission(PerOrder(buy_cost=0.00015, sell_cost=0.00015, min_cost=0))
        #国债放大持有仓位倍数
        context.DEBT = 4
        #每标的购买资金
        context.max_cash_per_instrument = context.portfolio.portfolio_value/(len(context.instruments)-1+context.DEBT)
    
    # 回测引擎:每日数据处理函数,每天执行一次
    def m4_handle_data_bigquant_run(context, data):
        
        today = data.current_dt.strftime('%Y-%m-%d')
        # 获取当前持仓
        positions = {e.symbol: p.amount for e, p in context.portfolio.positions.items()}
        #买入并持有
        #每标的购买资金
        for instrument in context.instruments:
            if instrument not in positions.keys():
                cash = context.max_cash_per_instrument
                if instrument=='511010.HOF':
                    cash = context.max_cash_per_instrument * context.DEBT
                context.order_value(context.symbol(instrument), cash)
                
        
            
        
    
                
        
    # 回测引擎:准备数据,只执行一次
    def m4_prepare_bigquant_run(context):
        pass
    
    # 回测引擎:每个单位时间开始前调用一次,即每日开盘前调用一次。
    def m4_before_trading_start_bigquant_run(context, data):
        pass
    
    
    m1 = M.instruments.v2(
        start_date='2015-01-01',
        end_date='2021-10-10',
        market='CN_FUND',
        instrument_list="""#日经
    513520.HOF
    #德国指数
    513030.HOF
    #纳斯达克
    159941.ZOF
    #黄金
    518880.HOF
    #恒生
    159920.ZOF
    #沪深300
    510300.HOF
    #国债
    511010.HOF""",
        max_count=0
    )
    
    m3 = M.use_datasource.v1(
        instruments=m1.data,
        datasource_id='bar1d_CN_FUND',
        start_date='',
        end_date=''
    )
    
    m4 = M.trade.v4(
        instruments=m1.data,
        history_ds=m3.data,
        start_date='',
        end_date='',
        initialize=m4_initialize_bigquant_run,
        handle_data=m4_handle_data_bigquant_run,
        prepare=m4_prepare_bigquant_run,
        before_trading_start=m4_before_trading_start_bigquant_run,
        volume_limit=0.025,
        order_price_field_buy='open',
        order_price_field_sell='close',
        capital_base=1000000,
        auto_cancel_non_tradable_orders=True,
        data_frequency='daily',
        price_type='后复权',
        product_type='股票',
        plot_charts=True,
        backtest_only=False,
        benchmark=''
    )
    
    • 收益率45.04%
    • 年化收益率5.86%
    • 基准收益率39.51%
    • 阿尔法0.02
    • 贝塔0.21
    • 夏普比率0.42
    • 胜率1.0
    • 盈亏比0.0
    • 收益波动率7.05%
    • 信息比率-0.01
    • 最大回撤12.23%
    bigcharts-data-start/{"__type":"tabs","__id":"bigchart-cb3f23278e2b4595a90676b139761d62"}/bigcharts-data-end