Skip to content

fix(agent_loop): Bayesian likelihoods + trading-day horizons + debate de-risk (P2.2–P2.4)#61

Merged
Jcstack merged 2 commits into
mainfrom
fix/p2-correctness
Jun 26, 2026
Merged

fix(agent_loop): Bayesian likelihoods + trading-day horizons + debate de-risk (P2.2–P2.4)#61
Jcstack merged 2 commits into
mainfrom
fix/p2-correctness

Conversation

@Jcstack

@Jcstack Jcstack commented Jun 25, 2026

Copy link
Copy Markdown
Owner

Closes #54, closes #55, closes #56.

#54 — fix the Bayesian likelihood derivation

OutcomeTracker.get_calibration_data 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 only holds for posteriors. Replaced with genuine conditional frequencies: the realized state is reconstructed per signal from direction × correctness, and P(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 uses TradingCalendar (N sessions, with a calendar-day fallback) and gates each horizon on target session ≤ today. Adds the first dedicated OutcomeTracker unit 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

ruff clean; 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.

…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
Jcstack enabled auto-merge (squash) June 25, 2026 17:02
Comment thread src/agent_loop/decision_pipeline.py
Comment thread src/agent_loop/decision_pipeline.py
@Jcstack
Jcstack merged commit 56992bf into main Jun 26, 2026
6 checks passed
@Jcstack
Jcstack deleted the fix/p2-correctness branch June 26, 2026 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants