问答交流

模拟交易能收到调仓信息,但是持仓一直没有任何变化

由bq8lrsow创建,最终由small_q 被浏览 49 用户

问题描述:

    新手学习中,目前跟着课程实现了一个小市值策略,想在模拟交易中看看运行效果,这几天发现一直没有任何变化

看日志也没有发现任何错误信息,有些日志信息还看不太懂,比如最近一次执行结果如下:

[2023-11-16 21:07:04.245966] INFO 基础特征抽取: 年份 2023, 特征行数=311576
[2023-11-16 21:07:04.349232] INFO 基础特征抽取: 总行数: 311576
[2023-11-16 21:07:05.491635] INFO derived_feature_extractor: 提取完成 市值=market_cap_0, 0.003s
[2023-11-16 21:07:05.507977] INFO derived_feature_extractor: 提取完成 市盈率ttm=pe_ttm_0, 0.005s
[2023-11-16 21:07:05.516178] INFO derived_feature_extractor: 提取完成 上市时间=list_days_0, 0.002s
[2023-11-16 21:07:05.527516] INFO derived_feature_extractor: 提取完成 换手排名=rank_turn_0, 0.002s
[2023-11-16 21:07:06.529275] INFO derived_feature_extractor: /y_2023, 311576
[2023-11-16 21:07:10.149677] INFO A股股票过滤: 过滤 /y_2023, 181787/0/311576
[2023-11-16 21:07:10.155239] INFO A股股票过滤: 过滤完成, 181787 + 0
do_paper_run lm_1={'version': 'v3', 'algo_id': 175961, 'algo_unique_id': 'bq8lrsow_51edb5a2-8223-11ee-920c-0a4cf61f4cc2', 'algo_name': '小市值策略', 'algo_desc': '', 'first_date': '2023-11-13', 'benchmark_symbol': '000300.HIX', 'price_type': '真实价格', 'product_type': 'equity', 'data_frequency': '1d'}, options=DataSource(73e29737d7524fa298452fcedf10f1dbT)
[2023-11-16 21:07:12.190149] INFO hfpapertrading: init options_data:DataSource(73e29737d7524fa298452fcedf10f1dbT)
[2023-11-16 21:07:12.198991] INFO hfpapertrading: init username:bq8lrsow, algo_id:175961, first_date:2023-11-13,            frequency:1d, adjust_type:none, instruments:['000001.SZA', '000002.SZA', '000004.SZA', '000005.SZA', '000006.SZA', '000007.SZA', '000008.SZA', '000009.SZA', '000010.SZA', '000011.SZA', '000012.SZA', '000014.SZA', '000016.SZA', '000017.SZA', '000019.SZA', '000020.SZA', '000021.SZA', '000023.SZA', '000025.SZA', '000026.SZA', '000027.SZA', '000028.SZA', '000029.SZA', '000030.SZA', '000031.SZA', '000032.SZA', '000034.SZA', '000035.SZA', '000036.SZA', '000037.SZA', '000039.SZA', '000040.SZA']
[2023-11-16 21:07:12.208572] INFO hfpapertrading: init benchmark_symbol=000300.HIX
[2023-11-16 21:07:12.213011] INFO hfpapertrading: biglearning hfpapertrading:V1.3.1
[2023-11-16 21:07:12.220667] INFO hfpapertrading: bigtrader v1.10.5 2023-11-03
[2023-11-16 21:07:12.794267] INFO hfpapertrading: hfpapertrading invoke_micro_service done True
[2023-11-16 21:07:13.012587] INFO hfpapertrading: run_date: 2023-11-16, notebook_id:bq8lrsow_51edb5a2-8223-11ee-920c-0a4cf61f4cc2, algo_name:小市值策略, is_third_match:0
[2023-11-16 21:07:13.279510] INFO hfpapertrading: record_datas last_record=2023-11-15, <EquityAlgoDaily(run_date=2023-11-15, is_sync=0, cash=1000000.0, 
positions='[]', 
transactions='[]',                
orders='[]', 
extension='{"order_price_field_buy": "close", "order_price_field_sell": "open", "is_stock": "True"}', benchmark='{"000300.HIX": 0.007031440734863281, "000300.HIX.CUM": 0.007775425910949707}', portfolio='{"cum_return": 0.0, "annual_return": 0.0, "today_return": 0.0, "pv": 0.0, "max_pv": 1000000.0, "drawdown": 0.0, "first_date": "2023-11-13", "portfolio_value": 1000000.0, "cash": 1000000.0}', risk_indicator='{"alpha": -0.029128671418808594, "beta": 0.0, "volatility": 0.0, "sharpe": 0.0, "ir": -0.6702979518752208}', trading_days='3'
[2023-11-16 21:07:13.287000] INFO hfpapertrading: last_record is_sync cash:1000000.0, last_portfolio:{'cum_return': 0.0, 'annual_return': 0.0, 'today_return': 0.0, 'pv': 0.0, 'max_pv': 1000000.0, 'drawdown': 0.0, 'first_date': '2023-11-13', 'portfolio_value': 1000000.0, 'cash': 1000000.0}
[2023-11-16 21:07:13.301829] INFO hfpapertrading: last_record is_sync extension:{'order_price_field_buy': 'close', 'order_price_field_sell': 'open', 'is_stock': 'True'}
[2023-11-16 21:07:13.309005] INFO hfpapertrading: first_trading_date=2023-11-13, cash=1000000.0
[2023-11-16 21:07:13.315018] INFO hfpapertrading: hfpapertrading init_equity_name_map...
[2023-11-16 21:07:15.747763] INFO hfpapertrading: cached_benchmark_ds=DataSource(e2674dd4d48b40b1bd26d527a15229d6T) by benchmark_kwargs={'start_date': '2023-11-15', 'end_date': '2023-11-16', 'instruments': ['000300.HIX'], 'frequency': '1d', 'product_type': '', 'adjust_type': 'post'}
[2023-11-16 21:07:28.296107] INFO hfpapertrading: cached_daily_ds=DataSource(5f14e31d51c3439b98f756f24f97e6ceT)
[2023-11-16 21:07:37.029229] INFO hfpapertrading: create_history_data done
[2023-11-16 21:07:37.038424] INFO hfpapertrading: hfpapertrading get_adjust_factor_map...
[2023-11-16 21:07:37.044855] INFO hfpapertrading: last_positions=[]
[2023-11-16 21:07:37.091372] INFO hfpapertrading: daily_data=
              turn  adjust_factor  instrument       date       open  \
0         1.311517     113.936211  000001.SZA 2022-11-11  11.130000   
1         2.996342     172.824020  000002.SZA 2022-11-11  14.730001   
2         1.972625       4.063862  000004.SZA 2022-11-11   9.770000   
3         1.144187       9.267603  000005.SZA 2022-11-11   1.810000   
4         1.828831      38.939548  000006.SZA 2022-11-11   3.980000   
...            ...            ...         ...        ...        ...   
1269901   4.638292       1.072223  873665.BJA 2023-11-16   6.090000   
1269902  33.534552       1.000000  873679.BJA 2023-11-16  21.400000   
1269903  29.165093       1.000000  873693.BJA 2023-11-16  43.500000   
1269904   3.005746       1.000000  873726.BJA 2023-11-16  23.290001   
1269905  10.441604       1.079623  873833.BJA 2023-11-16  13.000000   

              volume        low  deal_number      close       high  \
0        254507055.0  11.010000     145178.0  11.430000  11.660000   
1        291165404.0  14.660000     185552.0  15.760000  15.760000   
2          2294725.0   9.380000       2099.0   9.380000   9.870000   
3         12104882.0   1.770000       1635.0   1.790000   1.830000   
4         24689122.0   3.950000      21565.0   4.060000   4.130000   
...              ...        ...          ...        ...        ...   
1269901    1530321.0   5.920000          0.0   5.930000   6.100000   
1269902    4285045.0  19.200001          0.0  19.200001  21.900000   
1269903    3526643.0  38.880001          0.0  39.500000  44.880001   
1269904     349530.0  22.790001          0.0  22.910000  23.549999   
1269905    2767871.0  12.120000          0.0  12.130000  13.000000   

               amount  lower_limit  upper_limit  st_status suspended  \
0        2.878557e+09         9.78        11.96        0.0     False   
1        4.449224e+09        12.90        15.76        0.0     False   
2        2.219022e+07         9.13        10.09        1.0     False   
3        2.173714e+07         1.72         1.90        1.0     False   
4        9.965954e+07         3.51         4.29        0.0     False   
...               ...          ...          ...        ...       ...   
1269901  9.180839e+06         4.30         7.96        0.0     False   
1269902  8.609956e+07        15.25        28.31        0.0     False   
1269903  1.501593e+08        32.25        59.89        0.0     False   
1269904  8.056765e+06        16.29        30.23        0.0     False   
1269905  3.445636e+07         9.03        16.75        0.0     False   

         price_limit_status  name delist_date  list_date  
0                       2.0  平安银行         NaT 1991-04-03  
1                       3.0   万科A         NaT 1991-01-29  
2                       2.0  ST国华         NaT 1990-12-01  
3                       2.0  ST星源         NaT 1990-12-10  
4                       2.0  深振业A         NaT 1992-04-27  
...                     ...   ...         ...        ...  
1269901                 2.0  科强股份         NaT 2023-09-26  
1269902                 2.0  前进科技         NaT 2023-11-10  
1269903                 2.0   阿为特         NaT 2023-10-27  
1269904                 2.0  卓兆点胶         NaT 2023-10-19  
1269905                 2.0  美心翼申         NaT 2023-11-08  

[1269906 rows x 19 columns]
2023-11-16 21:07:37.787222 init history datas... 
2023-11-16 21:07:37.797514 init history datas done. 
2023-11-16 21:07:37.991317 run_backtest() capital_base:1000000.0, frequency:1d, product_type:equity, date:2023-11-16 ~ 2023-11-16 
2023-11-16 21:07:38.004945 run_backtest() running... 
2023-11-16 21:07:38.053145 initial contracts len=0 
2023-11-16 21:07:38.062927 backtest inited. 
[2023-11-16 21:07:38.076595] INFO hfpapertrading: c_initialize() first_trading_date:2023-11-13, trading_day_index:3
[2023-11-16 21:07:38.533376] INFO hfpapertrading: c_initialize() positions len:0,value:0.0,margin:0.0
[2023-11-16 21:07:38.538235] INFO hfpapertrading: c_initialize() orders len:0, orders_date=2023-11-15
2023-11-16 21:07:38.543078 backtest transforming 1d, bars=1... 
2023-11-16 21:07:38.551551 transform start_trading_day=2023-11-16 00:00:00, simulation period=2023-11-16 ~ 2023-11-16 
2023-11-16 21:07:38.560263 transform before_start_days=0 
2023-11-16 21:07:38.570353 transform replay_func=<cyfunction BacktestEngine.transform.<locals>.replay_bars_dt at 0x7f752187d110> 
2023-11-16 21:07:39.052184 backtest run end! 
2023-11-16 21:07:39.080980 run_backtest() finished! time cost 1.068s! 
[2023-11-16 21:07:40.181042] INFO hfpapertrading: raw_perf_ds=DataSource(0d8f7ff0430841889010f7e17c36bb77T)
[2023-11-16 21:07:40.197372] INFO hfpapertrading: get last row of algo result_1:
            algorithm_period_return  benchmark_period_return  capital_used  \
2023-11-16                      0.0                      0.0             0   

            ending_cash  ending_value  long_value  longs_count  
2023-11-16    1000000.0             0           0            0  
[2023-11-16 21:07:40.217721] INFO hfpapertrading: get last row of algo result_2:
            pnl  portfolio_value  returns  short_value  shorts_count  \
2023-11-16  0.0        1000000.0      0.0          0.0             0   

            starting_cash  starting_value  trading_days  
2023-11-16      1000000.0             0.0             1  
[2023-11-16 21:07:40.225866] INFO hfpaper_helper: new_orders len=20
new_orders_df=
 Empty DataFrame
Columns: [account_id, acct_type, id, order_time, dt, created, symbol, amount, filled, price, name, direction, offset_display, offset, offset_flag, price_field, order_status, status, limit, multiplier, instrument, close, adjust_factor]
Index: []

[0 rows x 23 columns]
[2023-11-16 21:07:41.758812] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '002890.SZA', 'amount': 1700, 'filled': 0, 'price': 14.52, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.761809] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '002836.SZA', 'amount': 2900, 'filled': 0, 'price': 8.3701, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.764802] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '600883.SHA', 'amount': 3000, 'filled': 0, 'price': 8.23, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.767523] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '603499.SHA', 'amount': 2500, 'filled': 0, 'price': 9.7101, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.770380] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '600857.SHA', 'amount': 2700, 'filled': 0, 'price': 9.2201, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.774500] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '603637.SHA', 'amount': 2800, 'filled': 0, 'price': 8.6501, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.778838] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '600232.SHA', 'amount': 4200, 'filled': 0, 'price': 5.8401, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.783463] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '603955.SHA', 'amount': 1500, 'filled': 0, 'price': 15.7201, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.787730] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '603657.SHA', 'amount': 1600, 'filled': 0, 'price': 15.5901, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.833156] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '603810.SHA', 'amount': 1800, 'filled': 0, 'price': 13.3301, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.841918] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '000605.SZA', 'amount': 4000, 'filled': 0, 'price': 6.16, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.846969] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '603506.SHA', 'amount': 2100, 'filled': 0, 'price': 11.82, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.852666] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '603696.SHA', 'amount': 2500, 'filled': 0, 'price': 9.77, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.857812] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '600356.SHA', 'amount': 3200, 'filled': 0, 'price': 7.81, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.863903] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '002789.SZA', 'amount': 1600, 'filled': 0, 'price': 14.76, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.871353] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '600241.SHA', 'amount': 3100, 'filled': 0, 'price': 8.04, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.876117] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '600097.SHA', 'amount': 2400, 'filled': 0, 'price': 10.03, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.881704] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '603182.SHA', 'amount': 1600, 'filled': 0, 'price': 14.7101, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.888960] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '603829.SHA', 'amount': 1600, 'filled': 0, 'price': 15.2001, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.895098] INFO hfpaper_helper: new_order={'account_id': 'bkt000', 'acct_type': '0', 'id': '', 'order_time': '15:00:00', 'dt': datetime.datetime(2023, 11, 17, 15, 0), 'created': datetime.datetime(2023, 11, 16, 15, 0), 'symbol': '600287.SHA', 'amount': 4400, 'filled': 0, 'price': 5.56, 'name': '', 'direction': '1', 'offset_display': 'OPEN', 'offset': '0', 'offset_flag': '0', 'price_field': None, 'order_status': NOTTRADED(0), 'status': 'pending', 'limit': None, 'multiplier': 1}
[2023-11-16 21:07:41.900769] INFO hfpaper_helper: get_orders new_orders 20:
json_orders:

[2023-11-16 21:07:41.945448] INFO hfpaper_helper: get_last_sale_date_dict: {'002890.SZA': '2023-11-17 15:00:00', '002836.SZA': '2023-11-17 15:00:00', '600883.SHA': '2023-11-17 15:00:00', '603499.SHA': '2023-11-17 15:00:00', '600857.SHA': '2023-11-17 15:00:00', '603637.SHA': '2023-11-17 15:00:00', '600232.SHA': '2023-11-17 15:00:00', '603955.SHA': '2023-11-17 15:00:00', '603657.SHA': '2023-11-17 15:00:00', '603810.SHA': '2023-11-17 15:00:00', '000605.SZA': '2023-11-17 15:00:00', '603506.SHA': '2023-11-17 15:00:00', '603696.SHA': '2023-11-17 15:00:00', '600356.SHA': '2023-11-17 15:00:00', '002789.SZA': '2023-11-17 15:00:00', '600241.SHA': '2023-11-17 15:00:00', '600097.SHA': '2023-11-17 15:00:00', '603182.SHA': '2023-11-17 15:00:00', '603829.SHA': '2023-11-17 15:00:00', '600287.SHA': '2023-11-17 15:00:00'}
[2023-11-16 21:07:42.486446] INFO hfpaper_helper: get_positions_stocks position_value:0.0 new_positions:
 
json_positions:

[2023-11-16 21:07:42.494824] INFO hfpaper_helper: get_portfolio last_pv:1000000.0, current_pv:1000000.0, json_portfolio:{'cum_return': 0.0, 'annual_return': 0.0, 'today_return': 0.0, 'pv': 0.0, 'max_pv': 1000000.0, 'drawdown': 0.0, 'first_date': '2023-11-13', 'portfolio_value': 1000000.0, 'cash': 1000000.0}
[2023-11-16 21:07:42.498794] INFO hfpaper_helper: get_transactions transaction num 0
[2023-11-16 21:07:42.504360] INFO hfpaper_helper: get_transactions total_buy:0.0, total_sell:0.0, json_transaction:

reading benchmark data... 000300.HIX 2023-11-13 2023-11-16 00:00:00+00:00
   instrument        close       date
0  000300.HIX  3579.414062 2023-11-13
1  000300.HIX  3582.058350 2023-11-14
2  000300.HIX  3607.245361 2023-11-15
3  000300.HIX  3572.364014 2023-11-16
[2023-11-16 21:07:42.610844] INFO hfpapertrading: json_cum_benchmark={"000300.HIX": -0.009669780731201172, "000300.HIX.CUM": -0.001969635486602783}
[2023-11-16 21:07:42.621944] INFO hfpaper_helper: get_risk_indicators json_risk_indicator:{'alpha': -0.029128671418808594, 'beta': 0.0, 'volatility': 0.0, 'sharpe': 0.0, 'ir': 0.06888412238829711}
[2023-11-16 21:07:42.627931] INFO hfpapertrading: result json_extension:{"order_price_field_buy": "close", "order_price_field_sell": "open", "is_stock": "True"}
processing to update_database...
[2023-11-16 21:07:42.639662] INFO hfpapertrading: call add_new_daily_record for portfolio_value=1000000.0, position_value=0.0
[2023-11-16 21:07:42.879861] INFO hfpapertrading: invoke add_new_daily_record(bq8lrsow,175961,2023-11-16,json_portfolio={"cum_return": 0.0, "annual_return": 0.0, "today_return": 0.0, "pv": 0.0, "max_pv": 1000000.0, "drawdown": 0.0, "first_date": "2023-11-13", "portfolio_value": 1000000.0, "cash": 1000000.0},json_cum_benchmark={"000300.HIX": -0.009669780731201172, "000300.HIX.CUM": -0.001969635486602783}) done rv=None
cum_return_plot: 4, before_shared_cum_return_plot: 0,                    after_shared_cum_return_plot: 0, benchmark_cum_return_plot: 4, hold_percent_plot: 4
[2023-11-16 21:07:43.087059] INFO hfpapertrading: invoke update_equity_algo(bq8lrsow,175961,2023-11-16,cum_return=0.0,today_return=0.0) done rv=None
[2023-11-16 21:07:43.093068] INFO hfpapertrading: hfpapertrading result, new_cash 1000000.0

我的代码如下(手动添加了部分打印信息):

# 本代码由可视化策略环境自动生成 2023年11月16日 21:32
# 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
 
# 显式导入 BigQuant 相关 SDK 模块
from bigdatasource.api import DataSource
from bigdata.api.datareader import D
from biglearning.api import M
from biglearning.api import tools as T
from biglearning.module2.common.data import Outputs
 
import pandas as pd
import numpy as np
import math
import warnings
import datetime
 
from zipline.finance.commission import PerOrder
from zipline.api import get_open_orders
from zipline.api import symbol
 
from bigtrader.sdk import *
from bigtrader.utils.my_collections import NumPyDeque
from bigtrader.constant import OrderType
from bigtrader.constant import Direction

# 交易引擎:初始化函数,只执行一次
def m7_initialize_bigquant_run(context):
    # 加载预测数据
    context.ranker_prediction = context.options['data'].read_df()
    context.ranker_prediction.set_index('date',inplace=True)
    

# 交易引擎:每个单位时间开盘前调用一次。
def m7_before_trading_start_bigquant_run(context, data):
    # 盘前处理,订阅行情等
    pass

# 交易引擎:tick数据处理函数,每个tick执行一次
def m7_handle_tick_bigquant_run(context, tick):
    pass

# 交易引擎:bar数据处理函数,每个时间单位执行一次
def m7_handle_data_bigquant_run(context, data):
    remainder = context.trading_day_index % 5
    
    if remainder != 0:
        return
    
    import datetime
    
    # 初始化
    buy_list = []  #买入列表
    sell_list = [] #卖出列表
    
    # 数据准备
    today = data.current_dt.strftime('%Y-%m-%d')  # 读取当天数据
    time = data.current_dt
    
    account_pos = context.get_account_positions()
    holding_list = list({key: value for key, value in account_pos.items() if value.avail_qty > 0}.keys())
    holding_nums = len(holding_list)
    
    # 读取当日数据
    try:
        today_data = context.ranker_prediction.loc[today,:]
        today_data.reset_index(inplace=True)
    except:
        return
    
    # 策略
    today_data = today_data[today_data['上市时间'] >= 365]
    today_data = today_data[today_data['市盈率ttm'] >= 0.5]
    today_data = today_data[today_data['换手排名'] <= 0.3]
    today_data.sort_values(by='市值',ascending=True,inplace=True) #市值排序ß
    
    # 构建目标列表
    target_list = today_data.instrument.to_list()[:20]
    
    # 构建卖出列表
    for ins in holding_list:
        if ins not in target_list:
            sell_list.append(ins)
    
    # 构建买入列表
    for ins in target_list:
        if ins not in holding_list:
            buy_list.append(ins)
    
    print(f'筛选股票数: {len(buy_list)}  买入列表:  {buy_list}')
    print(f'卖出列表: {sell_list}')
    # 先卖
    for ins in sell_list:
        context.order_target(ins,0)
    
    # 等权买
    for ins in buy_list:
        context.order_target_percent(ins,0.025)
    
    
    
    
    
    
        
# 交易引擎:成交回报处理函数,每个成交发生时执行一次
def m7_handle_trade_bigquant_run(context, trade):
    pass

# 交易引擎:委托回报处理函数,每个委托变化时执行一次
def m7_handle_order_bigquant_run(context, order):
    pass

# 交易引擎:盘后处理函数,每日盘后执行一次
def m7_after_trading_bigquant_run(context, data):
    pass


m1 = M.instruments.v2(
    start_date=T.live_run_param('trading_date', '2023-11-16'),
    end_date=T.live_run_param('trading_date', '2023-11-16'),
    market='CN_STOCK_A',
    instrument_list='',
    max_count=0
)

m2 = M.input_features.v1(
    features="""市值=market_cap_0
市盈率ttm=pe_ttm_0
上市时间=list_days_0
换手排名=rank_turn_0
"""
)

m3 = M.general_feature_extractor.v7(
    instruments=m1.data,
    features=m2.data,
    start_date='',
    end_date='',
    before_start_days=90
)

m4 = M.derived_feature_extractor.v3(
    input_data=m3.data,
    features=m2.data,
    date_col='date',
    instrument_col='instrument',
    drop_na=True,
    remove_extra_columns=True,
    user_functions={}
)

m6 = M.chinaa_stock_filter.v1(
    input_data=m4.data,
    index_constituent_cond=['全部'],
    board_cond=['上证主板', '深证主板'],
    industry_cond=['全部'],
    st_cond=['正常'],
    delist_cond=['非退市'],
    output_left_data=False
)

m7 = M.hftrade.v2(
    instruments=m1.data,
    options_data=m6.data,
    start_date='',
    end_date='',
    initialize=m7_initialize_bigquant_run,
    before_trading_start=m7_before_trading_start_bigquant_run,
    handle_tick=m7_handle_tick_bigquant_run,
    handle_data=m7_handle_data_bigquant_run,
    handle_trade=m7_handle_trade_bigquant_run,
    handle_order=m7_handle_order_bigquant_run,
    after_trading=m7_after_trading_bigquant_run,
    capital_base=1000000,
    frequency='daily',
    price_type='真实价格',
    product_type='股票',
    before_start_days='0',
    volume_limit=1,
    order_price_field_buy='close',
    order_price_field_sell='open',
    benchmark='000300.HIX',
    plot_charts=True,
    disable_cache=False,
    replay_bdb=False,
    show_debug_info=False,
    backtest_only=False
)

我自己手动执行了一次,输出如下,看到筛选出了股票,但是没有实际的买入操作,大佬们帮忙看看啦

标签

模拟交易小市值策略持仓调仓交易
评论
  • 确实有点诡异,收到问题 我们看看
  • 应该是我这里写的问题,才发现
{link}