|
| 1 | +# Numerical Analysis |
| 2 | + |
| 3 | +Languages: English | [中文](zh/numerical-analysis.md) |
| 4 | + |
| 5 | +The numerical analysis module summarizes structured evidence retrieved by FinSight. It is implemented mainly in `query_intelligence/retrieval/market_analyzer.py` and exposed through `retrieval_result.analysis_summary`. |
| 6 | + |
| 7 | +This module supports explanation and evidence readiness. It does not produce deterministic buy/sell decisions. |
| 8 | + |
| 9 | +## Inputs |
| 10 | + |
| 11 | +Numerical analysis consumes structured rows already selected by retrieval: |
| 12 | + |
| 13 | +| Input | Typical source | Use | |
| 14 | +|---|---|---| |
| 15 | +| Price and quote history | `market_api`, Tushare, AKShare, efinance, seed data | Returns, moving averages, volatility, RSI, MACD, Bollinger bands. | |
| 16 | +| Fundamentals | `fundamental_sql`, Tushare, local structured rows | Profitability, valuation, ROE, PE/PB, data completeness. | |
| 17 | +| Industry context | `industry_sql` | Sector identity and sector-level context. | |
| 18 | +| Macro indicators | `macro_sql`, `macro_indicator`, `policy_event` | CPI, PMI, M2, treasury yields, policy-event direction. | |
| 19 | +| Fund/index rows | `fund_nav`, `fund_fee`, `index_daily`, `index_valuation` | NAV, fee, redemption, index trend and valuation evidence. | |
| 20 | + |
| 21 | +The module uses the resolved entity, source plan, retrieved structured rows, and NLU intent/topic hints. It does not re-run NLU. |
| 22 | + |
| 23 | +## Output |
| 24 | + |
| 25 | +`analysis_summary` is a compact object designed for downstream modules: |
| 26 | + |
| 27 | +```text |
| 28 | +analysis_summary |
| 29 | +├── market_signal |
| 30 | +│ ├── trend_signal |
| 31 | +│ ├── pct_change_nd |
| 32 | +│ ├── ma5 / ma20 |
| 33 | +│ ├── rsi_14 |
| 34 | +│ ├── macd |
| 35 | +│ ├── bollinger |
| 36 | +│ └── volatility_20d |
| 37 | +├── fundamental_signal |
| 38 | +│ ├── pe_ttm / pb / roe |
| 39 | +│ ├── valuation_assessment |
| 40 | +│ └── available_fields |
| 41 | +├── macro_signal |
| 42 | +│ ├── indicators[] |
| 43 | +│ └── overall |
| 44 | +└── data_readiness |
| 45 | + ├── has_price_data |
| 46 | + ├── has_fundamentals |
| 47 | + ├── has_macro |
| 48 | + ├── has_news |
| 49 | + ├── has_technical_indicators |
| 50 | + ├── relevant_intents |
| 51 | + └── relevant_topics |
| 52 | +``` |
| 53 | + |
| 54 | +## Indicator Meaning |
| 55 | + |
| 56 | +| Signal | Meaning | |
| 57 | +|---|---| |
| 58 | +| `trend_signal` | Directional description inferred from recent price and moving-average context. | |
| 59 | +| `pct_change_nd` | Recent percentage return over available windows. | |
| 60 | +| `ma5`, `ma20` | Short and medium moving averages when enough price history exists. | |
| 61 | +| `rsi_14` | Momentum indicator. Extreme values should be treated as context, not a standalone trading rule. | |
| 62 | +| `macd` | Trend and momentum signal derived from exponential moving averages. | |
| 63 | +| `bollinger` | Price position relative to recent volatility bands. | |
| 64 | +| `volatility_20d` | Recent realized volatility. | |
| 65 | +| `valuation_assessment` | Lightweight valuation interpretation based on available PE/PB/fundamental rows. | |
| 66 | +| `data_readiness` | Flags that tell downstream modules whether enough evidence exists for a reliable explanation. | |
| 67 | + |
| 68 | +## Design Rules |
| 69 | + |
| 70 | +- Use only structured evidence already retrieved by FinSight. |
| 71 | +- Keep calculations explainable and inspectable. |
| 72 | +- Preserve missing-data warnings instead of filling unsupported facts. |
| 73 | +- Treat indicators as descriptive signals, not trading instructions. |
| 74 | +- Keep downstream LLM prompts compact by passing summarized fields, not raw provider dumps. |
| 75 | + |
| 76 | +## Related Tests |
| 77 | + |
| 78 | +```bash |
| 79 | +python -m pytest tests/test_analysis_summary.py tests/test_market_analyzer.py -q |
| 80 | +``` |
| 81 | + |
| 82 | +## Related Documentation |
| 83 | + |
| 84 | +- [Query Intelligence](query-intelligence.md) |
| 85 | +- [LLM Response Handoff](llm-response.md) |
| 86 | +- [Training and Runtime Assets](training.md) |
0 commit comments