增加了先前缺失的现金流量表的导入模块。

This commit is contained in:
2026-08-12 22:13:30 +08:00
parent 9697b59d4f
commit 3684f4e2da
2 changed files with 177 additions and 7 deletions
+52 -7
View File
@@ -92,6 +92,8 @@
" import_adj_factor,\n",
" import_adj_factor_batch,\n",
" import_financial_statements,\n",
" import_cashflow,\n",
" import_cashflow_batch,\n",
" import_index_daily,\n",
" get_all_stock_codes,\n",
" get_stock_codes_from_db,\n",
@@ -519,13 +521,56 @@
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 验证财务数据\n",
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 7.1 单独导入现金流量表 (cashflow_vip VIP 接口)\n",
"\n",
"`import_cashflow` 使用 Tushare VIP 接口 `cashflow_vip`,支持两种方式:\n",
"- 按报告期全市场导入: `import_cashflow(period=\"20181231\")`,对应示例 `df2 = pro.cashflow_vip(period='20181231', fields='')`\n",
"- 按股票导入: `import_cashflow(ts_code=\"000001.SZ\", start_date=..., end_date=...)`,或批量 `import_cashflow_batch(stock_list, ...)`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 方式A: 按报告期全市场导入 (推荐,一次拉取全市场某报告期数据,调用次数最少)\n",
"# n = import_cashflow(period=\"20241231\") # 对应 pro.cashflow_vip(period='20241231', fields='')\n",
"# print(f\"导入 20241231 报告期现金流量表: {n} 条\")\n",
"\n",
"# 方式B: 按股票列表批量导入 (适合补单只/部分股票数据)\n",
"if 'stock_list' not in dir():\n",
" stock_list = get_stock_codes_from_db()\n",
"\n",
"import_cashflow_batch(\n",
" stock_list,\n",
" start_date=\"2010-01-01\",\n",
" end_date=\"2025-12-31\",\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 方式C: 导入单只股票的现金流量表\n",
"# n = import_cashflow(ts_code=\"000001.SZ\", start_date=\"2010-01-01\", end_date=\"2025-12-31\")\n",
"# print(f\"导入 000001.SZ 现金流量表: {n} 条\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 验证财务数据\n",
"conn = get_pg_connection()\n",
"cursor = conn.cursor()\n",
"for table in [\"income\", \"balancesheet\", \"cashflow\", \"fina_indicator\"]:\n",