Skip to content

feat(observation): wire real 7-day policy-impact baseline from narrative archive#14

Merged
Leonard-Don merged 1 commit into
mainfrom
feat/v0.3-real-baseline
May 29, 2026
Merged

feat(observation): wire real 7-day policy-impact baseline from narrative archive#14
Leonard-Don merged 1 commit into
mainfrom
feat/v0.3-real-baseline

Conversation

@Leonard-Don
Copy link
Copy Markdown
Owner

What & why

The "本日观察" section's 对比近 7 日 context lines were anchored on hand-tuned constants, behind a load_recent_history() hook that always returned None and a docstring promising "v0.3 will wire the real super-pricing archive." That v0.3 work never landed — so the code's self-description didn't match reality. This PR implements it.

Changes

  • baseline.load_recent_history() now reads super-pricing's cache/alt_data/narrative_history.jsonl, regex-extracting the policy-radar avg_impact (it lives in the entry prose, e.g. avg_impact=-0.35) from the last 7 signal-bearing entries → {"policy_impact_7d": [...]} (|avg_impact|, oldest→newest).
  • baseline.resolve_baseline() — new helper that reduces a metric series to its mean, with per-metric fallback to the constant. Single graceful-degradation seam.
  • observation.synthesize_observation() resolves baselines once (_Baselines.from_history) and threads them through the candidate builders. The policy context line now shows the real rolling mean instead of a frozen constant.
  • config.narrative_history_path() — resolves the archive path via the existing SOURCE_REPO_DIRS convention; overridable for tests.

Real-data check

On the current archive the policy-impact baseline resolves to 0.25 (vs the old hard-coded 0.18).

Scope / caveats (by design)

  • Only policy_impact is archive-backed. The narrative archive does not expose per-day metal-spread / ETF-NAV / industry-heat numerics, so those three baselines keep constant-fallback. Adding one later is a one-line change (return the new key from load_recent_history).
  • The narrative archive is a local runtime cache (not committed; absent in CI and fresh clones), so those runs fall back to constants — consistent with the existing super-pricing adapter's local-first design.
  • ⚠️ Heads-up (pre-existing, not changed here): SOURCE_REPO_DIRS["super_pricing"] points at ~/PycharmProjects/super-pricing-system. On machines where the repo lives elsewhere, the archive won't resolve and the baseline falls back to the constant — same path assumption the adapter already makes.

Tests

Adds tests/test_baseline_history.py (11 tests): reader extraction/filtering/limit/missing-file/malformed-line, the resolve_baseline fallback seam, and observation integration (real mean when history present, constant fallback when absent). Written test-first.

  • ✅ Full suite 327 passed, 3 skipped
  • ruff check clean

🤖 Generated with Claude Code

…ive archive

The v0.2 observation section anchored its "对比近 7 日" context lines on
hand-tuned constants, behind a `load_recent_history()` hook that always
returned None and a docstring promising "v0.3 will wire the real archive".
This lands that v0.3 work so the code matches its own contract.

- `baseline.load_recent_history()` now reads super-pricing's
  `cache/alt_data/narrative_history.jsonl`, regex-extracting the policy-radar
  `avg_impact` from the last 7 signal-bearing entries → `{"policy_impact_7d": [...]}`.
- `baseline.resolve_baseline()` reduces a metric series to its mean with
  per-metric fallback to the constants (single graceful-degradation seam).
- `observation.synthesize_observation()` resolves baselines once and threads
  them through the candidate builders; the policy context line now shows the
  real rolling mean (0.25 on the current archive vs the old 0.18 constant).

Scope/caveats:
- Only `policy_impact` is archive-backed; metal-spread / ETF-NAV / industry-heat
  numerics aren't in the narrative archive, so they keep constant-fallback.
- The archive is a local runtime cache (absent in CI / fresh clones), so those
  runs fall back to constants — consistent with the existing adapter's design.

Tests: adds tests/test_baseline_history.py (11 tests; reader, fallback seam,
observation integration). Full suite 327 passed, ruff clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Leonard-Don Leonard-Don merged commit f04bb93 into main May 29, 2026
2 checks passed
@Leonard-Don Leonard-Don deleted the feat/v0.3-real-baseline branch May 29, 2026 06:26
Leonard-Don added a commit that referenced this pull request May 29, 2026
…ive archive (#14)

The v0.2 observation section anchored its "对比近 7 日" context lines on
hand-tuned constants, behind a `load_recent_history()` hook that always
returned None and a docstring promising "v0.3 will wire the real archive".
This lands that v0.3 work so the code matches its own contract.

- `baseline.load_recent_history()` now reads super-pricing's
  `cache/alt_data/narrative_history.jsonl`, regex-extracting the policy-radar
  `avg_impact` from the last 7 signal-bearing entries → `{"policy_impact_7d": [...]}`.
- `baseline.resolve_baseline()` reduces a metric series to its mean with
  per-metric fallback to the constants (single graceful-degradation seam).
- `observation.synthesize_observation()` resolves baselines once and threads
  them through the candidate builders; the policy context line now shows the
  real rolling mean (0.25 on the current archive vs the old 0.18 constant).

Scope/caveats:
- Only `policy_impact` is archive-backed; metal-spread / ETF-NAV / industry-heat
  numerics aren't in the narrative archive, so they keep constant-fallback.
- The archive is a local runtime cache (absent in CI / fresh clones), so those
  runs fall back to constants — consistent with the existing adapter's design.

Tests: adds tests/test_baseline_history.py (11 tests; reader, fallback seam,
observation integration). Full suite 327 passed, ruff clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant