mcpField
T
trader-memory-core

trader-memory-core

github.com/mphinance其他3287 次安装3 天前更新
代码仓库

关于 trader-memory-core

trader-memory-core 是用于投资研究的持久化状态技能,将筛选、分析、仓位规模和组合管理结果整合为每个投资想法的 thesis,并跨对话记录状态与复盘。当前支持单标的 thesis 生命周期管理。

主要功能

  1. 01整合研究结果为 thesis
  2. 02管理 thesis 状态与仓位
  3. 03按代码、状态或类型查询
  4. 04跟踪复核日期与提醒
  5. 05生成平仓复盘和统计

适用场景

  1. 01登记筛选器生成的投资候选
  2. 02将 thesis 推进至入场或持仓状态
  3. 03查找待复核的 thesis
  4. 04平仓后记录表现与经验

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mphinance/alpha-skills --skill trader-memory-core

安装后在 Claude Code 中输入/trader-memory-core确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

README.md
assets/
postmortem_template.md
references/
field_mapping.md
thesis_lifecycle.md
schemas/
thesis.schema.json
scripts/
fmp_price_adapter.py
thesis_ingest.py
thesis_review.py
thesis_store.py
scripts/tests/
conftest.py
test_fmp_price_adapter.py
test_thesis_ingest.py
test_thesis_review.py
test_thesis_store.py

详细介绍

Trader Memory Core

概述

持久化状态层,将筛选 → 分析 → 仓位规模 → 投资组合管理的输出整合为每个投资想法对应的单个“投资论点对象”。跨对话跟踪你的判断、实际情况以及所学到的经验。

第 1 阶段支持单标的投资论点:dividend_income、growth_momentum、mean_reversion、earnings_drift、pivot_breakout。

使用场景

  • 筛选器(kanchi、earnings-trade-analyzer、vcp、pead、canslim、edge-candidate-agent)生成候选标的后
  • 将投资论点从 IDEA → ENTRY_READY → ACTIVE → CLOSED 迁移时
  • 将仓位计算器的输出附加到投资论点时
  • 检查哪些投资论点需要复审时
  • 平仓并生成包含经验总结的事后复盘时

先决条件

  • Python 3.10+
  • pyyaml(已包含在项目依赖项中)
  • FMP API 密钥(可选,仅用于事后复盘中的 MAE/MFE 计算)

工作流

1. 注册 — 将筛选器输出导入为投资论点

读取筛选器的 JSON 输出,并使用相应的适配器将其转换为投资论点。

python3 skills/trader-memory-core/scripts/thesis_ingest.py \
  --source kanchi-dividend-sop \
  --input reports/kanchi_entry_signals_2026-03-14.json \
  --state-dir state/theses/

支持的来源:kanchi-dividend-sop、earnings-trade-analyzer、vcp-screener、pead-screener、canslim-screener、edge-candidate-agent。

每个投资论点的初始状态都是 IDEA。

2. 查询 — 搜索和列出投资论点
python3 skills/trader-memory-core/scripts/thesis_store.py \
  --state-dir state/theses/ list --ticker AAPL --status ACTIVE

按 --ticker、--status 或 --type 筛选。

3. 更新 — 迁移状态、附加仓位、关联报告

状态迁移(仅 IDEA → ENTRY_READY):

在 Python 中使用 thesis_store.transition(state_dir, thesis_id, "ENTRY_READY", reason)。

建立仓位(ENTRY_READY → ACTIVE):

使用 thesis_store.open_position(state_dir, thesis_id, actual_price, actual_date) — 这是进入 ACTIVE 状态的唯一途径。可选传入 shares 和 event_date(用于补录过去的交易)。

平仓或作废(→ CLOSED 或 INVALIDATED):

使用 thesis_store.terminate(state_dir, thesis_id, terminal_status, exit_reason, actual_price, actual_date)。对于 CLOSED,会委托给 close() 计算盈亏。对于 INVALIDATED,如果入场价和出场价可用,也会计算盈亏。

记录复审(任何非终态):

使用 thesis_store.mark_reviewed(state_dir, thesis_id, review_date=..., outcome="OK"|"WARN"|"REVIEW") 推进 next_review_date 并记录提醒。

附加仓位计算器输出:

使用 thesis_store.attach_position(state_dir, thesis_id, report_path) 关联仓位规模数据。该操作会验证报告模式为 “shares”(而不是 budget)。

关联相关报告:

使用 thesis_store.link_report(state_dir, thesis_id, skill, file, date) 交叉引用分析文档。

4. 复审 — 检查到期日期和监控状态
python3 skills/trader-memory-core/scripts/thesis_review.py \
  --state-dir state/theses/ review-due --as-of 2026-04-15

列出 next_review_date <= as_of 的投资论点。结合 kanchi-dividend-review-monitor 触发条件(T1-T5)进行系统化复审。

5. 事后复盘 — 平仓并总结
python3 skills/trader-memory-core/scripts/thesis_review.py \
  --state-dir state/theses/ postmortem th_aapl_div_20260314_a3f1

在 state/journal/ 中生成结构化的事后复盘。如果有 FMP API 密钥,还会包含 MAE/MFE(最大不利/有利波动)指标。

汇总统计:

python3 skills/trader-memory-core/scripts/thesis_review.py \
  --state-dir state/theses/ summary

显示所有已平仓投资论点的胜率、平均 P&L% 和按类型细分的数据。

输出格式

投资论点 YAML(state/theses/)

每个投资论点都是一个 YAML 文件,包含:

  • 标识信息:thesis_id、ticker、created_at
  • 分类:thesis_type、setup_type、catalyst
  • 生命周期:status、status_history
  • 入场/出场:目标价格、实际价格、条件
  • 仓位:股数、价值、风险(从 position-sizer 附加)
  • 监控:复审日期、触发条件、提醒
  • 来源:来源技能、筛选评级、原始溯源信息
  • 结果:P&L、持有天数、MAE/MFE、经验总结
索引(state/theses/_index.json)

轻量级索引,无需加载完整 YAML 文件即可快速查询。

日志(state/journal/)

事后复盘 Markdown 报告:pm_{thesis_id}.md。

核心原则

  • 仅向前转换:IDEA → ENTRY_READY → ACTIVE → CLOSED(不可回退)
  • 原始来源数据:所有原始筛选器数据均保存在 origin.raw_provenance 中
  • 原子写入:所有文件操作均使用 tempfile + os.replace
  • 由 Git 跟踪的状态:提交 state/ 目录,以提供审计跟踪
  • 第一阶段范围:仅支持单一标的的投资论点(配对交易和期权将在第二阶段支持)

资源

  • references/thesis_lifecycle.md — 状态及有效转换
  • references/field_mapping.md — 源技能到规范字段的映射
  • schemas/thesis.schema.json — 用于验证投资论点的 JSON Schema

评论

支持 Markdown