[量化学堂-策略开发]浅谈小市值策略

市值
多因字选股
alpha
精选
标签: #<Tag:0x00007fd3288814d8> #<Tag:0x00007fd328881398> #<Tag:0x00007fd328881258> #<Tag:0x00007fd328881118>

(iQuant) #1

前几篇的教程都是关于择时的策略,今天打算写一篇选股的策略——基于市值的选股策略。本文的主要目的是给大家演示一下如何在BigQuant平台上开发出传统量化选股策略,大家会发现,原来通过可视化的方式,策略开发是如此的高效和便捷。

了解Alpha策略和Fama_French三因子模型的人都知道,市值因子是一个长期有效的超额收益来源,对股票收益率有一定的解释作用,小市值的股票更容易带来超额收益。这也比较好理解,因为小市值类股票往往表现活跃,容易引发炒作风潮。此外,还有IPO管制的原因(大量排队企业选择借壳),也有市场风险偏好提升的原因(市场恶性循环越来越偏爱小市值)。

现在,开始正式介绍策略部分吧。为方便小伙伴们理解,我们会介绍更详细和具体。

策略逻辑:市值可以带来超额收益

策略内容:每月月初买入市值最小的30只股票并且成交额满足一定条件的股票,持有至下个月月初再调仓。

资金管理:等权重买入

风险控制:无单只股票仓位上限控制、无止盈止损

策略完整代码见文末,可以直接复制到个人策略研究空间。我们运行完曲线如下:

回测结果比较真实,小市值策略在过去几年确实是这样的表现。2017年以来,中小盘风格转换明显,创业板、中小板走势比较弱,因此该策略也面临较大回撤,但是2018年下半年到2019年上半年,小市值策略表现惊人。

纸上得来终觉浅,绝知此事须躬行。还是请小伙伴自己动手去实现吧:slight_smile: 点击 克隆策略就可以把策略克隆到自己的账户了。

克隆策略

    {"Description":"实验创建于2019/4/20","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-299:instruments","SourceOutputPortId":"-290:data"},{"DestinationInputPortId":"-32:instruments","SourceOutputPortId":"-290:data"},{"DestinationInputPortId":"-299:features","SourceOutputPortId":"-286:data"},{"DestinationInputPortId":"-606:input_ds","SourceOutputPortId":"-299:data"},{"DestinationInputPortId":"-53:input_data","SourceOutputPortId":"-606:data_1"},{"DestinationInputPortId":"-32:options_data","SourceOutputPortId":"-53:data"}],"ModuleNodes":[{"Id":"-290","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2014-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2019-04-19","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":"0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"-290"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-290","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"IsPartOfPartialRun":null,"Comment":"输入证券","CommentCollapsed":true},{"Id":"-286","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"market_cap_float_0\namount_0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-286"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-286","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"IsPartOfPartialRun":null,"Comment":"输入特征","CommentCollapsed":true},{"Id":"-299","ModuleId":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v7","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_start_days","Value":"60","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-299"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-299"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-299","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-606","ModuleId":"BigQuantSpace.sort.sort-v4","ModuleParameters":[{"Name":"sort_by","Value":"market_cap_float_0","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"group_by","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"keep_columns","Value":"--","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"ascending","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_ds","NodeId":"-606"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"sort_by_ds","NodeId":"-606"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-606","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"IsPartOfPartialRun":null,"Comment":"依据某个因子排序","CommentCollapsed":true},{"Id":"-32","ModuleId":"BigQuantSpace.trade.trade-v4","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"handle_data","Value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n \n \n context.extension['index'] += 1\n # 不在换仓日就return,相当于后面的代码只会一个月运行一次,买入的股票会持有1个月\n if context.extension['index'] % context.rebalance_days != 0:\n return \n \n # 当前的日期\n date = data.current_dt.strftime('%Y-%m-%d')\n \n cur_data = context.indicator_data[context.indicator_data['date'] == date]\n # 根据日期获取调仓需要买入的股票的列表\n stock_to_buy = list(cur_data.instrument[:context.stock_num])\n # 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表\n stock_hold_now = [equity.symbol for equity in context.portfolio.positions]\n # 继续持有的股票:调仓时,如果买入的股票已经存在于目前的持仓里,那么应继续持有\n no_need_to_sell = [i for i in stock_hold_now if i in stock_to_buy]\n # 需要卖出的股票\n stock_to_sell = [i for i in stock_hold_now if i not in no_need_to_sell]\n \n # 卖出\n for stock in stock_to_sell:\n # 如果该股票停牌,则没法成交。因此需要用can_trade方法检查下该股票的状态\n # 如果返回真值,则可以正常下单,否则会出错\n # 因为stock是字符串格式,我们用symbol方法将其转化成平台可以接受的形式:Equity格式\n\n if data.can_trade(context.symbol(stock)):\n # order_target_percent是平台的一个下单接口,表明下单使得该股票的权重为0,\n # 即卖出全部股票,可参考回测文档\n context.order_target_percent(context.symbol(stock), 0)\n \n # 如果当天没有买入的股票,就返回\n if len(stock_to_buy) == 0:\n return\n\n # 等权重买入 \n weight = 1 / len(stock_to_buy)\n \n # 买入\n for stock in stock_to_buy:\n if data.can_trade(context.symbol(stock)):\n # 下单使得某只股票的持仓权重达到weight,因为\n # weight大于0,因此是等权重买入\n context.order_target_percent(context.symbol(stock), weight)\n ","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"prepare","Value":"# 回测引擎:准备数据,只执行一次\ndef bigquant_run(context):\n pass\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"initialize","Value":"# 回测引擎:初始化函数,只执行一次\ndef bigquant_run(context):\n # 加载股票指标数据,数据继承自m6模块\n context.indicator_data = context.options['data'].read_df()\n\n # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数\n context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))\n \n # 设置股票数量\n context.stock_num = 30\n \n # 调仓天数,22个交易日大概就是一个月。可以理解为一个月换仓一次\n context.rebalance_days = 22\n \n # 如果策略运行中,需要将数据进行保存,可以借用extension这个对象,类型为dict\n # 比如当前运行的k线的索引,比如个股持仓天数、买入均价\n if 'index' not in context.extension:\n context.extension['index'] = 0\n \n \n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_trading_start","Value":"# 回测引擎:每个单位时间开始前调用一次,即每日开盘前调用一次。\ndef bigquant_run(context, data):\n pass\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"volume_limit","Value":0.025,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"order_price_field_buy","Value":"open","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"order_price_field_sell","Value":"open","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"capital_base","Value":1000000,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"auto_cancel_non_tradable_orders","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"data_frequency","Value":"daily","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"price_type","Value":"后复权","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"product_type","Value":"股票","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"plot_charts","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"backtest_only","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"benchmark","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-32"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"options_data","NodeId":"-32"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"history_ds","NodeId":"-32"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"benchmark_ds","NodeId":"-32"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"trading_calendar","NodeId":"-32"}],"OutputPortsInternal":[{"Name":"raw_perf","NodeId":"-32","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":5,"IsPartOfPartialRun":null,"Comment":"回测","CommentCollapsed":true},{"Id":"-53","ModuleId":"BigQuantSpace.filter.filter-v3","ModuleParameters":[{"Name":"expr","Value":"amount_0 > 10000","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_left_data","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-53"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-53","OutputType":null},{"Name":"left_data","NodeId":"-53","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":6,"IsPartOfPartialRun":null,"Comment":"过滤掉不需要的股票数据","CommentCollapsed":true}],"SerializedClientData":"<?xml version='1.0' encoding='utf-16'?><DataV1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><Meta /><NodePositions><NodePosition Node='-290' Position='-40,17,200,200'/><NodePosition Node='-286' Position='343,15,200,200'/><NodePosition Node='-299' Position='225,137,200,200'/><NodePosition Node='-606' Position='229,224,200,200'/><NodePosition Node='-32' Position='177,399,200,200'/><NodePosition Node='-53' Position='215,304,200,200'/></NodePositions><NodeGroups /></DataV1>"},"IsDraft":true,"ParentExperimentId":null,"WebService":{"IsWebServiceExperiment":false,"Inputs":[],"Outputs":[],"Parameters":[{"Name":"交易日期","Value":"","ParameterDefinition":{"Name":"交易日期","FriendlyName":"交易日期","DefaultValue":"","ParameterType":"String","HasDefaultValue":true,"IsOptional":true,"ParameterRules":[],"HasRules":false,"MarkupType":0,"CredentialDescriptor":null}}],"WebServiceGroupId":null,"SerializedClientData":"<?xml version='1.0' encoding='utf-16'?><DataV1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><Meta /><NodePositions></NodePositions><NodeGroups /></DataV1>"},"DisableNodesUpdate":false,"Category":"user","Tags":[],"IsPartialRun":true}
    In [1]:
    # 本代码由可视化策略环境自动生成 2019年4月20日 17:45
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # 回测引擎:每日数据处理函数,每天执行一次
    def m5_handle_data_bigquant_run(context, data):
        
        
        context.extension['index'] += 1
        # 不在换仓日就return,相当于后面的代码只会一个月运行一次,买入的股票会持有1个月
        if  context.extension['index'] % context.rebalance_days != 0:
            return 
        
        # 当前的日期
        date = data.current_dt.strftime('%Y-%m-%d')
        
        cur_data = context.indicator_data[context.indicator_data['date'] == date]
        # 根据日期获取调仓需要买入的股票的列表
        stock_to_buy = list(cur_data.instrument[:context.stock_num])
        # 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表
        stock_hold_now = [equity.symbol for equity in context.portfolio.positions]
        # 继续持有的股票:调仓时,如果买入的股票已经存在于目前的持仓里,那么应继续持有
        no_need_to_sell = [i for i in stock_hold_now if i in stock_to_buy]
        # 需要卖出的股票
        stock_to_sell = [i for i in stock_hold_now if i not in no_need_to_sell]
      
        # 卖出
        for stock in stock_to_sell:
            # 如果该股票停牌,则没法成交。因此需要用can_trade方法检查下该股票的状态
            # 如果返回真值,则可以正常下单,否则会出错
            # 因为stock是字符串格式,我们用symbol方法将其转化成平台可以接受的形式:Equity格式
    
            if data.can_trade(context.symbol(stock)):
                # order_target_percent是平台的一个下单接口,表明下单使得该股票的权重为0,
                #   即卖出全部股票,可参考回测文档
                context.order_target_percent(context.symbol(stock), 0)
        
        # 如果当天没有买入的股票,就返回
        if len(stock_to_buy) == 0:
            return
    
        # 等权重买入 
        weight =  1 / len(stock_to_buy)
        
        # 买入
        for stock in stock_to_buy:
            if data.can_trade(context.symbol(stock)):
                # 下单使得某只股票的持仓权重达到weight,因为
                # weight大于0,因此是等权重买入
                context.order_target_percent(context.symbol(stock), weight)
     
    # 回测引擎:准备数据,只执行一次
    def m5_prepare_bigquant_run(context):
        pass
    
    # 回测引擎:初始化函数,只执行一次
    def m5_initialize_bigquant_run(context):
        # 加载股票指标数据,数据继承自m6模块
        context.indicator_data = context.options['data'].read_df()
    
        # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数
        context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))
        
        # 设置股票数量
        context.stock_num = 30
        
        # 调仓天数,22个交易日大概就是一个月。可以理解为一个月换仓一次
        context.rebalance_days = 22
        
        # 如果策略运行中,需要将数据进行保存,可以借用extension这个对象,类型为dict
        # 比如当前运行的k线的索引,比如个股持仓天数、买入均价
        if 'index' not in context.extension:
            context.extension['index'] = 0
     
        
    
    # 回测引擎:每个单位时间开始前调用一次,即每日开盘前调用一次。
    def m5_before_trading_start_bigquant_run(context, data):
        pass
    
    
    m1 = M.instruments.v2(
        start_date='2014-01-01',
        end_date='2019-04-19',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m2 = M.input_features.v1(
        features="""market_cap_float_0
    amount_0"""
    )
    
    m3 = M.general_feature_extractor.v7(
        instruments=m1.data,
        features=m2.data,
        start_date='',
        end_date='',
        before_start_days=60
    )
    
    m4 = M.sort.v4(
        input_ds=m3.data,
        sort_by='market_cap_float_0',
        group_by='instrument',
        keep_columns='--',
        ascending=True
    )
    
    m6 = M.filter.v3(
        input_data=m4.data_1,
        expr='amount_0 > 10000',
        output_left_data=False
    )
    
    m5 = M.trade.v4(
        instruments=m1.data,
        options_data=m6.data,
        start_date='',
        end_date='',
        handle_data=m5_handle_data_bigquant_run,
        prepare=m5_prepare_bigquant_run,
        initialize=m5_initialize_bigquant_run,
        before_trading_start=m5_before_trading_start_bigquant_run,
        volume_limit=0.025,
        order_price_field_buy='open',
        order_price_field_sell='open',
        capital_base=1000000,
        auto_cancel_non_tradable_orders=True,
        data_frequency='daily',
        price_type='后复权',
        product_type='股票',
        plot_charts=True,
        backtest_only=False,
        benchmark=''
    )
    
    • 收益率1250.65%
    • 年化收益率66.15%
    • 基准收益率76.85%
    • 阿尔法0.46
    • 贝塔0.73
    • 夏普比率1.57
    • 胜率0.67
    • 盈亏比1.21
    • 收益波动率34.3%
    • 信息比率0.09
    • 最大回撤37.63%
    bigcharts-data-start/{"__type":"tabs","__id":"bigchart-de049823611e4a8698ff3f1faada67bc"}/bigcharts-data-end

    传统小市值策略 VS AI市值策略
    请教:如何选出高市值的标的
    投资组合优化器
    模拟盘没有交易记录呢,这个是每周都会调仓的啊。。。
    为什么我的程序在我的交易”达到条件没有交易
    【策略案例】基于pe_ttm选股因子策略分享
    (jiandanqinxin1990) #2

    我想请问一下,如果在每月一号调仓的时候出现新股上市,也会出现部分很小市值的新股,此时如果进行买入操作,但是又买不进,程序里面应该怎么设置呢,包括停牌的小市值股票?


    (iQuant) #3

    对于停牌的股票,因为成交量为0,因此这类股票会被过滤
    对于新上市的股票,会有一字涨停的情形,这类情形无法买入,是不会成交的,订单会取消


    (hohner12) #4

    请问,将换仓周期设置为一周之后,为什么会出现一周内连续交易的情况


    (iQuant) #5

    应该是代码有问题,建议你将修改的代码分享到社区大家看看。


    (disc) #6

    谢谢分享,抱走研究


    (1899) #7

    你好 请问类似止盈止损、买入卖出条件等能放在AI策略里么?要是可以放的话,是不是应该放在handle_data函数下,还是其他处理?


    (小Q) #8

    可以的。
    策略进场出场、止盈止损、资金管理、风险控制可以自己编写代码。
    AI策略也有handle_data函数,在里面实现就可以。


    #9

    还需要添加一些细节才能使用,调试一段时间后再来评论


    (chenjianjia) #10

    daily_buy_stock = market_cap_data.groupby(‘date’).apply(lambda df:df[(df[‘amount’] > 0)].sort_values(by=‘market_cap’,ascending=False)[:30])

    为什么排序的ascending=False或者=True回测的结果都一样?
    从2017年1月1日至2017年12月31日的回测

    还是就是我想选择市值从小到大第500位开始的30只股票该怎么写代码?谢谢


    (小Q) #11

    你好,很可能你的代码某个地方有问题,建议你分享出来,大家帮你看看~


    (chenjianjia) #13
    import pandas as pd
    # 获取股票代码
    instruments = D.instruments()
    # 确定起始时间
    start_date = '2017-01-01' 
    # 确定结束时间
    end_date = '2017-12-31' 
    # 获取股票总市值数据,返回DataFrame数据格式
    market_cap_data = D.history_data(instruments,start_date,end_date,
                  fields=['market_cap','amount'])
    # 获取每日按小市值排序 (从低到高)的前三十只股票
    daily_buy_stock = market_cap_data.groupby('date').apply(lambda df:df[(df['amount'] > 0)].sort_values(by='market_cap',ascending=True)[:30])
    
    

    (chenjianjia) #14

    1导入了pandas库 import pandas as pd
    2修改了起止时间从2017年1月1日至2017年12月31日
    3排序用了df.sort_values里面的参数,ascending=True是我自己加进去的
    就改了这三个地方,其他和上面原帖的代码一样,可是我发现ascending=True或者ascending=False回测结果都一样啊,有高人指点一下吗?还有我想选择市值从小到大第500位开始的30只股票该怎么写代码?谢谢


    (upndown) #15

    应该是这样吧

    daily_buy_stock = market_cap_data.groupby('date').apply(lambda df:df[(df['amount'] > 0)].sort_values(by='market_cap',ascending=False)[500:530])
    

    (chenjianjia) #16

    这里ascending=True或者False,选前30支股票[:30]或者从第200位开始选30支股票[200:230],甚至直选一只股票[;1]回测的结果都是一样的呀?这是为什么?


    (小Q) #17

    你的策略应该是击中缓存了,你可以将交易模块中增加一个参数——m_deps,如下:

    m=M.trade.v3( 
        instruments=D.instruments(),
        start_date='2013-01-01', # 开始时间 
        end_date='2018-01-31', # 结束时间
        # 必须传入initialize,只在第一天运行
        prepare=prepare, # 数据准备函数
        initialize=initialize, # 初始化函数
        #  必须传入handle_data,每个交易日都会运行
        handle_data=handle_data,
        # 买入以开盘价成交
        order_price_field_buy='open',
        # 卖出也以开盘价成交
        order_price_field_sell='open',
        # 策略本金
        capital_base=1000000,
        # 比较基准:沪深300
        benchmark='000300.INDX',
        m_deps=np.random.randn(),
    )
    
    

    分享策略到社区的方法是:如何分享策略到社区


    (chenjianjia) #18

    甚至吧by=‘market_cap’,换成by=‘amount’,回测的结果也一样


    (chenjianjia) #19

    问题解决了,但prepare函数应该不需要吧,能够简单解释一下击中缓存是什么意思吗?python能一步一步地调试程序吗?


    (iQuant) #20

    如果回测的话,prepare函数确实可以不要,但是如果要模拟实盘,每天会更新daily_buy_stock这个变量,因此需要借助prepare函数,因为这样的话可以把context传进去,可以根据start_date 和end_date 更新变量。

    平台对于相同的参数传入,会击中缓存(hit cache),hit cache的时候日志可以看得出来,你可以稍微修改下传入的参数就能重新运行,不会hit cache。

    之所以我们引入了缓存机制,是因为这样可以节约很多的计算资源!


    (chenjianjia) #21

    我知道了,我之前从量化学堂里克隆的那个版本没有prepare函数,daily_buy_stock是通过initialize函数传给context的,新版本是改在prepare里传给context,如果是这个原因的话可能没有击中缓存