2018年A股全景复盘,散户人均亏损10万

策略分享
数据分析
复盘
2018
标签: #<Tag:0x00007f61ed5ab328> #<Tag:0x00007f61ed5ab1e8> #<Tag:0x00007f61ed5ab080> #<Tag:0x00007f61ed5aaf40>

(ingeno) #1

2018已经过去。2018年,A股创史上第二差年度表现,四大指数全球排名垫底。我们对2018年A股做了一个全景数据复盘。感兴趣朋友可以在下方研究基础上做进一步扩展。

2018年A股全景复盘

  • A股核心指数2018年表现
  • A股最差和最好5个指数表现:表现最好的指数是上证公用,录得 -11.21% 收益
  • A股最差和最好5个行业表现:表现最好的行业是休闲服务,录得 -10.93% 收益
  • 十大牛股 (包含新股、次新):表现最好的中石科技,162% 收益
  • 十大牛股 (去除新股、次新):表现最好的卫宁监控,85.9% 收益
  • 十大熊股:表现最差的是 中弘退(000979),亏损 88.7%,已经退市

完整报告和代码

完整数据见下表。您也可以克隆策略,查看源代码,配置参数即可分析任何时间段数据

克隆策略

    {"Description":"实验创建于2018/12/29","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-266:input_1","SourceOutputPortId":"-64:data"},{"DestinationInputPortId":"-273:input_data","SourceOutputPortId":"-74:data_1"},{"DestinationInputPortId":"-297:input_data","SourceOutputPortId":"-74:data_2"},{"DestinationInputPortId":"-309:input_data","SourceOutputPortId":"-74:data_3"},{"DestinationInputPortId":"-256:data2","SourceOutputPortId":"-233:data"},{"DestinationInputPortId":"-74:input_1","SourceOutputPortId":"-256:data"},{"DestinationInputPortId":"-256:data1","SourceOutputPortId":"-266:data_1"},{"DestinationInputPortId":"-363:data1","SourceOutputPortId":"-328:data_1"},{"DestinationInputPortId":"-328:input_1","SourceOutputPortId":"-337:data"},{"DestinationInputPortId":"-368:input_data","SourceOutputPortId":"-347:data_1"},{"DestinationInputPortId":"-380:input_data","SourceOutputPortId":"-347:data_2"},{"DestinationInputPortId":"-399:input_data","SourceOutputPortId":"-347:data_3"},{"DestinationInputPortId":"-363:data2","SourceOutputPortId":"-356:data"},{"DestinationInputPortId":"-347:input_1","SourceOutputPortId":"-363:data"},{"DestinationInputPortId":"-347:input_2","SourceOutputPortId":"-394:data"}],"ModuleNodes":[{"Id":"-64","ModuleId":"BigQuantSpace.use_datasource.use_datasource-v1","ModuleParameters":[{"Name":"datasource_id","Value":"bar1d_index_CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"2018-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2018-12-28","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-64"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-64"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-64","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"Comment":"指数和行业数据","CommentCollapsed":false},{"Id":"-74","ModuleId":"BigQuantSpace.cached.cached-v3","ModuleParameters":[{"Name":"run","Value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n # https://bigquant.com/docs/#/datasource?id=a%E8%82%A1%E6%8C%87%E6%95%B0%E4%BB%A3%E7%A0%81%E8%A1%A8\n df = input_1.read_df().sort_values('returns')\n\n # 主要指数\n # 沪深300,用000300.HIX\n df1 = df[df['symbol'].isin({'上证综指', '深证成指', '创业板指', '中小板指', '000300.HIX'})]\n data_1 = DataSource.write_df(df1)\n\n # 指数\n # 去掉行业指数\n df2 = df[~df['instrument'].str.startswith('SW')]\n df2 = pd.concat([df2[:5], df2[-5:]])\n data_2 = DataSource.write_df(df2)\n\n # 行业\n # 去掉行业指数\n df3 = df[df['instrument'].str.startswith('SW')]\n df3 = pd.concat([df3[:5], df3[-5:]])\n # 清理行业显示字符串\n df3['symbol'] = df3['symbol'].str[:-5]\n data_3 = DataSource.write_df(df3)\n return Outputs(data_1=data_1, data_2=data_2, data_3=data_3)\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"post_run","Value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"input_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"params","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-74"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-74"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-74"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-74","OutputType":null},{"Name":"data_2","NodeId":"-74","OutputType":null},{"Name":"data_3","NodeId":"-74","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":6,"Comment":"核心指数、表现最好和最差指数、表现最好和最差行业","CommentCollapsed":false},{"Id":"-233","ModuleId":"BigQuantSpace.use_datasource.use_datasource-v1","ModuleParameters":[{"Name":"datasource_id","Value":"basic_info_index_CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"2018-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2018-12-28","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-233"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-233"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-233","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":7,"Comment":"指数名称","CommentCollapsed":false},{"Id":"-256","ModuleId":"BigQuantSpace.join.join-v3","ModuleParameters":[{"Name":"on","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"how","Value":"left","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"sort","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data1","NodeId":"-256"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"-256"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-256","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":10,"Comment":"合并,指数名称","CommentCollapsed":false},{"Id":"-266","ModuleId":"BigQuantSpace.cached.cached-v3","ModuleParameters":[{"Name":"run","Value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n # 示例代码如下。在这里编写您的代码\n df = input_1.read_df()\n returns_s = df.groupby('instrument').apply(lambda x: x['close'].iloc[-1] / x['open'].iloc[0] - 1)\n df = pd.DataFrame({'instrument': returns_s.index, 'returns': returns_s.values})\n data_1 = DataSource.write_df(df)\n return Outputs(data_1=data_1)\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"post_run","Value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"input_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"params","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-266"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-266"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-266"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-266","OutputType":null},{"Name":"data_2","NodeId":"-266","OutputType":null},{"Name":"data_3","NodeId":"-266","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":11,"Comment":"计算年度收益","CommentCollapsed":false},{"Id":"-273","ModuleId":"BigQuantSpace.plot_dataframe.plot_dataframe-v1","ModuleParameters":[{"Name":"title","Value":"A股核心指数表现","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_type","Value":"column","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"x","Value":"symbol","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"y","Value":"returns","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"options","Value":"{\n 'chart': {\n 'height': 400\n }\n}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"candlestick","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_1","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_2","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_3","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_4","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-273"}],"OutputPortsInternal":[],"UsePreviousResults":false,"moduleIdForCode":12,"Comment":"主要指数表现","CommentCollapsed":false},{"Id":"-297","ModuleId":"BigQuantSpace.plot_dataframe.plot_dataframe-v1","ModuleParameters":[{"Name":"title","Value":"A股最差和最好指数表现","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_type","Value":"column","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"x","Value":"symbol","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"y","Value":"returns","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"options","Value":"{\n 'chart': {\n 'height': 400\n }\n}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"candlestick","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_1","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_2","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_3","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_4","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-297"}],"OutputPortsInternal":[],"UsePreviousResults":false,"moduleIdForCode":14,"Comment":"指数表现","CommentCollapsed":false},{"Id":"-309","ModuleId":"BigQuantSpace.plot_dataframe.plot_dataframe-v1","ModuleParameters":[{"Name":"title","Value":"A股最差和最好行业表现","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_type","Value":"column","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"x","Value":"symbol","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"y","Value":"returns","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"options","Value":"{\n 'chart': {\n 'height': 400\n }\n}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"candlestick","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_1","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_2","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_3","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_4","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-309"}],"OutputPortsInternal":[],"UsePreviousResults":false,"moduleIdForCode":15,"Comment":"行业表现","CommentCollapsed":false},{"Id":"-320","ModuleId":"BigQuantSpace.comments.comments-v1","ModuleParameters":[],"InputPortsInternal":[],"OutputPortsInternal":[],"UsePreviousResults":true,"moduleIdForCode":16,"Comment":"指数行业表现","CommentCollapsed":false},{"Id":"-321","ModuleId":"BigQuantSpace.comments.comments-v1","ModuleParameters":[],"InputPortsInternal":[],"OutputPortsInternal":[],"UsePreviousResults":true,"moduleIdForCode":17,"Comment":"个股表现","CommentCollapsed":false},{"Id":"-328","ModuleId":"BigQuantSpace.cached.cached-v3","ModuleParameters":[{"Name":"run","Value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n # 示例代码如下。在这里编写您的代码\n df = input_1.read_df()\n returns_s = df.groupby('instrument').apply(lambda x: x['close'].iloc[-1] / x['open'].iloc[0] - 1)\n df = pd.DataFrame({'instrument': returns_s.index, 'returns': returns_s.values})\n data_1 = DataSource.write_df(df)\n return Outputs(data_1=data_1)\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"post_run","Value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"input_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"params","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-328"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-328"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-328"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-328","OutputType":null},{"Name":"data_2","NodeId":"-328","OutputType":null},{"Name":"data_3","NodeId":"-328","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":18,"Comment":"计算年度收益","CommentCollapsed":false},{"Id":"-337","ModuleId":"BigQuantSpace.use_datasource.use_datasource-v1","ModuleParameters":[{"Name":"datasource_id","Value":"bar1d_CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"2018-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2018-12-28","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-337"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-337"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-337","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":19,"Comment":"指数和行业数据","CommentCollapsed":false},{"Id":"-347","ModuleId":"BigQuantSpace.cached.cached-v3","ModuleParameters":[{"Name":"run","Value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n # https://bigquant.com/docs/#/datasource?id=a%E8%82%A1%E6%8C%87%E6%95%B0%E4%BB%A3%E7%A0%81%E8%A1%A8\n df = input_1.read_df().sort_values('returns')\n df['name'].fillna(df['instrument'], inplace=True)\n\n # 10大牛股\n data_1 = DataSource.write_df(df[-10:])\n\n # 10大牛股,去掉新股\n df_2017 = input_2.read()\n df2 = df[df['instrument'].isin(df_2017['instrument'])]\n df2 = df2[-10:]\n data_2 = DataSource.write_df(df2)\n\n # 10大熊股\n data_3 = DataSource.write_df(df[:10])\n\n return Outputs(data_1=data_1, data_2=data_2, data_3=data_3)\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"post_run","Value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"input_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"params","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-347"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-347"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-347"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-347","OutputType":null},{"Name":"data_2","NodeId":"-347","OutputType":null},{"Name":"data_3","NodeId":"-347","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"Comment":"个股表现","CommentCollapsed":false},{"Id":"-356","ModuleId":"BigQuantSpace.use_datasource.use_datasource-v1","ModuleParameters":[{"Name":"datasource_id","Value":"instruments_CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"2018-12-28","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2018-12-28","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-356"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-356"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-356","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"Comment":"股票名称","CommentCollapsed":false},{"Id":"-363","ModuleId":"BigQuantSpace.join.join-v3","ModuleParameters":[{"Name":"on","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"how","Value":"left","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"sort","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data1","NodeId":"-363"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"-363"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-363","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"Comment":"合并,指数名称","CommentCollapsed":false},{"Id":"-368","ModuleId":"BigQuantSpace.plot_dataframe.plot_dataframe-v1","ModuleParameters":[{"Name":"title","Value":"十大牛股 (包含新股、次新)","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_type","Value":"bar","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"x","Value":"name","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"y","Value":"returns","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"options","Value":"{\n 'chart': {\n 'height': 400\n }\n}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"candlestick","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_1","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_2","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_3","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_4","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-368"}],"OutputPortsInternal":[],"UsePreviousResults":false,"moduleIdForCode":4,"Comment":"十大牛股 (包含新股、次新)","CommentCollapsed":false},{"Id":"-380","ModuleId":"BigQuantSpace.plot_dataframe.plot_dataframe-v1","ModuleParameters":[{"Name":"title","Value":"十大牛股 (去除新股、次新)","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_type","Value":"bar","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"x","Value":"name","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"y","Value":"returns","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"options","Value":"{\n 'chart': {\n 'height': 400\n }\n}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"candlestick","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_1","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_2","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_3","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_4","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-380"}],"OutputPortsInternal":[],"UsePreviousResults":false,"moduleIdForCode":20,"Comment":"十大牛股 (去除新股、次新)","CommentCollapsed":false},{"Id":"-394","ModuleId":"BigQuantSpace.use_datasource.use_datasource-v1","ModuleParameters":[{"Name":"datasource_id","Value":"instruments_CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"2017-12-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2017-12-01","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-394"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-394"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-394","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":21,"Comment":"股票名称","CommentCollapsed":false},{"Id":"-399","ModuleId":"BigQuantSpace.plot_dataframe.plot_dataframe-v1","ModuleParameters":[{"Name":"title","Value":"十大熊股","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_type","Value":"bar","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"x","Value":"name","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"y","Value":"returns","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"options","Value":"{\n 'chart': {\n 'height': 400\n }\n}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"candlestick","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_1","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_2","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_3","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_4","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-399"}],"OutputPortsInternal":[],"UsePreviousResults":false,"moduleIdForCode":22,"Comment":"十大熊股","CommentCollapsed":false}],"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='-64' Position='-81.42967224121094,-126.02815246582031,200,200'/><NodePosition Node='-74' Position='74.42509460449219,184.56802368164062,200,200'/><NodePosition Node='-233' Position='213.3304901123047,-126.29376220703125,200,200'/><NodePosition Node='-256' Position='73.57131958007812,84.88032531738281,200,200'/><NodePosition Node='-266' Position='-82.68632888793945,-24.495709896087646,200,200'/><NodePosition Node='-273' Position='-83.94964981079102,360.8050842285156,200,200'/><NodePosition Node='-297' Position='205.75732421875,360.5393371582031,200,200'/><NodePosition Node='-309' Position='74.791748046875,452.49322509765625,200,200'/><NodePosition Node='-320' Position='72.57829284667969,-220.2766571044922,200,200'/><NodePosition Node='-321' Position='729.9001617431641,-219.27899169921875,200,200'/><NodePosition Node='-328' Position='567.0557823181152,-12.128518342971802,200,200'/><NodePosition Node='-337' Position='565.7860565185547,-123.76724243164062,200,200'/><NodePosition Node='-347' Position='735.5368499755859,210.83128356933594,200,200'/><NodePosition Node='-356' Position='880.7587127685547,-124.03287506103516,200,200'/><NodePosition Node='-363' Position='734.6831359863281,107.353759765625,200,200'/><NodePosition Node='-368' Position='588.7844161987305,361.802734375,200,200'/><NodePosition Node='-380' Position='881.8137741088867,361.2718200683594,200,200'/><NodePosition Node='-394' Position='991.7871551513672,-33.30434860289097,200,200'/><NodePosition Node='-399' Position='739.0996627807617,458.1145935058594,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 [162]:
    # 本代码由可视化策略环境自动生成 2018年12月29日 10:56
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m11_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        df = input_1.read_df()
        returns_s = df.groupby('instrument').apply(lambda x: x['close'].iloc[-1] / x['open'].iloc[0] - 1)
        df = pd.DataFrame({'instrument': returns_s.index, 'returns': returns_s.values})
        data_1 = DataSource.write_df(df)
        return Outputs(data_1=data_1)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m11_post_run_bigquant_run(outputs):
        return outputs
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m6_run_bigquant_run(input_1, input_2, input_3):
        # https://bigquant.com/docs/#/datasource?id=a%E8%82%A1%E6%8C%87%E6%95%B0%E4%BB%A3%E7%A0%81%E8%A1%A8
        df = input_1.read_df().sort_values('returns')
    
        # 主要指数
        # 沪深300,用000300.HIX
        df1 = df[df['symbol'].isin({'上证综指', '深证成指', '创业板指', '中小板指', '000300.HIX'})]
        data_1 = DataSource.write_df(df1)
    
        # 指数
        # 去掉行业指数
        df2 = df[~df['instrument'].str.startswith('SW')]
        df2 = pd.concat([df2[:5], df2[-5:]])
        data_2 = DataSource.write_df(df2)
    
        # 行业
        # 去掉行业指数
        df3 = df[df['instrument'].str.startswith('SW')]
        df3 = pd.concat([df3[:5], df3[-5:]])
        # 清理行业显示字符串
        df3['symbol'] = df3['symbol'].str[:-5]
        data_3 = DataSource.write_df(df3)
        return Outputs(data_1=data_1, data_2=data_2, data_3=data_3)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m6_post_run_bigquant_run(outputs):
        return outputs
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m18_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        df = input_1.read_df()
        returns_s = df.groupby('instrument').apply(lambda x: x['close'].iloc[-1] / x['open'].iloc[0] - 1)
        df = pd.DataFrame({'instrument': returns_s.index, 'returns': returns_s.values})
        data_1 = DataSource.write_df(df)
        return Outputs(data_1=data_1)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m18_post_run_bigquant_run(outputs):
        return outputs
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m1_run_bigquant_run(input_1, input_2, input_3):
        # https://bigquant.com/docs/#/datasource?id=a%E8%82%A1%E6%8C%87%E6%95%B0%E4%BB%A3%E7%A0%81%E8%A1%A8
        df = input_1.read_df().sort_values('returns')
        df['name'].fillna(df['instrument'], inplace=True)
    
        # 10大牛股
        data_1 = DataSource.write_df(df[-10:])
    
        # 10大牛股,去掉新股
        df_2017 = input_2.read()
        df2 = df[df['instrument'].isin(df_2017['instrument'])]
        df2 = df2[-10:]
        data_2 = DataSource.write_df(df2)
    
        # 10大熊股
        data_3 = DataSource.write_df(df[:10])
    
        return Outputs(data_1=data_1, data_2=data_2, data_3=data_3)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m1_post_run_bigquant_run(outputs):
        return outputs
    
    
    m5 = M.use_datasource.v1(
        datasource_id='bar1d_index_CN_STOCK_A',
        start_date='2018-01-01',
        end_date='2018-12-28'
    )
    
    m11 = M.cached.v3(
        input_1=m5.data,
        run=m11_run_bigquant_run,
        post_run=m11_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m7 = M.use_datasource.v1(
        datasource_id='basic_info_index_CN_STOCK_A',
        start_date='2018-01-01',
        end_date='2018-12-28'
    )
    
    m10 = M.join.v3(
        data1=m11.data_1,
        data2=m7.data,
        on='instrument',
        how='left',
        sort=False
    )
    
    m6 = M.cached.v3(
        input_1=m10.data,
        run=m6_run_bigquant_run,
        post_run=m6_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m12 = M.plot_dataframe.v1(
        input_data=m6.data_1,
        title='A股核心指数表现',
        chart_type='column',
        x='symbol',
        y='returns',
        options={
        'chart': {
            'height': 400
        }
    },
        candlestick=False,
        pane_1='',
        pane_2='',
        pane_3='',
        pane_4=''
    )
    
    m14 = M.plot_dataframe.v1(
        input_data=m6.data_2,
        title='A股最差和最好指数表现',
        chart_type='column',
        x='symbol',
        y='returns',
        options={
        'chart': {
            'height': 400
        }
    },
        candlestick=False,
        pane_1='',
        pane_2='',
        pane_3='',
        pane_4=''
    )
    
    m15 = M.plot_dataframe.v1(
        input_data=m6.data_3,
        title='A股最差和最好行业表现',
        chart_type='column',
        x='symbol',
        y='returns',
        options={
        'chart': {
            'height': 400
        }
    },
        candlestick=False,
        pane_1='',
        pane_2='',
        pane_3='',
        pane_4=''
    )
    
    m16 = M.comments.v1(
    
    )
    
    m17 = M.comments.v1(
    
    )
    
    m19 = M.use_datasource.v1(
        datasource_id='bar1d_CN_STOCK_A',
        start_date='2018-01-01',
        end_date='2018-12-28'
    )
    
    m18 = M.cached.v3(
        input_1=m19.data,
        run=m18_run_bigquant_run,
        post_run=m18_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m2 = M.use_datasource.v1(
        datasource_id='instruments_CN_STOCK_A',
        start_date='2018-12-28',
        end_date='2018-12-28'
    )
    
    m3 = M.join.v3(
        data1=m18.data_1,
        data2=m2.data,
        on='instrument',
        how='left',
        sort=False
    )
    
    m21 = M.use_datasource.v1(
        datasource_id='instruments_CN_STOCK_A',
        start_date='2017-12-01',
        end_date='2017-12-01'
    )
    
    m1 = M.cached.v3(
        input_1=m3.data,
        input_2=m21.data,
        run=m1_run_bigquant_run,
        post_run=m1_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m4 = M.plot_dataframe.v1(
        input_data=m1.data_1,
        title='十大牛股 (包含新股、次新)',
        chart_type='bar',
        x='name',
        y='returns',
        options={
        'chart': {
            'height': 400
        }
    },
        candlestick=False,
        pane_1='',
        pane_2='',
        pane_3='',
        pane_4=''
    )
    
    m20 = M.plot_dataframe.v1(
        input_data=m1.data_2,
        title='十大牛股 (去除新股、次新)',
        chart_type='bar',
        x='name',
        y='returns',
        options={
        'chart': {
            'height': 400
        }
    },
        candlestick=False,
        pane_1='',
        pane_2='',
        pane_3='',
        pane_4=''
    )
    
    m22 = M.plot_dataframe.v1(
        input_data=m1.data_3,
        title='十大熊股',
        chart_type='bar',
        x='name',
        y='returns',
        options={
        'chart': {
            'height': 400
        }
    },
        candlestick=False,
        pane_1='',
        pane_2='',
        pane_3='',
        pane_4=''
    )
    
    [2018-12-29 10:56:43.630634] INFO: bigquant: use_datasource.v1 开始运行..
    [2018-12-29 10:56:43.636826] INFO: bigquant: 命中缓存
    [2018-12-29 10:56:43.637980] INFO: bigquant: use_datasource.v1 运行完成[0.00739s].
    [2018-12-29 10:56:43.642038] INFO: bigquant: cached.v3 开始运行..
    [2018-12-29 10:56:43.646343] INFO: bigquant: 命中缓存
    [2018-12-29 10:56:43.647234] INFO: bigquant: cached.v3 运行完成[0.005177s].
    [2018-12-29 10:56:43.649440] INFO: bigquant: use_datasource.v1 开始运行..
    [2018-12-29 10:56:43.653317] INFO: bigquant: 命中缓存
    [2018-12-29 10:56:43.654110] INFO: bigquant: use_datasource.v1 运行完成[0.004693s].
    [2018-12-29 10:56:43.656277] INFO: bigquant: join.v3 开始运行..
    [2018-12-29 10:56:43.661065] INFO: bigquant: 命中缓存
    [2018-12-29 10:56:43.661925] INFO: bigquant: join.v3 运行完成[0.00563s].
    [2018-12-29 10:56:43.666953] INFO: bigquant: cached.v3 开始运行..
    [2018-12-29 10:56:43.677920] INFO: bigquant: 命中缓存
    [2018-12-29 10:56:43.679250] INFO: bigquant: cached.v3 运行完成[0.012289s].
    
    [2018-12-29 10:56:43.750076] INFO: bigquant: comments.v1 开始运行..
    [2018-12-29 10:56:43.752014] INFO: bigquant: 命中缓存
    [2018-12-29 10:56:43.752754] INFO: bigquant: comments.v1 运行完成[0.002686s].
    [2018-12-29 10:56:43.754917] INFO: bigquant: comments.v1 开始运行..
    [2018-12-29 10:56:43.756621] INFO: bigquant: 命中缓存
    [2018-12-29 10:56:43.757371] INFO: bigquant: comments.v1 运行完成[0.002451s].
    [2018-12-29 10:56:43.759111] INFO: bigquant: use_datasource.v1 开始运行..
    [2018-12-29 10:56:43.762765] INFO: bigquant: 命中缓存
    [2018-12-29 10:56:43.763450] INFO: bigquant: use_datasource.v1 运行完成[0.004345s].
    [2018-12-29 10:56:43.766319] INFO: bigquant: cached.v3 开始运行..
    [2018-12-29 10:56:43.769663] INFO: bigquant: 命中缓存
    [2018-12-29 10:56:43.770344] INFO: bigquant: cached.v3 运行完成[0.004027s].
    [2018-12-29 10:56:43.772068] INFO: bigquant: use_datasource.v1 开始运行..
    [2018-12-29 10:56:43.776101] INFO: bigquant: 命中缓存
    [2018-12-29 10:56:43.776977] INFO: bigquant: use_datasource.v1 运行完成[0.004908s].
    [2018-12-29 10:56:43.779191] INFO: bigquant: join.v3 开始运行..
    [2018-12-29 10:56:43.783366] INFO: bigquant: 命中缓存
    [2018-12-29 10:56:43.784210] INFO: bigquant: join.v3 运行完成[0.005017s].
    [2018-12-29 10:56:43.786067] INFO: bigquant: use_datasource.v1 开始运行..
    [2018-12-29 10:56:43.790220] INFO: bigquant: 命中缓存
    [2018-12-29 10:56:43.791002] INFO: bigquant: use_datasource.v1 运行完成[0.004932s].
    [2018-12-29 10:56:43.794437] INFO: bigquant: cached.v3 开始运行..
    [2018-12-29 10:56:43.802170] INFO: bigquant: 命中缓存
    [2018-12-29 10:56:43.803250] INFO: bigquant: cached.v3 运行完成[0.008798s].
    

    相关报告