fix(agent_loop): Bayesian likelihoods + trading-day horizons + debate de-risk (P2.2–P2.4)#61
Merged
Conversation
…debate de-risk Closes #54, #55, #56 (P2.2, P2.3, P2.4). #54 — Bayesian likelihood derivation. get_calibration_data previously set P(signal|bull) = hit-rate and P(signal|bear) = 1 - hit-rate, conflating a posterior (accuracy) with a likelihood and asserting a complementarity that does not hold for likelihoods. Replace with genuine conditional frequencies: reconstruct the realized state per signal from (direction × correctness) and estimate P(bullish reading | bull) and P(bullish reading | bear) as Laplace-smoothed counts. They are real likelihoods (need not sum to 1); the engine's log(p_bull/p_bear) is now positive only for genuinely informative sources. #55 — T+1/T+3/T+5 horizons used timedelta(days=N) (calendar days), so a T+1 lookup after a Friday landed on a non-trading Saturday. Switch to trading-day arithmetic via TradingCalendar (with a calendar-day fallback) and gate each horizon on "target session <= today". Adds the first dedicated OutcomeTracker unit test (the feedback heart was only covered indirectly). #56 — the pipeline hard-refused buys when the LLM debate was unavailable, so live decision quality rested entirely on an unvalidated oracle. Add an opt-in allow_degraded_buys (default OFF — behavior-preserving) that lets the deterministic stack issue a damped buy off the Bayesian prescreen, so a missing/failed debate degrades gracefully instead of silently dropping signals. ruff clean; 382 agent_loop/bayesian/decision/outcome tests green (incl. 8 new). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Jcstack
enabled auto-merge (squash)
June 25, 2026 17:02
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.
Closes #54, closes #55, closes #56.
#54 — fix the Bayesian likelihood derivation
OutcomeTracker.get_calibration_datasetP(signal|bull) = hit-rateandP(signal|bear) = 1 − hit-rate— conflating a posterior (accuracy) with a likelihood, and asserting a complementarity that only holds for posteriors. Replaced with genuine conditional frequencies: the realized state is reconstructed per signal fromdirection × correctness, andP(bullish reading | bull)/P(bullish reading | bear)are estimated as Laplace-smoothed counts. They are real likelihoods (need not sum to 1);log(p_bull/p_bear)is now positive only for genuinely informative sources.#55 — trading-day T+N horizons
t1/t3/t5 = created_at + timedelta(days=N)used calendar days, so a T+1 lookup after a Friday landed on a non-trading Saturday. Now usesTradingCalendar(N sessions, with a calendar-day fallback) and gates each horizon on target session ≤ today. Adds the first dedicatedOutcomeTrackerunit test (the feedback heart was only covered indirectly).#56 — de-risk the LLM-debate dependency
The pipeline hard-refused buys when the debate engine was unavailable, so live decision quality rested entirely on an unvalidated oracle. Added opt-in
allow_degraded_buys(default OFF — behavior-preserving): when enabled, the deterministic stack issues a damped buy off the Bayesian prescreen, so a missing/failed debate degrades gracefully instead of silently dropping signals.Verified
ruffclean; 382 agent_loop / bayesian / decision / outcome / execution tests green, including 8 new (3 likelihood-correctness, 2 trading-day, 3 degraded-buy).Simulation-only project; not investment advice.