From c196e336487369019182ad6845d75c7780b220f8 Mon Sep 17 00:00:00 2001 From: aszerW Date: Wed, 25 Mar 2026 22:16:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(report):=20=E4=BF=AE=E5=A4=8D=E8=B0=83?= =?UTF-8?q?=E4=BB=93=E4=BF=A1=E5=8F=B7=E6=8A=A5=E5=91=8A=E4=B8=ADETF?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=98=BE=E7=A4=BA=E4=B8=8E=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在调仓信号表格中添加ETF代码列,完善持仓数据展示 - 处理ETF代码缺失情况,显示为“直接交易” - 调整表格列宽,优化整体排版宽度 - 完善调入和调出持仓部分的ETF信息获取逻辑 --- strategies/rotation/report.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/strategies/rotation/report.py b/strategies/rotation/report.py index 0ceaa1e..435d361 100644 --- a/strategies/rotation/report.py +++ b/strategies/rotation/report.py @@ -465,9 +465,9 @@ def _plot_report_chart( data_base_date_str = data_base_date.strftime("%Y-%m-%d") ax0.set_title(f"最新调仓信号 (信号日期: {signal_date_str},基于 {data_base_date_str} 数据,下一交易日执行)", fontsize=14, fontweight="bold", loc="left", pad=15) - # 构建表格数据(添加ETF净值和溢价率列) + # 构建表格数据(添加ETF代码、ETF净值和溢价率列) table_data = [] - col_labels = ["标的名称", "指数代码", "仓位", "得分", "进场日期", "进场价", "最新价", "ETF净值", "溢价率", "操作", "持有天数", "盈亏"] + col_labels = ["标的名称", "指数代码", "ETF代码", "仓位", "得分", "进场日期", "进场价", "最新价", "ETF净值", "溢价率", "操作", "持有天数", "盈亏"] # 下期持仓(调入/维持) for pos in latest["positions"]: @@ -477,10 +477,13 @@ def _plot_report_chart( entry_date_str = pos["entry_date"].strftime("%m-%d") if pos.get("entry_date") else "—" score_str = f'{pos["score"]:.2f}' if pos["score"] is not None else "—" - # 获取ETF净值和溢价率 + # 获取ETF代码、ETF净值和溢价率 idx_code = pos["code"] cfg = code_config.get(idx_code, {}) market = cfg.get('market', 'A') + etf_code = cfg.get('etf', '—') + if etf_code is None: + etf_code = '直接交易' if market == 'CRYPTO': etf_nav_str = "—" @@ -496,7 +499,7 @@ def _plot_report_chart( premium_str = "—" table_data.append([ - pos["name"], pos["code"], f'{pos["weight"]:.0%}', + pos["name"], pos["code"], etf_code, f'{pos["weight"]:.0%}', score_str, entry_date_str, entry_str, f'{pos["current_price"]:.2f}', etf_nav_str, premium_str, pos["action"], days_str, pnl_str ]) @@ -509,10 +512,13 @@ def _plot_report_chart( entry_date_str = pos["entry_date"].strftime("%m-%d") if pos.get("entry_date") else "—" score_str = "—" # 调出品种无得分 - # 获取ETF净值和溢价率 + # 获取ETF代码、ETF净值和溢价率 idx_code = pos["code"] cfg = code_config.get(idx_code, {}) market = cfg.get('market', 'A') + etf_code = cfg.get('etf', '—') + if etf_code is None: + etf_code = '直接交易' if market == 'CRYPTO': etf_nav_str = "—" @@ -528,7 +534,7 @@ def _plot_report_chart( premium_str = "—" table_data.append([ - pos["name"], pos["code"], f'{pos["weight"]:.0%}', + pos["name"], pos["code"], etf_code, f'{pos["weight"]:.0%}', score_str, entry_date_str, entry_str, f'{pos["current_price"]:.2f}', etf_nav_str, premium_str, "调出", days_str, pnl_str ]) @@ -539,7 +545,7 @@ def _plot_report_chart( colLabels=col_labels, loc="center", cellLoc="center", - colWidths=[0.09, 0.09, 0.06, 0.07, 0.07, 0.07, 0.07, 0.07, 0.08, 0.06, 0.07, 0.07], + colWidths=[0.08, 0.08, 0.08, 0.05, 0.06, 0.06, 0.06, 0.06, 0.06, 0.07, 0.05, 0.06, 0.06], bbox=[0, 0, 1, 1], # 使用完整宽度 ) table.auto_set_font_size(False)