feat(observation): wire real 7-day policy-impact baseline from narrative archive#14
Merged
Merged
Conversation
…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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
The "本日观察" section's
对比近 7 日context lines were anchored on hand-tuned constants, behind aload_recent_history()hook that always returnedNoneand 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'scache/alt_data/narrative_history.jsonl, regex-extracting the policy-radaravg_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 existingSOURCE_REPO_DIRSconvention; 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)
policy_impactis 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 fromload_recent_history).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, theresolve_baselinefallback seam, and observation integration (real mean when history present, constant fallback when absent). Written test-first.ruff checkclean🤖 Generated with Claude Code