程序员量化交易实战 33:汇总模拟盘运行历史
第 32 篇把每日运行结果写成了 JSON 归档。单日归档解决了“当天发生了什么”。第 33 篇要回答另一个问题最近一段时间这个模拟盘系统是否稳定。历史摘要看什么现在先不做复杂报表只统计四个最基础的指标字段含义report_count归档报告数量latest_trade_date最新交易日latest_status最新健康状态blocker_count历史阻断次数notification_success_rate通知成功率这些指标足够支撑一个很实际的判断如果最近十天有三天 blocker问题不在策略而在运行链路。摘要对象第 33 章新增app/run_history.py。dataclass(frozenTrue) class RunHistorySummary: report_count: int latest_trade_date: str latest_status: str blocker_count: int notification_success_rate: float这不是策略收益统计而是运行质量统计。从归档目录读取实现逻辑很直接读取目录下所有*-paper-report.json按文件名排序然后统计。reports [] for path in sorted(Path(directory).glob(*-paper-report.json)): reports.append(read_archived_report(path))空目录也要有明确返回不能抛异常。if not reports: return RunHistorySummary(0, , missing, 0, 0.0)对模拟盘来说missing是一个有用状态。它告诉上层不是系统健康而是还没有历史。通知成功率通知成功率按归档报告里的健康信息统计。notification_count sum( 1 for item in reports if item[health].get(notification_accepted) )最后保留 6 位小数notification_success_rateround(notification_count / len(reports), 6)这里没有引入 pandas也没有做图。运行历史摘要应该足够轻可以在命令行、接口、日报里随手调用。当前联动运行结果paper-ops-check会先写入一条前一日 blocker 归档再写入当天 ok 归档然后从归档目录汇总历史uv run python -m scripts.chapter_examples paper-ops-check这次历史摘要里report_count2blocker_count1通知成功率是50%。这不是收益统计而是运行质量统计。等真实调度接入以后这类摘要可以快速回答“最近是策略表现不好还是系统经常没跑稳”。测试历史统计测试先复用第 32 章的归档函数造两天数据uv run pytest tests/test_run_history.py关键断言assert summary.report_count 2 assert summary.latest_trade_date 2026-01-29 assert summary.latest_status blocker assert summary.blocker_count 1 assert summary.notification_success_rate 0.5这组断言说明历史摘要能跨多个归档文件稳定工作。本章更新与代码仓库本章更新内容新增app/run_history.py。实现RunHistorySummary。从日报归档目录读取历史报告。统计报告数量、最新状态、阻断次数和通知成功率。增加paper-ops-check联动示例展示两日归档汇总后的运行历史。补充运行质量统计和收益统计的区别。新增tests/test_run_history.py覆盖正常目录和空目录。代码仓库https://github.com/ax2/zi-quant-platform本章代码git clone https://github.com/ax2/zi-quant-platform.git cd zi-quant-platform git checkout chapter-33 uv sync --extra dev uv run pytest tests/test_run_history.py第 33 章提交为9f55d07tag 为chapter-33。本篇小结历史摘要让模拟盘从“今天是否跑完”变成“最近是否稳定”。第 33 篇读取归档报告拿到最新状态、阻断次数和通知成功率。下一篇会继续补一个常见的生产问题行情数据缺口应该如何被显式识别而不是被策略静默忽略。