fix(report): 修复调仓信号报告中ETF代码显示与表格布局
- 在调仓信号表格中添加ETF代码列,完善持仓数据展示 - 处理ETF代码缺失情况,显示为“直接交易” - 调整表格列宽,优化整体排版宽度 - 完善调入和调出持仓部分的ETF信息获取逻辑
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user