financial-analyst 0.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. financial_analyst-0.6.0/.env.example +7 -0
  2. financial_analyst-0.6.0/.gitignore +15 -0
  3. financial_analyst-0.6.0/CHANGELOG.md +118 -0
  4. financial_analyst-0.6.0/CLAUDE.md +18 -0
  5. financial_analyst-0.6.0/LICENSE +195 -0
  6. financial_analyst-0.6.0/PKG-INFO +217 -0
  7. financial_analyst-0.6.0/README.md +165 -0
  8. financial_analyst-0.6.0/README_zh.md +29 -0
  9. financial_analyst-0.6.0/config/data_sources.yaml +37 -0
  10. financial_analyst-0.6.0/config/llm.yaml +31 -0
  11. financial_analyst-0.6.0/config/loaders.yaml +14 -0
  12. financial_analyst-0.6.0/config/models.yaml +7 -0
  13. financial_analyst-0.6.0/config/plugins.yaml +10 -0
  14. financial_analyst-0.6.0/config/swarm/stock-deep-dive.yaml +62 -0
  15. financial_analyst-0.6.0/docs/architecture.md +56 -0
  16. financial_analyst-0.6.0/docs/ask.md +43 -0
  17. financial_analyst-0.6.0/docs/byom.md +105 -0
  18. financial_analyst-0.6.0/docs/data_ingest.md +169 -0
  19. financial_analyst-0.6.0/docs/dream_loop.md +72 -0
  20. financial_analyst-0.6.0/docs/extending.md +74 -0
  21. financial_analyst-0.6.0/docs/memories.md +88 -0
  22. financial_analyst-0.6.0/examples/__init__.py +0 -0
  23. financial_analyst-0.6.0/examples/custom_f10_collector.py +50 -0
  24. financial_analyst-0.6.0/examples/custom_loader_csv_only.py +52 -0
  25. financial_analyst-0.6.0/examples/custom_model_fm_cluster.py +64 -0
  26. financial_analyst-0.6.0/examples/custom_news_collector.py +65 -0
  27. financial_analyst-0.6.0/memories/_shared/playbook_V1_V10.md +38 -0
  28. financial_analyst-0.6.0/memories/bear-advocate/failure_modes_F1_F14.md +43 -0
  29. financial_analyst-0.6.0/memories/bear-advocate/pitfalls.md +547 -0
  30. financial_analyst-0.6.0/memories/bull-advocate/factor_insights_long_side.md +22 -0
  31. financial_analyst-0.6.0/memories/f10-reader/known_game_capital.md +35 -0
  32. financial_analyst-0.6.0/memories/fundamental-analyst/rating_system.md +348 -0
  33. financial_analyst-0.6.0/memories/fundamental-analyst/valuation_playbook.md +19 -0
  34. financial_analyst-0.6.0/memories/introspector/introspector_rules.md +37 -0
  35. financial_analyst-0.6.0/memories/news-reader/extraction_rules.md +18 -0
  36. financial_analyst-0.6.0/memories/quant-analyst/rules_learned.md +41 -0
  37. financial_analyst-0.6.0/memories/quant-analyst/tsfm_zero_shot.md +16 -0
  38. financial_analyst-0.6.0/memories/quant-analyst/v4_factor_evolution.md +16 -0
  39. financial_analyst-0.6.0/memories/report-writer/rating_system.md +348 -0
  40. financial_analyst-0.6.0/memories/report-writer/report_template.md +50 -0
  41. financial_analyst-0.6.0/memories/risk-officer/V10_execution_discipline.md +15 -0
  42. financial_analyst-0.6.0/memories/risk-officer/always_include.txt +1 -0
  43. financial_analyst-0.6.0/memories/risk-officer/hard_rules.md +26 -0
  44. financial_analyst-0.6.0/memories/risk-officer/lagging_signal_lesson_D45_D46.md +15 -0
  45. financial_analyst-0.6.0/memories/technical-analyst/5min_10round_report.md +147 -0
  46. financial_analyst-0.6.0/memories/technical-analyst/factor_insights.md +417 -0
  47. financial_analyst-0.6.0/memories/whale-analyst/board_scorer_v5.md +20 -0
  48. financial_analyst-0.6.0/memories/whale-analyst/sentiment_signals_R7_R20.md +19 -0
  49. financial_analyst-0.6.0/memories/whale-analyst/whale_judge_rules.md +29 -0
  50. financial_analyst-0.6.0/pyproject.toml +96 -0
  51. financial_analyst-0.6.0/scripts/init_memories.py +38 -0
  52. financial_analyst-0.6.0/src/financial_analyst/__init__.py +3 -0
  53. financial_analyst-0.6.0/src/financial_analyst/agent/__init__.py +0 -0
  54. financial_analyst-0.6.0/src/financial_analyst/agent/base.py +66 -0
  55. financial_analyst-0.6.0/src/financial_analyst/agent/memory.py +129 -0
  56. financial_analyst-0.6.0/src/financial_analyst/agent/memory_index.py +264 -0
  57. financial_analyst-0.6.0/src/financial_analyst/agent/orchestrator.py +64 -0
  58. financial_analyst-0.6.0/src/financial_analyst/agent/registry.py +28 -0
  59. financial_analyst-0.6.0/src/financial_analyst/agent/schemas.py +48 -0
  60. financial_analyst-0.6.0/src/financial_analyst/agent/tier1/__init__.py +0 -0
  61. financial_analyst-0.6.0/src/financial_analyst/agent/tier1/f10_reader.py +75 -0
  62. financial_analyst-0.6.0/src/financial_analyst/agent/tier1/factor_computer.py +103 -0
  63. financial_analyst-0.6.0/src/financial_analyst/agent/tier1/model_predictor.py +36 -0
  64. financial_analyst-0.6.0/src/financial_analyst/agent/tier1/news_reader.py +73 -0
  65. financial_analyst-0.6.0/src/financial_analyst/agent/tier1/quote_fetcher.py +96 -0
  66. financial_analyst-0.6.0/src/financial_analyst/agent/tier2/__init__.py +0 -0
  67. financial_analyst-0.6.0/src/financial_analyst/agent/tier2/fundamental_analyst.py +64 -0
  68. financial_analyst-0.6.0/src/financial_analyst/agent/tier2/quant_analyst.py +64 -0
  69. financial_analyst-0.6.0/src/financial_analyst/agent/tier2/technical_analyst.py +69 -0
  70. financial_analyst-0.6.0/src/financial_analyst/agent/tier2/whale_analyst.py +62 -0
  71. financial_analyst-0.6.0/src/financial_analyst/agent/tier3/__init__.py +0 -0
  72. financial_analyst-0.6.0/src/financial_analyst/agent/tier3/bear_advocate.py +74 -0
  73. financial_analyst-0.6.0/src/financial_analyst/agent/tier3/bull_advocate.py +63 -0
  74. financial_analyst-0.6.0/src/financial_analyst/agent/tier3/report_writer.py +140 -0
  75. financial_analyst-0.6.0/src/financial_analyst/agent/tier3/risk_officer.py +82 -0
  76. financial_analyst-0.6.0/src/financial_analyst/ask/__init__.py +5 -0
  77. financial_analyst-0.6.0/src/financial_analyst/ask/ask_agent.py +120 -0
  78. financial_analyst-0.6.0/src/financial_analyst/ask/schemas.py +12 -0
  79. financial_analyst-0.6.0/src/financial_analyst/ask/tools.py +269 -0
  80. financial_analyst-0.6.0/src/financial_analyst/cli.py +308 -0
  81. financial_analyst-0.6.0/src/financial_analyst/data/__init__.py +0 -0
  82. financial_analyst-0.6.0/src/financial_analyst/data/cache.py +34 -0
  83. financial_analyst-0.6.0/src/financial_analyst/data/collectors/__init__.py +10 -0
  84. financial_analyst-0.6.0/src/financial_analyst/data/collectors/f10/__init__.py +3 -0
  85. financial_analyst-0.6.0/src/financial_analyst/data/collectors/f10/base.py +38 -0
  86. financial_analyst-0.6.0/src/financial_analyst/data/collectors/news/__init__.py +3 -0
  87. financial_analyst-0.6.0/src/financial_analyst/data/collectors/news/base.py +35 -0
  88. financial_analyst-0.6.0/src/financial_analyst/data/ingest/__init__.py +14 -0
  89. financial_analyst-0.6.0/src/financial_analyst/data/ingest/akshare_ingester.py +30 -0
  90. financial_analyst-0.6.0/src/financial_analyst/data/ingest/base.py +38 -0
  91. financial_analyst-0.6.0/src/financial_analyst/data/ingest/bin_writer.py +100 -0
  92. financial_analyst-0.6.0/src/financial_analyst/data/ingest/csv_ingester.py +205 -0
  93. financial_analyst-0.6.0/src/financial_analyst/data/ingest/yfinance_ingester.py +30 -0
  94. financial_analyst-0.6.0/src/financial_analyst/data/loader_factory.py +77 -0
  95. financial_analyst-0.6.0/src/financial_analyst/data/loaders/__init__.py +4 -0
  96. financial_analyst-0.6.0/src/financial_analyst/data/loaders/base.py +33 -0
  97. financial_analyst-0.6.0/src/financial_analyst/data/loaders/qlib_binary.py +259 -0
  98. financial_analyst-0.6.0/src/financial_analyst/data/loaders/tushare.py +158 -0
  99. financial_analyst-0.6.0/src/financial_analyst/dream/__init__.py +10 -0
  100. financial_analyst-0.6.0/src/financial_analyst/dream/introspector.py +85 -0
  101. financial_analyst-0.6.0/src/financial_analyst/dream/outcome_tracker.py +159 -0
  102. financial_analyst-0.6.0/src/financial_analyst/dream/proposal_writer.py +34 -0
  103. financial_analyst-0.6.0/src/financial_analyst/factors/__init__.py +3 -0
  104. financial_analyst-0.6.0/src/financial_analyst/factors/core.py +127 -0
  105. financial_analyst-0.6.0/src/financial_analyst/factors/sentiment/__init__.py +4 -0
  106. financial_analyst-0.6.0/src/financial_analyst/factors/sentiment/board_scorer.py +84 -0
  107. financial_analyst-0.6.0/src/financial_analyst/factors/sentiment/volume_regime.py +55 -0
  108. financial_analyst-0.6.0/src/financial_analyst/factors/whale.py +74 -0
  109. financial_analyst-0.6.0/src/financial_analyst/knowledge/__init__.py +4 -0
  110. financial_analyst-0.6.0/src/financial_analyst/knowledge/base.py +11 -0
  111. financial_analyst-0.6.0/src/financial_analyst/knowledge/local_markdown.py +23 -0
  112. financial_analyst-0.6.0/src/financial_analyst/llm/__init__.py +3 -0
  113. financial_analyst-0.6.0/src/financial_analyst/llm/client.py +68 -0
  114. financial_analyst-0.6.0/src/financial_analyst/models/__init__.py +8 -0
  115. financial_analyst-0.6.0/src/financial_analyst/models/base.py +11 -0
  116. financial_analyst-0.6.0/src/financial_analyst/models/lgb_momentum.py +75 -0
  117. financial_analyst-0.6.0/src/financial_analyst/models/registry.py +33 -0
  118. financial_analyst-0.6.0/src/financial_analyst/plugins.py +61 -0
  119. financial_analyst-0.6.0/src/financial_analyst/settings.py +28 -0
  120. financial_analyst-0.6.0/src/financial_analyst/swarm/__init__.py +4 -0
  121. financial_analyst-0.6.0/src/financial_analyst/swarm/loader.py +97 -0
  122. financial_analyst-0.6.0/src/financial_analyst/tui.py +609 -0
  123. financial_analyst-0.6.0/src/financial_analyst/utils/__init__.py +0 -0
  124. financial_analyst-0.6.0/src/financial_analyst/utils/events.py +15 -0
  125. financial_analyst-0.6.0/tests/__init__.py +0 -0
  126. financial_analyst-0.6.0/tests/conftest.py +4 -0
  127. financial_analyst-0.6.0/tests/integration/__init__.py +0 -0
  128. financial_analyst-0.6.0/tests/integration/test_end_to_end.py +21 -0
  129. financial_analyst-0.6.0/tests/integration/test_memory_mode.py +167 -0
  130. financial_analyst-0.6.0/tests/integration/test_preset_loading.py +24 -0
  131. financial_analyst-0.6.0/tests/integration/test_smoke_deep_dive.py +101 -0
  132. financial_analyst-0.6.0/tests/test_agent_registry.py +30 -0
  133. financial_analyst-0.6.0/tests/test_ask_agent.py +104 -0
  134. financial_analyst-0.6.0/tests/test_ask_cli.py +37 -0
  135. financial_analyst-0.6.0/tests/test_ask_tools.py +97 -0
  136. financial_analyst-0.6.0/tests/test_cache.py +30 -0
  137. financial_analyst-0.6.0/tests/test_cli.py +17 -0
  138. financial_analyst-0.6.0/tests/test_cli_list_commands.py +59 -0
  139. financial_analyst-0.6.0/tests/test_collectors_abc.py +51 -0
  140. financial_analyst-0.6.0/tests/test_dream_cli.py +101 -0
  141. financial_analyst-0.6.0/tests/test_events.py +27 -0
  142. financial_analyst-0.6.0/tests/test_examples_smoke.py +49 -0
  143. financial_analyst-0.6.0/tests/test_factors_core.py +36 -0
  144. financial_analyst-0.6.0/tests/test_factors_sentiment.py +31 -0
  145. financial_analyst-0.6.0/tests/test_factors_whale.py +25 -0
  146. financial_analyst-0.6.0/tests/test_ingest_bin_writer.py +92 -0
  147. financial_analyst-0.6.0/tests/test_ingest_cli.py +119 -0
  148. financial_analyst-0.6.0/tests/test_ingest_csv.py +205 -0
  149. financial_analyst-0.6.0/tests/test_introspector.py +69 -0
  150. financial_analyst-0.6.0/tests/test_knowledge.py +23 -0
  151. financial_analyst-0.6.0/tests/test_lgb_momentum.py +39 -0
  152. financial_analyst-0.6.0/tests/test_llm_client.py +49 -0
  153. financial_analyst-0.6.0/tests/test_loader_factory.py +81 -0
  154. financial_analyst-0.6.0/tests/test_loaders.py +107 -0
  155. financial_analyst-0.6.0/tests/test_loaders_qlib.py +267 -0
  156. financial_analyst-0.6.0/tests/test_memory.py +149 -0
  157. financial_analyst-0.6.0/tests/test_memory_cli.py +123 -0
  158. financial_analyst-0.6.0/tests/test_memory_index.py +88 -0
  159. financial_analyst-0.6.0/tests/test_memory_proposals_cli.py +78 -0
  160. financial_analyst-0.6.0/tests/test_model_registry.py +32 -0
  161. financial_analyst-0.6.0/tests/test_orchestrator.py +42 -0
  162. financial_analyst-0.6.0/tests/test_outcome_tracker.py +109 -0
  163. financial_analyst-0.6.0/tests/test_plugins.py +55 -0
  164. financial_analyst-0.6.0/tests/test_proposal_writer.py +60 -0
  165. financial_analyst-0.6.0/tests/test_schemas.py +10 -0
  166. financial_analyst-0.6.0/tests/test_settings.py +24 -0
  167. financial_analyst-0.6.0/tests/test_subagent_base.py +39 -0
  168. financial_analyst-0.6.0/tests/test_subagents/__init__.py +0 -0
  169. financial_analyst-0.6.0/tests/test_subagents/test_bear_advocate.py +27 -0
  170. financial_analyst-0.6.0/tests/test_subagents/test_bull_advocate.py +32 -0
  171. financial_analyst-0.6.0/tests/test_subagents/test_f10_reader.py +11 -0
  172. financial_analyst-0.6.0/tests/test_subagents/test_factor_computer.py +121 -0
  173. financial_analyst-0.6.0/tests/test_subagents/test_fundamental_analyst.py +120 -0
  174. financial_analyst-0.6.0/tests/test_subagents/test_model_predictor.py +52 -0
  175. financial_analyst-0.6.0/tests/test_subagents/test_news_reader.py +27 -0
  176. financial_analyst-0.6.0/tests/test_subagents/test_quant_analyst.py +39 -0
  177. financial_analyst-0.6.0/tests/test_subagents/test_quote_fetcher.py +31 -0
  178. financial_analyst-0.6.0/tests/test_subagents/test_report_writer.py +105 -0
  179. financial_analyst-0.6.0/tests/test_subagents/test_risk_officer.py +40 -0
  180. financial_analyst-0.6.0/tests/test_subagents/test_technical_analyst.py +107 -0
  181. financial_analyst-0.6.0/tests/test_subagents/test_whale_analyst.py +132 -0
  182. financial_analyst-0.6.0/tests/test_tui_dispatch.py +31 -0
@@ -0,0 +1,7 @@
1
+ ANTHROPIC_API_KEY=
2
+ OPENAI_API_KEY=
3
+ DASHSCOPE_API_KEY=
4
+ DEEPSEEK_API_KEY=
5
+ TUSHARE_TOKEN=
6
+ FA_LOG_LEVEL=INFO
7
+ FA_CACHE_DIR=~/.financial-analyst/cache
@@ -0,0 +1,15 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .pytest_cache/
4
+ .ruff_cache/
5
+ *.egg-info/
6
+ build/
7
+ dist/
8
+ .env
9
+ out/
10
+ news/**/*.txt
11
+ news/**/*.html
12
+ news/**/*.pdf
13
+ kb/**/*.parquet
14
+ .venv/
15
+ venv/
@@ -0,0 +1,118 @@
1
+ # Changelog
2
+
3
+ ## v0.6.0 — 2026-05-18
4
+
5
+ ### Added
6
+ - First PyPI release. Install: `pip install financial-analyst`.
7
+ - Polished `pyproject.toml` with full metadata (classifiers, urls, keywords, authors).
8
+
9
+ ### Changed
10
+ - README quick-start lead now shows `pip install financial-analyst` instead of `git clone`.
11
+ - Version bump 0.5.0 → 0.6.0.
12
+
13
+ ### Notes
14
+ - No functional code changes vs v0.5.0. This release is packaging-only.
15
+
16
+ ## v0.4.0 — 2026-05-18
17
+
18
+ ### Added (BYOM: Bring Your Own Models)
19
+ - `BaseNewsCollector` ABC — plug-in interface for auto-collecting news into `news/<code>/` drop-zone (`data/collectors/news/base.py`).
20
+ - `BaseF10Collector` ABC — plug-in interface for F10 data (公司公告/龙虎榜/大宗交易) into `f10/<code>/` (`data/collectors/f10/base.py`).
21
+ - 4 example stubs under `examples/`:
22
+ - `custom_model_fm_cluster.py` — FM cluster model pattern
23
+ - `custom_loader_csv_only.py` — minimal CSV-backed `BaseLoader`
24
+ - `custom_news_collector.py` — Tushare news API skeleton
25
+ - `custom_f10_collector.py` — pytdx F10 skeleton
26
+ - Plugin discovery: `config/plugins.yaml` lists user `.py` files exec'd at startup (`src/financial_analyst/plugins.py`).
27
+ - CLI introspection: `financial-analyst {models,loaders,agents,collectors} list`.
28
+ - `docs/byom.md` — full Bring-Your-Own-Models guide.
29
+
30
+ ### Changed
31
+ - README "Extending" section now points to BYOM workflow.
32
+ - `tests/test_agent_registry.py` no longer pollutes the `SubAgentRegistry`; fixtures clear it.
33
+
34
+ ## v0.3.0 — 2026-05-18
35
+
36
+ ### Added (Ingest + Dream Loop)
37
+ - **CSV → Qlib binary ingester** (`data/ingest/csv_ingester.py`) with both long-format and per-code-filename support, schema-configurable, ohlcv field mapping.
38
+ - `BaseIngester` ABC + reserved `AkshareIngester` / `YfinanceIngester` stubs for v0.4+.
39
+ - CLI: `financial-analyst ingest --source <name> [--dry-run]`.
40
+ - **Dream loop** for agent self-improving memory:
41
+ - `OutcomeTracker` — measure T+5d/T+20d outcomes against past predictions in `out/*.json`, scoring verdict ∈ {correct, wrong, partial, pending}.
42
+ - `Introspector` sub-agent — LLM-driven post-mortem analyst (NOT in stock-deep-dive preset).
43
+ - `ProposalWriter` — writes `Introspector` proposals to `memories/_proposed/<agent>/<date>_<slug>.md` with YAML frontmatter.
44
+ - `memories/introspector/introspector_rules.md` meta-rules (focus on wrong>partial>correct, 2/3-5/6+ confidence thresholds, target risk-officer when in doubt).
45
+ - CLI: `financial-analyst dream [--since 30] [--dry-run]`.
46
+ - TUI: `/dream`, `/memory list-proposals`, `/memory accept _proposed/<file>`, `/memory reject _proposed/<file>`.
47
+ - `docs/data_ingest.md`, `docs/dream_loop.md`.
48
+
49
+ ### Changed
50
+ - `config/data_sources.yaml` template added for ingester config.
51
+ - Memory CLI usage strings updated to list all 11 subcommands.
52
+
53
+ ### Safety
54
+ - Dream proposals require human review (no auto-merge); auto-accept is explicitly NOT implemented.
55
+ - `/memory accept` only operates on paths starting with `_proposed/`.
56
+
57
+ ## v0.2.3 — 2026-05-18
58
+
59
+ ### Fixed (Hotfix found during real SH600666 testing)
60
+ - **`AgentMemory.load_relevant` falls back to `load_all` on 0 FTS5 hits** — prevents agents going "blind" when the JSON-derived query doesn't match memory wording.
61
+ - **Per-agent `always_include.txt`** — listed files load unconditionally regardless of retrieval results. Initial entry: `memories/risk-officer/always_include.txt` lists `hard_rules.md` (game-capital veto must never be missed).
62
+ - **`report-writer` post-validation** — if `risk-officer.veto_flags` is non-empty OR `rating_overall ≤ 0`, `position_pct` is forced to 0 and `action` re-derived. Sanity-override notes appended to the markdown report.
63
+ - **`mv_tier` enum** — `fundamental-analyst.FundamentalOutput.mv_tier` changed from `str` to `Literal["large","mid","small"]`; pre-normalize Chinese variants (`中小盘`→`small`, `大盘`→`large`, etc.) before pydantic validation.
64
+
65
+ ## v0.2.2 — 2026-05-18
66
+
67
+ ### Added
68
+ - **5min bar support**. `QlibBinaryLoader` now accepts `dict` provider_uri with `day` + `5min` (+ optional `1min`) keys.
69
+ - `BaseLoader.fetch_quote` signature extended with `freq: str = "day"` (backward compatible).
70
+ - `factor-computer` auto-fetches 5min bars where available, activating:
71
+ - **board_scorer v5 `seal_micro` dimension** (-3..+3): `seal_bar`, `seal_at_close`, `gap_open`, `open_count`.
72
+ - **volume_regime R11 `tail_surge`** signal: last-30-min volume + return ramp.
73
+ - **R14 super_distr** combined signal (`r9_distr AND r11_tail_surge`).
74
+ - TushareLoader gracefully returns empty DataFrame for non-day freq.
75
+
76
+ ## v0.2.1 — 2026-05-18
77
+
78
+ ### Added
79
+ - `ParquetCache` wired into `TushareLoader` (cache miss → API; cache hit → no network). Configurable TTL (default 86400s = 1 day) and `enable_cache=False` opt-out.
80
+ - `QlibBinaryLoader` reads Qlib binary directories — zero-network microsecond reads. Schema: `<provider_uri>/calendars/day.txt` + `instruments/all.txt` + `features/<code_lower>/<field>.day.bin` (4-byte float32 start_index + float32 array).
81
+ - `loader_factory.get_default_loader()` — reads `config/loaders.yaml` to instantiate the configured default. Sub-agents (`quote-fetcher`, `factor-computer`, `LGBMomentumModel`) use this factory.
82
+ - `config/loaders.yaml` template with both `tushare` (cache) and `qlib_binary` options.
83
+
84
+ ### Changed
85
+ - `TushareLoader` re-implemented using raw `requests.post` (bypasses the `tushare` Python library's round-robin to `api.waditu.com` which times out behind corporate proxies). HTTP only.
86
+ - `quote-fetcher` uses `_safe_float` for `daily_basic` fields (handles None/NaN gracefully for stocks without dividends, etc.).
87
+ - `cli.py` calls `load_dotenv(override=True)` so `.env` overrides shell env vars (fixes Windows user-level TUSHARE_TOKEN conflicts).
88
+ - `llm.client` now explicitly passes `api_key` from per-provider `api_key_env` so LiteLLM doesn't fall back to OPENAI_API_KEY when using qwen/deepseek/etc.
89
+ - `config/llm.yaml` default switched to Qwen (`qwen3.5-plus`) since most users have DashScope keys, not Anthropic.
90
+ - Report writer renders the markdown report inline in terminal (Rich Markdown) and exports a colored HTML copy next to the .md. Clickable `file:///` URL in TUI output.
91
+ - Forced UTF-8 stdout/stderr at module load (cli.py + tui.py) so Windows zh-CN PowerShell doesn't choke on `¥` / emoji / rare CJK.
92
+
93
+ ## v0.2.0 — 2026-05-18
94
+
95
+ ### Added
96
+ - `MemoryIndex` — SQLite FTS5 full-text index over `memories/**/*.md` with CJK tokenization, incremental updates, agent-filtered search.
97
+ - `AgentMemory.load_relevant(query, top_k)` — hybrid retrieval that pulls top-K snippets via FTS5 while always including `_shared/` core rules. Backward-compatible with `load_all()`.
98
+ - Per-agent `memory_mode: full | retrieval` configuration in swarm preset YAML. Defaults to `full` (v0.1 behavior preserved).
99
+ - TUI `/memory` subcommands: `search`, `show`, `edit`, `stats`, `diff`, `reindex` (in addition to existing `list`, `reload`).
100
+ - `bear-advocate` and `risk-officer` opted into retrieval mode by default (biggest memory libraries).
101
+
102
+ ### Changed
103
+ - `SubAgent.__init__` accepts optional `index: Optional[MemoryIndex] = None`.
104
+ - `swarm.load_preset()` accepts `memory_index` parameter; passes through to retrieval-mode agents only.
105
+ - `MemoryIndex.stats()` now includes `total_bytes` and `per_agent_bytes`.
106
+
107
+ ### Token cost impact
108
+ - Single-stock report: ~80K → ~30K tokens (estimated 62% reduction) when both retrieval-mode agents are exercised.
109
+ - Per-report Qwen cost: ~¥0.05 → ~¥0.02.
110
+
111
+ ## v0.1.0 — 2026-05-17
112
+
113
+ ### Initial release
114
+ - 13 sub-agents in 3 trust tiers (5 Tier-1 data fetchers, 4 Tier-2 analysts, 4 Tier-3 decision agents).
115
+ - Pluggable per-agent memory (`memories/<agent>/*.md`) with `_shared/` cross-agent playbook.
116
+ - Tushare data loader, LGB momentum model, LiteLLM multi-provider abstraction.
117
+ - Rich TUI with prompt-toolkit REPL.
118
+ - 100+ pydantic-validated tests, opt-in real E2E test.
@@ -0,0 +1,18 @@
1
+ # Claude Code Working Instructions
2
+
3
+ Multi-agent A-share research workstation. 13 sub-agents in three trust tiers.
4
+
5
+ ## Hard Rules
6
+ - Only `report-writer` has the `write` tool. All others are read-only.
7
+ - Untrusted sources (news, F10) only touch `news-reader` and `f10-reader`. Their output is pydantic-validated JSON.
8
+ - Memory is per-agent under `memories/<agent>/*.md`. Hot-reloadable: edit a markdown → next agent invocation picks it up.
9
+ - LLM is provider-abstracted via LiteLLM. Configure in `config/llm.yaml`.
10
+
11
+ ## Code Style
12
+ - Python 3.11+, type hints, async-first (asyncio.gather for parallel tiers).
13
+ - pydantic v2 for all sub-agent IO.
14
+ - pytest for tests. Mock LLM in unit tests; real LLM only in integration tests under `tests/integration/`.
15
+
16
+ ## Workflow
17
+ - Each task in `docs/superpowers/plans/*.md` should produce exactly one commit.
18
+ - Run `pytest tests/` before each commit.
@@ -0,0 +1,195 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other transformations
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and its derivative works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of tracking and
55
+ discussing modifications to the Work, but excluding communication that
56
+ is conspicuously marked or designated in writing by the copyright owner
57
+ as "Not a Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and included
61
+ within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by the combined work (in which such
78
+ Contribution(s) was submitted). If You institute patent litigation
79
+ against any entity (including a cross-claim or counterclaim in a
80
+ lawsuit) alleging that the Work or any combination of the Work
81
+ constitutes direct or contributory patent infringement, then any
82
+ patent licenses granted to You under this License for that Work
83
+ shall terminate as of the date such litigation is filed.
84
+
85
+ 4. Redistribution. You may reproduce and distribute copies of the
86
+ Work or Derivative Works thereof in any medium, with or without
87
+ modifications, and in Source or Object form, provided that You
88
+ meet the following conditions:
89
+
90
+ (a) You must give any other recipients of the Work or Derivative
91
+ Works a copy of this License; and
92
+
93
+ (b) You must cause any modified files to carry prominent notices
94
+ stating that You changed the files; and
95
+
96
+ (c) You must retain, in the Source form of any Derivative Works
97
+ that You distribute, all copyright, patent, trademark, and
98
+ attribution notices from the Source form of the Work,
99
+ excluding those notices that do not pertain to any part of
100
+ the Derivative Works; and
101
+
102
+ (d) If the Work includes a "NOTICE" text file as part of its
103
+ distribution, You must include a readable copy of the
104
+ attribution notices contained within such NOTICE file, in
105
+ at least one of the following places: within a NOTICE text
106
+ file distributed as part of the Derivative Works; within
107
+ the Source form or documentation, if provided along with the
108
+ Derivative Works; or, within a display generated by the
109
+ Derivative Works, if and wherever such third-party notices
110
+ normally appear. The contents of the NOTICE file are for
111
+ informational purposes only and do not modify the License.
112
+ You may add Your own attribution notices within Derivative
113
+ Works that You distribute, alongside or in addition to the
114
+ NOTICE text from the Work, provided that such additional
115
+ attribution notices cannot be construed as modifying the
116
+ License.
117
+
118
+ You may add Your own license statement for Your modifications and
119
+ may provide additional grant of rights to use, copy, modify, merge,
120
+ publish, distribute, sublicense, and/or sell copies of the Work,
121
+ and to permit persons to whom the Work is furnished to do so,
122
+ subject to the following conditions: you must include the above
123
+ copyright notice and this permission notice in all copies or
124
+ substantial portions of the Work.
125
+
126
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
127
+ any Contribution intentionally submitted for inclusion in the Work
128
+ by You to the Licensor shall be under the terms and conditions of
129
+ this License, without any additional terms or conditions.
130
+ Notwithstanding the above, nothing herein shall supersede or modify
131
+ the terms of any separate license agreement you may have executed
132
+ with Licensor regarding such Contributions.
133
+
134
+ 6. Trademarks. This License does not grant permission to use the trade
135
+ names, trademarks, service marks, or product names of the Licensor,
136
+ except as required for reasonable and customary use in describing the
137
+ origin of the Work and reproducing the content of the NOTICE file.
138
+
139
+ 7. Disclaimer of Warranty. Unless required by applicable law or
140
+ agreed to in writing, Licensor provides the Work (and each
141
+ Contributor provides its Contributions) on an "AS IS" BASIS,
142
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
143
+ implied, including, without limitation, any warranties or conditions
144
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
145
+ PARTICULAR PURPOSE. You are solely responsible for determining the
146
+ appropriateness of using or reproducing the Work and assume any
147
+ risks associated with Your exercise of permissions under this License.
148
+
149
+ 8. Limitation of Liability. In no event and under no legal theory,
150
+ whether in tort (including negligence), contract, or otherwise,
151
+ unless required by applicable law (such as deliberate and grossly
152
+ negligent acts) or agreed to in writing, shall any Contributor be
153
+ liable to You for damages, including any direct, indirect, special,
154
+ incidental, or exemplary damages of any character arising as a
155
+ result of this License or out of the use or inability to use the
156
+ Work (including but not limited to damages for loss of goodwill,
157
+ work stoppage, computer failure or malfunction, or all other
158
+ commercial damages or losses), even if such Contributor has been
159
+ advised of the possibility of such damages.
160
+
161
+ 9. Accepting Warranty or Liability. While redistributing the Work or
162
+ Derivative Works thereof, You may choose to offer, and charge a fee
163
+ for, acceptance of support, warranty, indemnity, or other liability
164
+ obligations and/or rights consistent with this License. However, in
165
+ accepting such obligations, You may offer such obligations only on
166
+ Your own behalf and on Your sole responsibility, not on behalf of
167
+ any other Contributor, and only if You agree to indemnify, defend,
168
+ and hold each Contributor harmless for any liability incurred by,
169
+ or claims asserted against, such Contributor by reason of your
170
+ accepting any warranty or additional liability.
171
+
172
+ END OF TERMS AND CONDITIONS
173
+
174
+ APPENDIX: How to apply the Apache License to your work.
175
+
176
+ To apply the Apache License to your work, attach the following
177
+ boilerplate notice, with the fields enclosed by brackets "[]"
178
+ replaced with your own identifying information. (Don't include
179
+ the brackets!) The text should be enclosed in the appropriate
180
+ comment syntax for the file format in question. It may also be
181
+ a square bracket around a slash like "[/]" for display.
182
+
183
+ Copyright 2026 financial-analyst contributors
184
+
185
+ Licensed under the Apache License, Version 2.0 (the "License");
186
+ you may not use this file except in compliance with the License.
187
+ You may obtain a copy of the License at
188
+
189
+ http://www.apache.org/licenses/LICENSE-2.0
190
+
191
+ Unless required by applicable law or agreed to in writing, software
192
+ distributed under the License is distributed on an "AS IS" BASIS,
193
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
194
+ implied. See the License for the specific language governing
195
+ permissions and limitations under the License.
@@ -0,0 +1,217 @@
1
+ Metadata-Version: 2.4
2
+ Name: financial-analyst
3
+ Version: 0.6.0
4
+ Summary: A-share single-stock deep-dive multi-agent research workstation with three-tier trust isolation, FTS5 memory retrieval, dream loop introspection, and BYOM extensibility.
5
+ Project-URL: Homepage, https://github.com/jesson-hh/financial-analyst
6
+ Project-URL: Repository, https://github.com/jesson-hh/financial-analyst
7
+ Project-URL: Issues, https://github.com/jesson-hh/financial-analyst/issues
8
+ Project-URL: Changelog, https://github.com/jesson-hh/financial-analyst/blob/main/CHANGELOG.md
9
+ Project-URL: Documentation, https://github.com/jesson-hh/financial-analyst/tree/main/docs
10
+ Author-email: jesson-hh <xuyi1030@proton.me>
11
+ Maintainer-email: jesson-hh <xuyi1030@proton.me>
12
+ License: Apache-2.0
13
+ License-File: LICENSE
14
+ Keywords: a-share,ai-agent,claude,fintech,fts5,investment-research,litellm,llm,multi-agent,qlib,quantitative-finance,qwen,stock-research,tushare
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Environment :: Console
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Intended Audience :: Financial and Insurance Industry
19
+ Classifier: License :: OSI Approved :: Apache Software License
20
+ Classifier: Natural Language :: Chinese (Simplified)
21
+ Classifier: Natural Language :: English
22
+ Classifier: Operating System :: OS Independent
23
+ Classifier: Programming Language :: Python :: 3
24
+ Classifier: Programming Language :: Python :: 3 :: Only
25
+ Classifier: Programming Language :: Python :: 3.11
26
+ Classifier: Programming Language :: Python :: 3.12
27
+ Classifier: Topic :: Office/Business :: Financial :: Investment
28
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
29
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
30
+ Requires-Python: >=3.11
31
+ Requires-Dist: anyio>=4
32
+ Requires-Dist: lightgbm>=4
33
+ Requires-Dist: litellm>=1.50
34
+ Requires-Dist: numpy>=1.26
35
+ Requires-Dist: pandas>=2
36
+ Requires-Dist: prompt-toolkit>=3.0
37
+ Requires-Dist: pyarrow>=15
38
+ Requires-Dist: pydantic-settings>=2.1
39
+ Requires-Dist: pydantic>=2.5
40
+ Requires-Dist: pyyaml>=6
41
+ Requires-Dist: rich>=13
42
+ Requires-Dist: tushare>=1.4
43
+ Requires-Dist: typer>=0.12
44
+ Provides-Extra: dev
45
+ Requires-Dist: build>=1.0; extra == 'dev'
46
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
47
+ Requires-Dist: pytest-mock>=3.12; extra == 'dev'
48
+ Requires-Dist: pytest>=8; extra == 'dev'
49
+ Requires-Dist: ruff>=0.5; extra == 'dev'
50
+ Requires-Dist: twine>=5.0; extra == 'dev'
51
+ Description-Content-Type: text/markdown
52
+
53
+ # Financial Analyst
54
+
55
+ [![PyPI](https://img.shields.io/pypi/v/financial-analyst)](https://pypi.org/project/financial-analyst/)
56
+ [![tests](https://img.shields.io/badge/tests-240_passed-brightgreen)](https://github.com/jesson-hh/financial-analyst/actions)
57
+ [![python](https://img.shields.io/badge/python-3.11+-blue)](https://www.python.org/)
58
+ [![license](https://img.shields.io/badge/license-Apache_2.0-green)](LICENSE)
59
+
60
+ **A-share single-stock deep-dive multi-agent research workstation.**
61
+
62
+ **13 sub-agents in three trust tiers** — five Tier-1 data fetchers (two of which read untrusted news/F10 with JSON-schema-locked output), four Tier-2 analysts (fundamental, technical, whale-sentiment, quant), four Tier-3 decision agents (bull, bear, risk officer, report writer). Only the report writer can write files. Memory is pluggable per-agent (`memories/<agent>/*.md`) — edit a markdown, the next report uses it. FTS5-backed retrieval keeps prompt costs ~60% lower than naive full-injection.
63
+
64
+ Inspired by [Anthropic's financial-services](https://github.com/anthropics/financial-services) (3-tier trust isolation, single-writer pattern) and [HKUDS/Vibe-Trading](https://github.com/HKUDS/Vibe-Trading) (YAML swarm presets, multi-provider LLM).
65
+
66
+ ## What's in v0.6
67
+
68
+ - **13 sub-agent DAG** (data → analyst → decision), Qwen/Claude/DeepSeek/Ollama via LiteLLM
69
+ - **QlibBinaryLoader** (day + 5min) + **TushareLoader** (HTTP + ParquetCache) + **CSV ingester**
70
+ - **R7-R20 sentiment signals** (board_scorer v5, volume_regime super_distr/tail_surge, whale signals)
71
+ - **Pluggable memory** with FTS5 retrieval + always_include white-list + `_shared/` cross-agent playbook
72
+ - **Dream loop** — agent self-improving memory (OutcomeTracker + Introspector + `memories/_proposed/` staging + human accept/reject)
73
+ - **BYOM** — registry-based plug-in points for models / loaders / collectors / sub-agents / KBs; `config/plugins.yaml` auto-loads user `.py` files at startup
74
+ - **Markdown + JSON + HTML** output (Rich Markdown rendering + standalone HTML file)
75
+ - **226 tests** unit + integration (mocked LLM)
76
+
77
+ ## Quick Start
78
+
79
+ **One-line install (when v0.6.0 is on PyPI):**
80
+
81
+ ```bash
82
+ pip install financial-analyst
83
+ ```
84
+
85
+ Or **from source** (development):
86
+
87
+ ```bash
88
+ git clone https://github.com/jesson-hh/financial-analyst.git
89
+ cd financial-analyst
90
+ python -m venv .venv && .venv\Scripts\activate # Windows; or `source .venv/bin/activate`
91
+ pip install -e .[dev]
92
+ ```
93
+
94
+ Then:
95
+
96
+ ```bash
97
+ cp .env.example .env
98
+ # Edit .env: set TUSHARE_TOKEN + your LLM provider key (default config uses DASHSCOPE_API_KEY for Qwen)
99
+ financial-analyst # boots TUI
100
+ ```
101
+
102
+ In TUI:
103
+
104
+ ```
105
+ > 看看 600519
106
+ > /ask 我最近研报里 bear 段是不是过激了
107
+ > /agents
108
+ > /memory search 游资
109
+ > /show
110
+ > /dream --since 30
111
+ > /memory list-proposals
112
+ > /quit
113
+ ```
114
+
115
+ One-shot:
116
+
117
+ ```bash
118
+ financial-analyst report SH600519
119
+ financial-analyst ask "SH600519 现在 PE 多少"
120
+ financial-analyst ingest --source my_csv
121
+ financial-analyst dream --since 30
122
+ financial-analyst models list
123
+ ```
124
+
125
+ ## Architecture
126
+
127
+ ```
128
+ Orchestrator → Tier 1 (data, parallel) → Tier 2 (analysts, parallel) → Tier 3 (decision, serial)
129
+ ↓ ↓ ↓
130
+ fetch + factor 4 analysts bull/bear/risk → writer
131
+ + read untrusted consume tier 1 JSON consume tier 2 JSON
132
+ with JSON schemas
133
+ ```
134
+
135
+ See [docs/architecture.md](docs/architecture.md) for the full DAG and trust model.
136
+
137
+ ## Extending — Bring Your Own Models (BYOM)
138
+
139
+ `financial-analyst` is a **framework**, not a fixed product. Plug in your own private models / loaders / collectors:
140
+
141
+ ```python
142
+ # G:/my_private_code/my_fm.py
143
+ from financial_analyst.models import BaseModel, ModelRegistry
144
+
145
+ class MyFMCluster(BaseModel):
146
+ def predict(self, code, asof):
147
+ return {"score": ..., "rank_pct": ..., "cluster": ...}
148
+ def metadata(self):
149
+ return {"name": "my_fm", "version": "W10"}
150
+
151
+ ModelRegistry.register("my_fm", MyFMCluster)
152
+ ```
153
+
154
+ ```yaml
155
+ # config/plugins.yaml
156
+ load_at_startup:
157
+ - G:/my_private_code/my_fm.py
158
+ ```
159
+
160
+ Now `financial-analyst report SH600519` includes your model in the quant consensus. **No proprietary checkpoint enters the open-source repo.**
161
+
162
+ See [docs/byom.md](docs/byom.md) for the full guide. Examples for FM cluster / CSV loader / Tushare news collector / pytdx F10 collector are in [`examples/`](examples/).
163
+
164
+ ## Data Ingestion
165
+
166
+ If you don't have a Qlib data directory, ingest your CSVs:
167
+
168
+ ```yaml
169
+ # config/data_sources.yaml
170
+ sources:
171
+ - name: my_csv
172
+ type: csv
173
+ path: G:/my_data/*.csv
174
+ code_col: ts_code
175
+ date_col: trade_date
176
+ target: ~/.financial-analyst/data/my_csv
177
+ ```
178
+
179
+ ```bash
180
+ financial-analyst ingest --source my_csv
181
+ # Then point config/loaders.yaml `qlib_binary.provider_uri.day` at the target
182
+ ```
183
+
184
+ See [docs/data_ingest.md](docs/data_ingest.md).
185
+
186
+ ## Memory System
187
+
188
+ Each sub-agent has `memories/<agent-name>/` with markdown files. Files are appended to the agent's system prompt at runtime. v0.2+: FTS5 retrieval keeps prompt cost down for agents marked `memory_mode: retrieval`. Critical files listed in `memories/<agent>/always_include.txt` are loaded unconditionally.
189
+
190
+ See [docs/memories.md](docs/memories.md) for principles, file-organization advice, and CLI commands.
191
+
192
+ ## Dream Loop — Agent Self-Improving Memory
193
+
194
+ Run `/dream` (or `financial-analyst dream`) to:
195
+ 1. Score past reports against T+5d / T+20d actual prices.
196
+ 2. Have an introspector sub-agent identify patterns in wrong predictions.
197
+ 3. Stage proposals in `memories/_proposed/<agent>/` for human review.
198
+ 4. `/memory accept` merges; `/memory reject` discards.
199
+
200
+ **Auto-accept is intentionally NOT implemented** — incorrect memory updates compound losses in quant systems. Human review only.
201
+
202
+ See [docs/dream_loop.md](docs/dream_loop.md).
203
+
204
+ ## Tests
205
+
206
+ ```bash
207
+ pytest tests/ # 240 unit + integration tests (mocked)
208
+ FA_E2E=1 pytest tests/integration/test_end_to_end.py # real Tushare + LLM round-trip
209
+ ```
210
+
211
+ ## License
212
+
213
+ Apache 2.0.
214
+
215
+ ## Disclaimer
216
+
217
+ Drafts analyst work product for review by qualified professionals. Does not make investment recommendations, execute transactions, or post to any ledger. You are responsible for compliance with applicable laws and regulations.