多线程rank6.0,赚钱,回撤略微减小
This commit is contained in:
@@ -2,31 +2,58 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "500802dc-7a20-48b7-a470-a4bae3ec534b",
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-30T16:42:39.056767Z",
|
||||
"start_time": "2025-03-30T16:42:37.817887Z"
|
||||
"end_time": "2025-04-06T15:34:34.020485Z",
|
||||
"start_time": "2025-04-06T15:34:33.497731Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import tushare as ts\n",
|
||||
"\n",
|
||||
"ts.set_token('3a0741c702ee7e5e5f2bf1f0846bafaafe4e320833240b2a7e4a685f')\n",
|
||||
"pro = ts.pro_api()"
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": 1
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "5a84bc9da6d54868",
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-30T16:42:59.784780Z",
|
||||
"start_time": "2025-03-30T16:42:39.056767Z"
|
||||
"end_time": "2025-04-06T15:34:46.227924Z",
|
||||
"start_time": "2025-04-06T15:34:34.042810Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" ts_code trade_date\n",
|
||||
"4717 600285.SH 20250403\n",
|
||||
"4718 600287.SH 20250403\n",
|
||||
"4719 600288.SH 20250403\n",
|
||||
"4708 600273.SH 20250403\n",
|
||||
"5309 601121.SH 20250403\n",
|
||||
"<class 'pandas.core.frame.DataFrame'>\n",
|
||||
"Index: 10301468 entries, 0 to 28272\n",
|
||||
"Data columns (total 2 columns):\n",
|
||||
" # Column Dtype \n",
|
||||
"--- ------ ----- \n",
|
||||
" 0 ts_code object\n",
|
||||
" 1 trade_date object\n",
|
||||
"dtypes: object(2)\n",
|
||||
"memory usage: 235.8+ MB\n",
|
||||
"None\n",
|
||||
"20250403\n",
|
||||
"20250407\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"import time\n",
|
||||
@@ -46,45 +73,37 @@
|
||||
"trade_dates = trade_cal[trade_cal['cal_date'] > max_date]['cal_date'].tolist()\n",
|
||||
"start_date = min(trade_dates)\n",
|
||||
"print(start_date)"
|
||||
],
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "bb3191de-27a2-4c89-a3b5-32a0d7b9496f",
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-04-06T15:34:48.652346Z",
|
||||
"start_time": "2025-04-06T15:34:46.236695Z"
|
||||
},
|
||||
"scrolled": true
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" ts_code trade_date\n",
|
||||
"4705 600289.SH 20250321\n",
|
||||
"4706 600292.SH 20250321\n",
|
||||
"4707 600293.SH 20250321\n",
|
||||
"4696 600279.SH 20250321\n",
|
||||
"7051 920116.BJ 20250321\n",
|
||||
"<class 'pandas.core.frame.DataFrame'>\n",
|
||||
"Index: 10237887 entries, 0 to 35266\n",
|
||||
"Data columns (total 2 columns):\n",
|
||||
" # Column Dtype \n",
|
||||
"--- ------ ----- \n",
|
||||
" 0 ts_code object\n",
|
||||
" 1 trade_date object\n",
|
||||
"dtypes: object(2)\n",
|
||||
"memory usage: 234.3+ MB\n",
|
||||
"None\n",
|
||||
"20250321\n",
|
||||
"20250324\n"
|
||||
"任务 20250417 完成\n",
|
||||
"任务 20250418 完成\n",
|
||||
"任务 20250416 完成\n",
|
||||
"任务 20250415 完成\n",
|
||||
"任务 20250414 完成\n",
|
||||
"任务 20250411 完成\n",
|
||||
"任务 20250410 完成\n",
|
||||
"任务 20250409 完成\n",
|
||||
"任务 20250408 完成\n",
|
||||
"任务 20250407 完成\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": 2
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"id": "bb3191de-27a2-4c89-a3b5-32a0d7b9496f",
|
||||
"metadata": {
|
||||
"scrolled": true,
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-30T16:43:03.372001Z",
|
||||
"start_time": "2025-03-30T16:43:00.012140Z"
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"from concurrent.futures import ThreadPoolExecutor, as_completed\n",
|
||||
"\n",
|
||||
@@ -115,143 +134,69 @@
|
||||
" except Exception as e:\n",
|
||||
" print(f\"获取 {trade_date} 数据时出错: {e}\")\n",
|
||||
"\n"
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"任务 20250418 完成\n",
|
||||
"任务 20250417 完成\n",
|
||||
"任务 20250416 完成\n",
|
||||
"任务 20250415 完成\n",
|
||||
"任务 20250411 完成\n",
|
||||
"任务 20250414 完成\n",
|
||||
"任务 20250409 完成\n",
|
||||
"任务 20250410 完成\n",
|
||||
"任务 20250408 完成\n",
|
||||
"任务 20250407 完成\n",
|
||||
"任务 20250403 完成\n",
|
||||
"任务 20250402 完成\n",
|
||||
"任务 20250401 完成\n",
|
||||
"任务 20250331 完成\n",
|
||||
"任务 20250327 完成\n",
|
||||
"任务 20250328 完成\n",
|
||||
"任务 20250326 完成\n",
|
||||
"任务 20250325 完成\n",
|
||||
"任务 20250324 完成\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": 3
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "96a81aa5890ea3c3",
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-30T16:43:03.397757Z",
|
||||
"start_time": "2025-03-30T16:43:03.384786Z"
|
||||
"end_time": "2025-04-06T15:34:48.680504Z",
|
||||
"start_time": "2025-04-06T15:34:48.665530Z"
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"print(all_daily_data)\n",
|
||||
"# 将所有数据合并为一个 DataFrame\n",
|
||||
"all_daily_data_df = pd.concat(all_daily_data, ignore_index=True)"
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[ trade_date ts_code up_limit down_limit\n",
|
||||
"0 20250327 000001.SZ 12.52 10.24\n",
|
||||
"1 20250327 000002.SZ 7.92 6.48\n",
|
||||
"2 20250327 000004.SZ 11.40 9.32\n",
|
||||
"3 20250327 000006.SZ 7.44 6.08\n",
|
||||
"4 20250327 000007.SZ 7.00 5.72\n",
|
||||
"0 20250408 000001.SZ 11.77 9.63\n",
|
||||
"1 20250408 000002.SZ 7.26 5.94\n",
|
||||
"2 20250408 000004.SZ 9.72 7.96\n",
|
||||
"3 20250408 000006.SZ 6.90 5.64\n",
|
||||
"4 20250408 000007.SZ 6.14 5.02\n",
|
||||
"... ... ... ... ...\n",
|
||||
"7059 20250327 920108.BJ 33.56 18.08\n",
|
||||
"7060 20250327 920111.BJ 40.57 21.85\n",
|
||||
"7061 20250327 920116.BJ 126.29 68.01\n",
|
||||
"7062 20250327 920118.BJ 44.14 23.78\n",
|
||||
"7063 20250327 920128.BJ 47.35 25.51\n",
|
||||
"7072 20250408 920108.BJ 25.33 13.65\n",
|
||||
"7073 20250408 920111.BJ 29.38 15.82\n",
|
||||
"7074 20250408 920116.BJ 96.40 51.92\n",
|
||||
"7075 20250408 920118.BJ 30.16 16.24\n",
|
||||
"7076 20250408 920128.BJ 34.15 18.39\n",
|
||||
"\n",
|
||||
"[7064 rows x 4 columns], trade_date ts_code up_limit down_limit\n",
|
||||
"0 20250328 000001.SZ 12.53 10.25\n",
|
||||
"1 20250328 000002.SZ 7.89 6.45\n",
|
||||
"2 20250328 000004.SZ 11.19 9.15\n",
|
||||
"3 20250328 000006.SZ 8.18 6.70\n",
|
||||
"4 20250328 000007.SZ 6.99 5.72\n",
|
||||
"[7077 rows x 4 columns], trade_date ts_code up_limit down_limit\n",
|
||||
"0 20250407 000001.SZ 12.47 10.21\n",
|
||||
"1 20250407 000002.SZ 7.85 6.43\n",
|
||||
"2 20250407 000004.SZ 10.80 8.84\n",
|
||||
"3 20250407 000006.SZ 7.67 6.27\n",
|
||||
"4 20250407 000007.SZ 6.82 5.58\n",
|
||||
"... ... ... ... ...\n",
|
||||
"7060 20250328 920108.BJ 31.03 16.71\n",
|
||||
"7061 20250328 920111.BJ 39.65 21.35\n",
|
||||
"7062 20250328 920116.BJ 115.67 62.29\n",
|
||||
"7063 20250328 920118.BJ 41.00 22.08\n",
|
||||
"7064 20250328 920128.BJ 44.83 24.15\n",
|
||||
"7070 20250407 920108.BJ 31.72 17.08\n",
|
||||
"7071 20250407 920111.BJ 36.85 19.85\n",
|
||||
"7072 20250407 920116.BJ 116.05 62.49\n",
|
||||
"7073 20250407 920118.BJ 38.07 20.51\n",
|
||||
"7074 20250407 920128.BJ 43.38 23.36\n",
|
||||
"\n",
|
||||
"[7065 rows x 4 columns], trade_date ts_code up_limit down_limit\n",
|
||||
"0 20250326 000001.SZ 12.57 10.29\n",
|
||||
"1 20250326 000002.SZ 7.91 6.47\n",
|
||||
"2 20250326 000004.SZ 11.28 9.23\n",
|
||||
"3 20250326 000006.SZ 7.17 5.87\n",
|
||||
"4 20250326 000007.SZ 6.67 5.45\n",
|
||||
"... ... ... ... ...\n",
|
||||
"7056 20250326 920108.BJ 33.96 18.30\n",
|
||||
"7057 20250326 920111.BJ 41.92 22.58\n",
|
||||
"7058 20250326 920116.BJ 133.64 71.96\n",
|
||||
"7059 20250326 920118.BJ 41.93 22.59\n",
|
||||
"7060 20250326 920128.BJ 49.40 26.60\n",
|
||||
"\n",
|
||||
"[7061 rows x 4 columns], trade_date ts_code up_limit down_limit\n",
|
||||
"0 20250325 000001.SZ 12.52 10.24\n",
|
||||
"1 20250325 000002.SZ 7.90 6.46\n",
|
||||
"2 20250325 000004.SZ 11.55 9.45\n",
|
||||
"3 20250325 000006.SZ 7.13 5.83\n",
|
||||
"4 20250325 000007.SZ 6.60 5.40\n",
|
||||
"... ... ... ... ...\n",
|
||||
"7055 20250325 920108.BJ 33.30 17.94\n",
|
||||
"7056 20250325 920111.BJ 39.97 21.53\n",
|
||||
"7057 20250325 920116.BJ 137.78 74.20\n",
|
||||
"7058 20250325 920118.BJ 39.52 21.28\n",
|
||||
"7059 20250325 920128.BJ 46.22 24.90\n",
|
||||
"\n",
|
||||
"[7060 rows x 4 columns], trade_date ts_code up_limit down_limit\n",
|
||||
"0 20250324 000001.SZ 12.56 10.28\n",
|
||||
"1 20250324 000002.SZ 8.10 6.62\n",
|
||||
"2 20250324 000004.SZ 12.82 10.49\n",
|
||||
"3 20250324 000006.SZ 7.44 6.08\n",
|
||||
"4 20250324 000007.SZ 6.89 5.63\n",
|
||||
"... ... ... ... ...\n",
|
||||
"7053 20250324 920108.BJ 34.84 18.76\n",
|
||||
"7054 20250324 920111.BJ 40.41 21.77\n",
|
||||
"7055 20250324 920116.BJ 134.55 72.45\n",
|
||||
"7056 20250324 920118.BJ 38.67 20.83\n",
|
||||
"7057 20250324 920128.BJ 45.86 24.70\n",
|
||||
"\n",
|
||||
"[7058 rows x 4 columns]]\n"
|
||||
"[7075 rows x 4 columns]]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": 4
|
||||
"source": [
|
||||
"print(all_daily_data)\n",
|
||||
"# 将所有数据合并为一个 DataFrame\n",
|
||||
"all_daily_data_df = pd.concat(all_daily_data, ignore_index=True)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"id": "ad9733a1-2f42-43ee-a98c-0bf699304c21",
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-30T16:43:03.696614Z",
|
||||
"start_time": "2025-03-30T16:43:03.411036Z"
|
||||
"end_time": "2025-04-06T15:34:48.966102Z",
|
||||
"start_time": "2025-04-06T15:34:48.693158Z"
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"\n",
|
||||
"\n",
|
||||
"# 将数据保存为 HDF5 文件(table 格式)\n",
|
||||
"all_daily_data_df.to_hdf(h5_filename, key='stk_limit', mode='a', format='table', append=True, data_columns=True)\n",
|
||||
"\n",
|
||||
"print(\"所有每日基础数据获取并保存完毕!\")"
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
@@ -261,20 +206,27 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": 5
|
||||
"source": [
|
||||
"\n",
|
||||
"\n",
|
||||
"# 将数据保存为 HDF5 文件(table 格式)\n",
|
||||
"all_daily_data_df.to_hdf(h5_filename, key='stk_limit', mode='a', format='table', append=True, data_columns=True)\n",
|
||||
"\n",
|
||||
"print(\"所有每日基础数据获取并保存完毕!\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "7e777f1f-4d54-4a74-b916-691ede6af055",
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-30T16:43:03.713628Z",
|
||||
"start_time": "2025-03-30T16:43:03.711521Z"
|
||||
"end_time": "2025-04-06T15:34:48.980659Z",
|
||||
"start_time": "2025-04-06T15:34:48.977771Z"
|
||||
}
|
||||
},
|
||||
"source": [],
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
||||
Reference in New Issue
Block a user