This commit is contained in:
liaozhaorun
2025-02-15 23:33:34 +08:00
parent 18d0876d86
commit 49fa31ac63
13 changed files with 2028 additions and 2580 deletions

View File

@@ -3,8 +3,8 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-09T14:52:54.170824Z",
"start_time": "2025-02-09T14:52:53.544850Z"
"end_time": "2025-02-11T16:39:38.576665Z",
"start_time": "2025-02-11T16:39:38.019824Z"
}
},
"cell_type": "code",
@@ -12,28 +12,38 @@
"%load_ext autoreload\n",
"%autoreload 2\n",
"\n",
"from utils.utils import read_and_merge_h5_data"
"from utils.utils import read_and_merge_h5_data\n"
],
"id": "79a7758178bafdd3",
"outputs": [],
"execution_count": 1
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"execution_count": 8
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-09T14:53:36.873700Z",
"start_time": "2025-02-09T14:52:54.170824Z"
"end_time": "2025-02-11T16:40:45.842510Z",
"start_time": "2025-02-11T16:39:54.757326Z"
}
},
"cell_type": "code",
"source": [
"\n",
"print('daily data')\n",
"df = read_and_merge_h5_data('../../data/daily_data.h5', key='daily_data',\n",
" columns=['ts_code', 'trade_date', 'open', 'close', 'high', 'low', 'vol'],\n",
" df=None)\n",
"\n",
"print('daily basic')\n",
"df = read_and_merge_h5_data('../../data/daily_basic.h5', key='daily_basic_with_st',\n",
"df = read_and_merge_h5_data('../../data/daily_basic.h5', key='daily_basic',\n",
" columns=['ts_code', 'trade_date', 'turnover_rate', 'pe_ttm', 'circ_mv', 'volume_ratio',\n",
" 'is_st'], df=df)\n",
"\n",
@@ -60,26 +70,26 @@
]
}
],
"execution_count": 2
"execution_count": 10
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-09T14:53:37.426404Z",
"start_time": "2025-02-09T14:53:36.955552Z"
"end_time": "2025-02-11T16:40:45.905077Z",
"start_time": "2025-02-11T16:40:45.848510Z"
}
},
"cell_type": "code",
"source": "origin_columns = df.columns.tolist()",
"id": "c4e9e1d31da6dba6",
"outputs": [],
"execution_count": 3
"execution_count": 11
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-09T14:53:38.164112Z",
"start_time": "2025-02-09T14:53:38.070007Z"
"end_time": "2025-02-11T16:40:46.016229Z",
"start_time": "2025-02-11T16:40:45.938587Z"
}
},
"cell_type": "code",
@@ -221,13 +231,13 @@
],
"id": "a735bc02ceb4d872",
"outputs": [],
"execution_count": 4
"execution_count": 12
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-09T14:53:49.153376Z",
"start_time": "2025-02-09T14:53:38.164112Z"
"end_time": "2025-02-11T16:40:56.805530Z",
"start_time": "2025-02-11T16:40:46.048312Z"
}
},
"cell_type": "code",
@@ -247,8 +257,8 @@
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 8364308 entries, 0 to 8364307\n",
"Data columns (total 83 columns):\n",
"RangeIndex: 8375079 entries, 0 to 8375078\n",
"Data columns (total 87 columns):\n",
" # Column Dtype \n",
"--- ------ ----- \n",
" 0 ts_code object \n",
@@ -258,103 +268,106 @@
" 4 high float64 \n",
" 5 low float64 \n",
" 6 vol float64 \n",
" 7 is_st object \n",
" 8 up_limit float64 \n",
" 9 down_limit float64 \n",
" 10 buy_sm_vol float64 \n",
" 11 sell_sm_vol float64 \n",
" 12 buy_lg_vol float64 \n",
" 13 sell_lg_vol float64 \n",
" 14 buy_elg_vol float64 \n",
" 15 sell_elg_vol float64 \n",
" 16 net_mf_vol float64 \n",
" 17 up float64 \n",
" 18 down float64 \n",
" 19 atr_14 float64 \n",
" 20 atr_6 float64 \n",
" 21 obv float64 \n",
" 22 maobv_6 float64 \n",
" 23 obv-maobv_6 float64 \n",
" 24 rsi_3 float64 \n",
" 25 rsi_6 float64 \n",
" 26 rsi_9 float64 \n",
" 27 return_10 float64 \n",
" 28 return_20 float64 \n",
" 29 avg_close_5 float64 \n",
" 30 std_return_5 float64 \n",
" 31 std_return_15 float64 \n",
" 32 std_return_25 float64 \n",
" 33 std_return_90 float64 \n",
" 34 std_return_90_2 float64 \n",
" 35 std_return_5 / std_return_90 float64 \n",
" 36 std_return_5 / std_return_25 float64 \n",
" 37 std_return_90 - std_return_90_2 float64 \n",
" 38 ema_5 float64 \n",
" 39 ema_13 float64 \n",
" 40 ema_20 float64 \n",
" 41 ema_60 float64 \n",
" 42 act_factor1 float64 \n",
" 43 act_factor2 float64 \n",
" 44 act_factor3 float64 \n",
" 45 act_factor4 float64 \n",
" 46 act_factor5 float64 \n",
" 47 act_factor6 float64 \n",
" 48 rank_act_factor1 float64 \n",
" 49 rank_act_factor2 float64 \n",
" 50 rank_act_factor3 float64 \n",
" 51 active_buy_volume_large float64 \n",
" 52 active_buy_volume_big float64 \n",
" 53 active_buy_volume_small float64 \n",
" 54 buy_lg_vol - sell_lg_vol float64 \n",
" 55 buy_elg_vol - sell_elg_vol float64 \n",
" 56 future_return1 float64 \n",
" 57 future_return2 float64 \n",
" 58 future_return3 float64 \n",
" 59 future_return4 float64 \n",
" 60 future_return5 float64 \n",
" 61 future_return6 float64 \n",
" 62 future_return7 float64 \n",
" 63 future_close1 float64 \n",
" 64 future_close2 float64 \n",
" 65 future_close3 float64 \n",
" 66 future_close4 float64 \n",
" 67 future_close5 float64 \n",
" 68 future_af11 float64 \n",
" 69 future_af12 float64 \n",
" 70 future_af13 float64 \n",
" 71 future_af14 float64 \n",
" 72 future_af15 float64 \n",
" 73 future_af21 float64 \n",
" 74 future_af22 float64 \n",
" 75 future_af23 float64 \n",
" 76 future_af24 float64 \n",
" 77 future_af25 float64 \n",
" 78 future_af31 float64 \n",
" 79 future_af32 float64 \n",
" 80 future_af33 float64 \n",
" 81 future_af34 float64 \n",
" 82 future_af35 float64 \n",
"dtypes: datetime64[ns](1), float64(80), object(2)\n",
"memory usage: 5.2+ GB\n",
" 7 turnover_rate float64 \n",
" 8 pe_ttm float64 \n",
" 9 circ_mv float64 \n",
" 10 volume_ratio float64 \n",
" 11 is_st object \n",
" 12 up_limit float64 \n",
" 13 down_limit float64 \n",
" 14 buy_sm_vol float64 \n",
" 15 sell_sm_vol float64 \n",
" 16 buy_lg_vol float64 \n",
" 17 sell_lg_vol float64 \n",
" 18 buy_elg_vol float64 \n",
" 19 sell_elg_vol float64 \n",
" 20 net_mf_vol float64 \n",
" 21 up float64 \n",
" 22 down float64 \n",
" 23 atr_14 float64 \n",
" 24 atr_6 float64 \n",
" 25 obv float64 \n",
" 26 maobv_6 float64 \n",
" 27 obv-maobv_6 float64 \n",
" 28 rsi_3 float64 \n",
" 29 rsi_6 float64 \n",
" 30 rsi_9 float64 \n",
" 31 return_10 float64 \n",
" 32 return_20 float64 \n",
" 33 avg_close_5 float64 \n",
" 34 std_return_5 float64 \n",
" 35 std_return_15 float64 \n",
" 36 std_return_25 float64 \n",
" 37 std_return_90 float64 \n",
" 38 std_return_90_2 float64 \n",
" 39 std_return_5 / std_return_90 float64 \n",
" 40 std_return_5 / std_return_25 float64 \n",
" 41 std_return_90 - std_return_90_2 float64 \n",
" 42 ema_5 float64 \n",
" 43 ema_13 float64 \n",
" 44 ema_20 float64 \n",
" 45 ema_60 float64 \n",
" 46 act_factor1 float64 \n",
" 47 act_factor2 float64 \n",
" 48 act_factor3 float64 \n",
" 49 act_factor4 float64 \n",
" 50 act_factor5 float64 \n",
" 51 act_factor6 float64 \n",
" 52 rank_act_factor1 float64 \n",
" 53 rank_act_factor2 float64 \n",
" 54 rank_act_factor3 float64 \n",
" 55 active_buy_volume_large float64 \n",
" 56 active_buy_volume_big float64 \n",
" 57 active_buy_volume_small float64 \n",
" 58 buy_lg_vol - sell_lg_vol float64 \n",
" 59 buy_elg_vol - sell_elg_vol float64 \n",
" 60 future_return1 float64 \n",
" 61 future_return2 float64 \n",
" 62 future_return3 float64 \n",
" 63 future_return4 float64 \n",
" 64 future_return5 float64 \n",
" 65 future_return6 float64 \n",
" 66 future_return7 float64 \n",
" 67 future_close1 float64 \n",
" 68 future_close2 float64 \n",
" 69 future_close3 float64 \n",
" 70 future_close4 float64 \n",
" 71 future_close5 float64 \n",
" 72 future_af11 float64 \n",
" 73 future_af12 float64 \n",
" 74 future_af13 float64 \n",
" 75 future_af14 float64 \n",
" 76 future_af15 float64 \n",
" 77 future_af21 float64 \n",
" 78 future_af22 float64 \n",
" 79 future_af23 float64 \n",
" 80 future_af24 float64 \n",
" 81 future_af25 float64 \n",
" 82 future_af31 float64 \n",
" 83 future_af32 float64 \n",
" 84 future_af33 float64 \n",
" 85 future_af34 float64 \n",
" 86 future_af35 float64 \n",
"dtypes: datetime64[ns](1), float64(84), object(2)\n",
"memory usage: 5.4+ GB\n",
"None\n"
]
}
],
"execution_count": 5
"execution_count": 13
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-09T14:55:28.712343Z",
"start_time": "2025-02-09T14:53:49.279168Z"
"end_time": "2025-02-11T16:42:03.707721Z",
"start_time": "2025-02-11T16:40:56.889317Z"
}
},
"cell_type": "code",
"source": [
"def filter_data(df):\n",
" df = df.groupby('trade_date').apply(lambda x: x.nlargest(1000, 'act_factor3'))\n",
" df = df[df['is_st'] == False]\n",
" df = df[df['is_st'] == False]\n",
" df = df[~df['is_st']]\n",
" df = df[~df['ts_code'].str.startswith('30')]\n",
" df = df[~df['ts_code'].str.startswith('68')]\n",
" df = df[~df['ts_code'].str.startswith('8')]\n",
@@ -372,106 +385,110 @@
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 1136157 entries, 0 to 1136156\n",
"Data columns (total 83 columns):\n",
"RangeIndex: 1101560 entries, 0 to 1101559\n",
"Data columns (total 87 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 ts_code 1136157 non-null object \n",
" 1 trade_date 1136157 non-null datetime64[ns]\n",
" 2 open 1136157 non-null float64 \n",
" 3 close 1136157 non-null float64 \n",
" 4 high 1136157 non-null float64 \n",
" 5 low 1136157 non-null float64 \n",
" 6 vol 1136157 non-null float64 \n",
" 7 is_st 1136157 non-null object \n",
" 8 up_limit 1135878 non-null float64 \n",
" 9 down_limit 1135878 non-null float64 \n",
" 10 buy_sm_vol 1135663 non-null float64 \n",
" 11 sell_sm_vol 1135663 non-null float64 \n",
" 12 buy_lg_vol 1135663 non-null float64 \n",
" 13 sell_lg_vol 1135663 non-null float64 \n",
" 14 buy_elg_vol 1135663 non-null float64 \n",
" 15 sell_elg_vol 1135663 non-null float64 \n",
" 16 net_mf_vol 1135663 non-null float64 \n",
" 17 up 1136157 non-null float64 \n",
" 18 down 1136157 non-null float64 \n",
" 19 atr_14 1136157 non-null float64 \n",
" 20 atr_6 1136157 non-null float64 \n",
" 21 obv 1136157 non-null float64 \n",
" 22 maobv_6 1136157 non-null float64 \n",
" 23 obv-maobv_6 1136157 non-null float64 \n",
" 24 rsi_3 1136157 non-null float64 \n",
" 25 rsi_6 1136157 non-null float64 \n",
" 26 rsi_9 1136157 non-null float64 \n",
" 27 return_10 1136157 non-null float64 \n",
" 28 return_20 1136157 non-null float64 \n",
" 29 avg_close_5 1136157 non-null float64 \n",
" 30 std_return_5 1136157 non-null float64 \n",
" 31 std_return_15 1136157 non-null float64 \n",
" 32 std_return_25 1136157 non-null float64 \n",
" 33 std_return_90 1136131 non-null float64 \n",
" 34 std_return_90_2 1136129 non-null float64 \n",
" 35 std_return_5 / std_return_90 1136131 non-null float64 \n",
" 36 std_return_5 / std_return_25 1136157 non-null float64 \n",
" 37 std_return_90 - std_return_90_2 1136129 non-null float64 \n",
" 38 ema_5 1136157 non-null float64 \n",
" 39 ema_13 1136157 non-null float64 \n",
" 40 ema_20 1136157 non-null float64 \n",
" 41 ema_60 1136153 non-null float64 \n",
" 42 act_factor1 1136157 non-null float64 \n",
" 43 act_factor2 1136157 non-null float64 \n",
" 44 act_factor3 1136157 non-null float64 \n",
" 45 act_factor4 1136152 non-null float64 \n",
" 46 act_factor5 1136152 non-null float64 \n",
" 47 act_factor6 1136157 non-null float64 \n",
" 48 rank_act_factor1 1136157 non-null float64 \n",
" 49 rank_act_factor2 1136157 non-null float64 \n",
" 50 rank_act_factor3 1136157 non-null float64 \n",
" 51 active_buy_volume_large 1135659 non-null float64 \n",
" 52 active_buy_volume_big 1135636 non-null float64 \n",
" 53 active_buy_volume_small 1135663 non-null float64 \n",
" 54 buy_lg_vol - sell_lg_vol 1135660 non-null float64 \n",
" 55 buy_elg_vol - sell_elg_vol 1135640 non-null float64 \n",
" 56 future_return1 1136157 non-null float64 \n",
" 57 future_return2 1136157 non-null float64 \n",
" 58 future_return3 1136157 non-null float64 \n",
" 59 future_return4 1136157 non-null float64 \n",
" 60 future_return5 1136157 non-null float64 \n",
" 61 future_return6 1136157 non-null float64 \n",
" 62 future_return7 1136157 non-null float64 \n",
" 63 future_close1 1136157 non-null float64 \n",
" 64 future_close2 1136157 non-null float64 \n",
" 65 future_close3 1136157 non-null float64 \n",
" 66 future_close4 1136157 non-null float64 \n",
" 67 future_close5 1136157 non-null float64 \n",
" 68 future_af11 1136157 non-null float64 \n",
" 69 future_af12 1136157 non-null float64 \n",
" 70 future_af13 1136157 non-null float64 \n",
" 71 future_af14 1136157 non-null float64 \n",
" 72 future_af15 1136157 non-null float64 \n",
" 73 future_af21 1136157 non-null float64 \n",
" 74 future_af22 1136157 non-null float64 \n",
" 75 future_af23 1136157 non-null float64 \n",
" 76 future_af24 1136157 non-null float64 \n",
" 77 future_af25 1136157 non-null float64 \n",
" 78 future_af31 1136157 non-null float64 \n",
" 79 future_af32 1136157 non-null float64 \n",
" 80 future_af33 1136157 non-null float64 \n",
" 81 future_af34 1136157 non-null float64 \n",
" 82 future_af35 1136157 non-null float64 \n",
"dtypes: datetime64[ns](1), float64(80), object(2)\n",
"memory usage: 719.5+ MB\n",
" 0 ts_code 1101560 non-null object \n",
" 1 trade_date 1101560 non-null datetime64[ns]\n",
" 2 open 1101560 non-null float64 \n",
" 3 close 1101560 non-null float64 \n",
" 4 high 1101560 non-null float64 \n",
" 5 low 1101560 non-null float64 \n",
" 6 vol 1101560 non-null float64 \n",
" 7 turnover_rate 1101560 non-null float64 \n",
" 8 pe_ttm 932908 non-null float64 \n",
" 9 circ_mv 1101560 non-null float64 \n",
" 10 volume_ratio 1101096 non-null float64 \n",
" 11 is_st 1101560 non-null object \n",
" 12 up_limit 1101282 non-null float64 \n",
" 13 down_limit 1101282 non-null float64 \n",
" 14 buy_sm_vol 1101069 non-null float64 \n",
" 15 sell_sm_vol 1101069 non-null float64 \n",
" 16 buy_lg_vol 1101069 non-null float64 \n",
" 17 sell_lg_vol 1101069 non-null float64 \n",
" 18 buy_elg_vol 1101069 non-null float64 \n",
" 19 sell_elg_vol 1101069 non-null float64 \n",
" 20 net_mf_vol 1101069 non-null float64 \n",
" 21 up 1101560 non-null float64 \n",
" 22 down 1101560 non-null float64 \n",
" 23 atr_14 1100687 non-null float64 \n",
" 24 atr_6 1100687 non-null float64 \n",
" 25 obv 1101560 non-null float64 \n",
" 26 maobv_6 1101560 non-null float64 \n",
" 27 obv-maobv_6 1101560 non-null float64 \n",
" 28 rsi_3 1100687 non-null float64 \n",
" 29 rsi_6 1100687 non-null float64 \n",
" 30 rsi_9 1100687 non-null float64 \n",
" 31 return_10 1101560 non-null float64 \n",
" 32 return_20 1101560 non-null float64 \n",
" 33 avg_close_5 1101560 non-null float64 \n",
" 34 std_return_5 1101560 non-null float64 \n",
" 35 std_return_15 1101560 non-null float64 \n",
" 36 std_return_25 1101559 non-null float64 \n",
" 37 std_return_90 1101533 non-null float64 \n",
" 38 std_return_90_2 1101531 non-null float64 \n",
" 39 std_return_5 / std_return_90 1101533 non-null float64 \n",
" 40 std_return_5 / std_return_25 1101559 non-null float64 \n",
" 41 std_return_90 - std_return_90_2 1101531 non-null float64 \n",
" 42 ema_5 1100687 non-null float64 \n",
" 43 ema_13 1100687 non-null float64 \n",
" 44 ema_20 1100687 non-null float64 \n",
" 45 ema_60 1100682 non-null float64 \n",
" 46 act_factor1 1100687 non-null float64 \n",
" 47 act_factor2 1100687 non-null float64 \n",
" 48 act_factor3 1100687 non-null float64 \n",
" 49 act_factor4 1100682 non-null float64 \n",
" 50 act_factor5 1100682 non-null float64 \n",
" 51 act_factor6 1100687 non-null float64 \n",
" 52 rank_act_factor1 1100687 non-null float64 \n",
" 53 rank_act_factor2 1100687 non-null float64 \n",
" 54 rank_act_factor3 1100687 non-null float64 \n",
" 55 active_buy_volume_large 1101065 non-null float64 \n",
" 56 active_buy_volume_big 1101042 non-null float64 \n",
" 57 active_buy_volume_small 1101069 non-null float64 \n",
" 58 buy_lg_vol - sell_lg_vol 1101066 non-null float64 \n",
" 59 buy_elg_vol - sell_elg_vol 1101046 non-null float64 \n",
" 60 future_return1 1101560 non-null float64 \n",
" 61 future_return2 1101560 non-null float64 \n",
" 62 future_return3 1101560 non-null float64 \n",
" 63 future_return4 1101560 non-null float64 \n",
" 64 future_return5 1101560 non-null float64 \n",
" 65 future_return6 1101560 non-null float64 \n",
" 66 future_return7 1101560 non-null float64 \n",
" 67 future_close1 1101560 non-null float64 \n",
" 68 future_close2 1101560 non-null float64 \n",
" 69 future_close3 1101560 non-null float64 \n",
" 70 future_close4 1101560 non-null float64 \n",
" 71 future_close5 1101560 non-null float64 \n",
" 72 future_af11 1100687 non-null float64 \n",
" 73 future_af12 1100687 non-null float64 \n",
" 74 future_af13 1100687 non-null float64 \n",
" 75 future_af14 1100687 non-null float64 \n",
" 76 future_af15 1100687 non-null float64 \n",
" 77 future_af21 1100687 non-null float64 \n",
" 78 future_af22 1100687 non-null float64 \n",
" 79 future_af23 1100687 non-null float64 \n",
" 80 future_af24 1100687 non-null float64 \n",
" 81 future_af25 1100687 non-null float64 \n",
" 82 future_af31 1100687 non-null float64 \n",
" 83 future_af32 1100687 non-null float64 \n",
" 84 future_af33 1100687 non-null float64 \n",
" 85 future_af34 1100687 non-null float64 \n",
" 86 future_af35 1100687 non-null float64 \n",
"dtypes: datetime64[ns](1), float64(84), object(2)\n",
"memory usage: 731.2+ MB\n",
"None\n"
]
}
],
"execution_count": 6
"execution_count": 14
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-09T15:00:45.828404Z",
"start_time": "2025-02-09T15:00:45.294830Z"
"end_time": "2025-02-11T16:42:04.317134Z",
"start_time": "2025-02-11T16:42:03.969288Z"
}
},
"cell_type": "code",
@@ -516,17 +533,18 @@
"name": "stdout",
"output_type": "stream",
"text": [
"['up', 'down', 'atr_14', 'atr_6', 'obv', 'maobv_6', 'obv-maobv_6', 'rsi_3', 'rsi_6', 'rsi_9', 'return_10', 'return_20', 'avg_close_5', 'std_return_5', 'std_return_15', 'std_return_25', 'std_return_90', 'std_return_90_2', 'std_return_5 / std_return_90', 'std_return_5 / std_return_25', 'std_return_90 - std_return_90_2', 'ema_5', 'ema_13', 'ema_20', 'ema_60', 'act_factor1', 'act_factor2', 'act_factor3', 'act_factor4', 'act_factor5', 'act_factor6', 'rank_act_factor1', 'rank_act_factor2', 'rank_act_factor3', 'active_buy_volume_large', 'active_buy_volume_big', 'active_buy_volume_small', 'buy_lg_vol - sell_lg_vol', 'buy_elg_vol - sell_elg_vol']\n"
"860933\n",
"240627\n"
]
}
],
"execution_count": 19
"execution_count": 15
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-09T14:56:05.319915Z",
"start_time": "2025-02-09T14:56:03.355725Z"
"end_time": "2025-02-11T16:42:06.417436Z",
"start_time": "2025-02-11T16:42:04.322121Z"
}
},
"cell_type": "code",
@@ -558,26 +576,40 @@
],
"id": "f4f16d63ad18d1bc",
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\liaozhaorun\\AppData\\Local\\Temp\\ipykernel_88940\\2181928612.py:16: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" train_data['label'], test_data['label'] = get_label(train_data), get_label(test_data)\n",
"C:\\Users\\liaozhaorun\\AppData\\Local\\Temp\\ipykernel_88940\\2181928612.py:16: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" train_data['label'], test_data['label'] = get_label(train_data), get_label(test_data)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"875004\n",
"最小日期: 2017-01-03\n",
"最大日期: 2022-12-30\n",
"260581\n",
"最小日期: 2023-01-03\n",
"最大日期: 2025-01-27\n"
"747134\n",
"184095\n"
]
}
],
"execution_count": 13
"execution_count": 16
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-09T14:56:05.480695Z",
"start_time": "2025-02-09T14:56:05.367238Z"
"end_time": "2025-02-11T16:42:08.032246Z",
"start_time": "2025-02-11T16:42:06.481439Z"
}
},
"cell_type": "code",
@@ -771,13 +803,13 @@
],
"id": "8f134d435f71e9e2",
"outputs": [],
"execution_count": 14
"execution_count": 17
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-09T14:56:05.576927Z",
"start_time": "2025-02-09T14:56:05.480695Z"
"end_time": "2025-02-11T16:42:08.126033Z",
"start_time": "2025-02-11T16:42:08.047878Z"
}
},
"cell_type": "code",
@@ -802,13 +834,13 @@
],
"id": "4a4542e1ed6afe7d",
"outputs": [],
"execution_count": 15
"execution_count": 18
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-09T14:57:25.341222Z",
"start_time": "2025-02-09T14:56:05.640256Z"
"end_time": "2025-02-11T16:43:30.267422Z",
"start_time": "2025-02-11T16:42:08.363141Z"
}
},
"cell_type": "code",
@@ -831,22 +863,23 @@
"name": "stdout",
"output_type": "stream",
"text": [
"train data size: 875004\n",
"train data size: 747134\n",
"未发现缓存模型,开始训练新模型。\n",
"Training until validation scores don't improve for 50 rounds\n",
"[500]\ttrain's l2: 0.415226\tvalid's l2: 0.57674\n",
"Early stopping, best iteration is:\n",
"[378]\ttrain's l2: 0.435049\tvalid's l2: 0.589178\n",
"[477]\ttrain's l2: 0.417575\tvalid's l2: 0.576627\n",
"Evaluated only: l2\n"
]
}
],
"execution_count": 16
"execution_count": 19
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-09T14:57:27.394697Z",
"start_time": "2025-02-09T14:57:25.373274Z"
"end_time": "2025-02-11T16:43:32.102494Z",
"start_time": "2025-02-11T16:43:30.315429Z"
}
},
"cell_type": "code",
@@ -856,20 +889,20 @@
],
"id": "5bb96ca8492e74d",
"outputs": [],
"execution_count": 17
"execution_count": 20
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-09T14:57:27.489570Z",
"start_time": "2025-02-09T14:57:27.397368Z"
"end_time": "2025-02-11T16:43:32.197091Z",
"start_time": "2025-02-11T16:43:32.107477Z"
}
},
"cell_type": "code",
"source": "predictions[['trade_date', 'score', 'ts_code']].to_csv('predictions.csv', index=False)",
"id": "5d1522a7538db91b",
"outputs": [],
"execution_count": 18
"execution_count": 21
}
],
"metadata": {