Skip to content

refactor(intelligence): merge the two causal-chain engines into one (P1.2)#67

Merged
Jcstack merged 1 commit into
mainfrom
refactor/p1-merge-causal-chains
Jun 26, 2026
Merged

refactor(intelligence): merge the two causal-chain engines into one (P1.2)#67
Jcstack merged 1 commit into
mainfrom
refactor/p1-merge-causal-chains

Conversation

@Jcstack

@Jcstack Jcstack commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Closes #48. Two parallel engines existed: ImpactChainEngine (in-code templates, substring match) and CausalChainConstructor/EventImpactEngine (YAML templates, regex + LLM fallback). The latter is canonical (it drives the core trading pipeline). This makes ImpactChainEngine a thin adapter over CausalChainConstructor — one engine — while preserving its public API.

How

  • impact_chain.py: ImpactChainEngine delegates to CausalChainConstructor; build_chain bridges CausalChainImpactChain (bullish→positive, confidence→magnitude, order→lag). The old CHAIN_TEMPLATES is kept only to build a sector→stock map that re-binds affected_stocks — because Engine B resolves sectors only — so find_stock_impact keeps working (this was the silent-regression trap; it's defused + tested). Engine B + its callers (aggregator / investment_director / trading_loop) are untouched.
  • config/impact_chain_templates.yaml: added usd_strengthen/usd_weaken so USD→gold (the one capability the in-code engine had that the YAML lacked) is preserved — the merge is lossless.
  • tests: test_impact_chain.py rewritten to the new contract (incl. a test proving find_stock_impact returns stock-level impacts); test_usd_affects_gold restored.

Verified

Full unit suite 3811 passed; ruff clean; intelligence sweep 234 green. detect_event_type is now single-match (documented semantic shift; no caller relied on multi-match). Simulation-only; not investment advice.

Closes #48 (P1.2). There were two parallel engines: ImpactChainEngine
(in-code templates, substring match) and CausalChainConstructor/EventImpactEngine
(YAML templates, regex + LLM fallback). The latter is canonical (core trading
pipeline). Make ImpactChainEngine a thin ADAPTER over CausalChainConstructor so
there is one chain-construction engine, preserving its public API.

- impact_chain.py: ImpactChainEngine now delegates to CausalChainConstructor.
  build_chain() bridges CausalChain→ImpactChain (bullish→positive, confidence→
  magnitude, order→lag). CHAIN_TEMPLATES is retained ONLY to build a
  sector→stock map that re-binds affected_stocks (Engine B resolves sectors
  only) — so find_stock_impact keeps working. Engine B and its callers
  (aggregator/investment_director/trading_loop) are untouched.
- config/impact_chain_templates.yaml: add usd_strengthen / usd_weaken templates
  so USD→gold transmission (the one capability the in-code engine had and the
  YAML lacked) is preserved — making the merge lossless.
- tests: rewrite test_impact_chain.py to the new contract (incl. a test proving
  find_stock_impact returns stock-level impacts); restore test_usd_affects_gold.

Verified: full unit suite 3811 passed; ruff clean. detect_event_type is now
single-match (documented semantic shift; no caller depended on multi-match).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Jcstack
Jcstack merged commit 8d2cfcc into main Jun 26, 2026
6 checks passed
@Jcstack
Jcstack deleted the refactor/p1-merge-causal-chains branch June 26, 2026 13:12
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.

[P1.2] Two parallel causal-chain engines in production — merge

1 participant