2.15
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "b94bb1f2-5332-485e-ae1b-eea01f938106",
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
@@ -9,43 +10,24 @@
|
||||
"start_time": "2025-02-11T15:21:54.050569Z"
|
||||
}
|
||||
},
|
||||
"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": "742c29d453b9bb38",
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-02-11T15:22:32.726905Z",
|
||||
"start_time": "2025-02-11T15:22:25.018135Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"import time\n",
|
||||
"\n",
|
||||
"h5_filename = '../../../data/money_flow.h5'\n",
|
||||
"key = '/money_flow'\n",
|
||||
"max_date = None\n",
|
||||
"with pd.HDFStore(h5_filename, mode='r') as store:\n",
|
||||
" df = store[key][['ts_code', 'trade_date']]\n",
|
||||
" print(df.info())\n",
|
||||
" max_date = df['trade_date'].max()\n",
|
||||
"\n",
|
||||
"print(max_date)\n",
|
||||
"trade_cal = pro.trade_cal(exchange='', start_date='20170101', end_date='20250220')\n",
|
||||
"trade_cal = trade_cal[trade_cal['is_open'] == 1] # 只保留交易日\n",
|
||||
"trade_dates = trade_cal[trade_cal['cal_date'] > max_date]['cal_date'].tolist()\n",
|
||||
"start_date = min(trade_dates)\n",
|
||||
"print(f'start_date: {start_date}')"
|
||||
],
|
||||
"id": "742c29d453b9bb38",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
@@ -66,18 +48,52 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": 6
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"import time\n",
|
||||
"\n",
|
||||
"h5_filename = '../../../data/money_flow.h5'\n",
|
||||
"key = '/money_flow'\n",
|
||||
"max_date = None\n",
|
||||
"with pd.HDFStore(h5_filename, mode='r') as store:\n",
|
||||
" df = store[key][['ts_code', 'trade_date']]\n",
|
||||
" print(df.info())\n",
|
||||
" max_date = df['trade_date'].max()\n",
|
||||
"\n",
|
||||
"print(max_date)\n",
|
||||
"trade_cal = pro.trade_cal(exchange='', start_date='20170101', end_date='20250220')\n",
|
||||
"trade_cal = trade_cal[trade_cal['is_open'] == 1] # 只保留交易日\n",
|
||||
"trade_dates = trade_cal[trade_cal['cal_date'] > max_date]['cal_date'].tolist()\n",
|
||||
"start_date = min(trade_dates)\n",
|
||||
"print(f'start_date: {start_date}')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "679ce40e-8d62-4887-970c-e1d8cbdeee6b",
|
||||
"metadata": {
|
||||
"scrolled": true,
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-02-11T15:22:14.513527Z",
|
||||
"start_time": "2025-02-11T15:22:12.973331Z"
|
||||
}
|
||||
},
|
||||
"scrolled": true
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"任务 20250220 完成\n",
|
||||
"任务 20250219 完成\n",
|
||||
"任务 20250217 完成\n",
|
||||
"任务 20250218 完成\n",
|
||||
"任务 20250213 完成\n",
|
||||
"任务 20250214 完成\n",
|
||||
"任务 20250212 完成\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from concurrent.futures import ThreadPoolExecutor, as_completed\n",
|
||||
"\n",
|
||||
@@ -107,40 +123,26 @@
|
||||
" except Exception as e:\n",
|
||||
" print(f\"获取 {trade_date} 数据时出错: {e}\")\n",
|
||||
"\n"
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"任务 20250219 完成\n",
|
||||
"任务 20250220 完成\n",
|
||||
"任务 20250218 完成\n",
|
||||
"任务 20250217 完成\n",
|
||||
"任务 20250214 完成\n",
|
||||
"任务 20250213 完成\n",
|
||||
"任务 20250212 完成\n",
|
||||
"任务 20250211 完成\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": 3
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "9af80516849d4e80",
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-02-11T15:22:16.656650Z",
|
||||
"start_time": "2025-02-11T15:22:16.639271Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": "all_daily_data_df = pd.concat(all_daily_data, ignore_index=True)\n",
|
||||
"id": "9af80516849d4e80",
|
||||
"outputs": [],
|
||||
"execution_count": 4
|
||||
"source": [
|
||||
"all_daily_data_df = pd.concat(all_daily_data, ignore_index=True)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"id": "a2b05187-437f-4053-bc43-bd80d4cf8b0e",
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
@@ -148,15 +150,6 @@
|
||||
"start_time": "2025-02-11T15:22:19.145561Z"
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"\n",
|
||||
"# 将所有数据合并为一个 DataFrame\n",
|
||||
"\n",
|
||||
"# 将数据保存为 HDF5 文件(table 格式)\n",
|
||||
"all_daily_data_df.to_hdf(h5_filename, key='money_flow', mode='a', format='table', append=True, data_columns=True)\n",
|
||||
"\n",
|
||||
"print(\"所有每日基础数据获取并保存完毕!\")"
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
@@ -166,7 +159,15 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": 5
|
||||
"source": [
|
||||
"\n",
|
||||
"# 将所有数据合并为一个 DataFrame\n",
|
||||
"\n",
|
||||
"# 将数据保存为 HDF5 文件(table 格式)\n",
|
||||
"all_daily_data_df.to_hdf(h5_filename, key='money_flow', mode='a', format='table', append=True, data_columns=True)\n",
|
||||
"\n",
|
||||
"print(\"所有每日基础数据获取并保存完毕!\")"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
||||
Reference in New Issue
Block a user