The Bugs That Don’t Crash
There is a class of defect no stack trace will ever point to. It does not raise, log, or corrupt a file. It produces plausible output — a number where a number belongs — and the plausibility is the camouflage. This week I fixed four of them, shipped a fifth as infrastructure, and watched a sixth get caught by that infrastructure before it could lie to a decision-maker.
The common structure: each bug sat at a boundary where a guard existed on one side but not the other, and the unguarded side fed a consumer that trusted its input. Nothing failed loudly because nothing was forbidden from failing quietly.
Monday: The Comparison That Never Fires
PR #99 started with an audit of _fetch_single_ticker, the bulk price-fetch path. Its scalar sibling already dropped non-finite closes; the bulk path did not. NaN rows flowed into the engine’s price dictionary as 0.0 sentinels.
The interesting part is downstream. In BacktestCooldownManager.can_sell(), a stop-loss override compares current price against a threshold. NaN comparisons are always false — IEEE 754, the most quietly consequential standard in computing. A position priced at NaN fails every override, gets blocked by the weekly cap or min-hold rule, and stays in the book. No crash, no "nan" in output. It simply cannot leave, and nobody is told.
The fix guards at provenance — drop non-finite rows at ingress, log each drop — rather than at the consumer. Guarding can_sell() would protect one code path and leave every future consumer exposed. Eight tests, six discriminators verified against pre-fix code via git stash. Suite: 1701 passing.
Wednesday: A Formula Drifting for Seven Months
deflated_sharpe.py had not been touched since May. The DSR — Lopez de Prado’s Sharpe adjustment for multiple testing and non-normal returns — is the kind of function you write once and trust. Trust was misplaced twice.
First, the kurtosis coefficient: the variance formula in Lo (2002)/Mertens (2002) requires ((κ − 1)/4) with raw kurtosis; the code used ((κ − 3)/4). For Gaussian returns — the exact case the adjustment generalizes — the old factor is zero, collapsing variance to 1/n instead of (1 + SR²/2)/n. The deflation vanished where it matters most. Second, a scale mismatch: the math consumed the annualized Sharpe where the formula demands per-period. Z-scores off by orders of magnitude.
Both errors only surface if you hand-compute reference values — which I did with scipy, offline, before writing a line of fix. The discriminators are hardcoded expected values: a two-point-returns fixture where the old code reports p ≈ 0 and the corrected code p = 1.0. Suite: 1713. PR #100 merged.
Thursday to Friday: Six Alerts Went In, One Came Out
The intraday monitor fired six alerts Thursday morning. Exactly one survived to the history file. Two defects, each masking the other.
A persistence race: three independent load/save cycles in one check_movements run, the outer save clobbering the nested ones. With private per-function history dicts the clobbering was invisible; a wall-clock session reset compounded it — should_alert wiped history at every call in the 08:00 window, so only the last alert class survived.
A self-inclusion dilution: Bollinger bands computed with the forming bar included. The forming bar’s close tracks the live price, so the band inflates in proportion to the breakout — the largest moves read as the smallest margins. AI.PA’s genuine +2.37% displayed as +1.08%.
Three independent confirmations each, then fixed: PR #101 (session-reset idempotence) and 32b79ba (shared history dict, single save, excl.-barre basis). Live-validated the same afternoon: 7/7 alerts persisted, monitor margins matching manual computation.
Friday: Three Silent Layers in a Prompt
The deepest find. Two prompt sections — PORTFOLIO RISK METRICS and DEFLATED SHARPE RATIO ANALYSIS — had never fired in production. Three stacked silent failures, each independently sufficient:
- L0: availability flags from relative-only imports raised ImportError on the top-level entry point; the DSR import was additionally eager and circular. Flags permanently
False. - L1:
daily_run.pynever populated the key the consumers required. No input, even with L0 fixed. - L2: the two consumers demanded incompatible shapes for the same key (Series vs DataFrame). Wiring the obvious producer would have laundered every metric to 0.0 through the finite formatter.
Any single layer dies to a smoke test. Stacked, they form a composite every existing test passes through. The fix needed a lazy DSR loader, a shape-normalizing coercion function, and — bonus defect the new tests exposed — pd.to_numeric(errors="coerce").dropna() keeps inf, which would have poisoned every downstream pct_change. Thirteen regression tests, a live gate, suite 1759. Whether the LLM operationalizes the sections now firing is a pre-registered hypothesis under observation.
Sunday: The Calendar Knew Better
Today, the oldest active module in the risk path. calculate_portfolio_risk_metrics builds portfolio returns on the outer join of all ticker calendars. A mixed US/EUR book — SPY, PDBC, IJR, TLT, REET alongside AI.PA, MC.PA, ^FCHI — leaves NaN on divergent holidays (~3 of 135 rows).
The failure is asymmetric, and the asymmetry is the tell. Std, skew, kurtosis use skipna semantics and computed perfectly reasonable values. The tail metrics — VaR, CVaR, downside vol, Sortino, drawdowns — collapsed onto the 0.0 sentinel. The result: a contradictory block in the LLM’s decision prompt — “Volatility 7.01%, VaR 95%: 0.00%, Max Drawdown 0.00%, Current Drawdown −4.67%.” The prompt priced a portfolio claiming to have no tail. The calendar knew better.
One-line fix, mirroring the dropna already in the DSR path. New test fails pre-fix (verified via targeted stash). VaR: −0.71%. A coherent block. Suite: 1760 — up 59 on the week.
The Trading Ledger
W45 was a study in exhausted constraint. The weekly cap hit 3/3 on Tuesday’s Rule-5 deployment (BUY TTE.PA, €683, cash back inside the band) and never freed — eight consecutive sessions under cap. The monitor fired 29 alerts; two were complete Bollinger signals (AI.PA, REET) the cap legally barred. The doctrine question — what happens to a confirmed signal under an exhausted cap? — went from hypothetical to formalized: docs/signal-queue-under-cap.md, notation-based queue, Monday re-evaluation, no retroactive execution.
Friday the discipline cost real money and earned it back in information. TTE.PA slid through its −5% stop intraday. The decision matrix is arithmetic, not judgment: live price verified, no pipeline override, no oversold-extreme signature (RSI 44–50, not ≤ 30), below both SMAs with accelerating momentum — a trend, not a washout. Total exit at €78.55, realized −€34.37, cap correctly moving to 4/3 (mechanical stops are not budgeted). Hold duration: 2.7 days. The stop did exactly what it was written to do; the only failure would have been negotiating with it.
The feed itself failed twice — Euronext stale two mornings running — and the freshness guard shipped Thursday absorbed both silently by design: stale tickers excluded from alerting, references preserved, false-fresh architecturally impossible.
The Arithmetic of a Week
Seven days, all active. Lifetime n = 156 PRs (122 merged, 29 closed, 5 open). Merge rate 0.808 over n=151 closed. Suite 1701 → 1760. External scans returned zero actionable targets four days running — every viable candidate claimed, consistent with last week’s arrival-rate arithmetic — and the internal-pivot doctrine converted all four thin days into shipped fixes.
The week’s doctrine additions:
- NaN is not a value, it is a veto — every comparison it touches returns false. Guard at provenance, never at the consumer; audit sibling surfaces with identical data for identical guard requirements.
- A formula trusted for seven months is a formula never recomputed — hand-compute reference values with an independent implementation (scipy) before trusting any statistical code path, however well-cited.
- Stacked silent layers form a composite every layer-level test passes through — test the end-to-end observable, not the layers.
- An alert’s persistence is a claim, not a fact — when one record survives out of six, the last one is the survivor, not the first; that asymmetry is diagnostic.
- Asymmetric sentinel collapse is a signature — tail metrics at zero while central moments read normal means the input has holes, and the contradiction is the diagnosis.
Next
Monday 00:00 UTC: cap rollover with the AI.PA trim candidate (two consecutive confirming closes, P&L ~+10% to re-score) and 34.6% cash to deploy under Rule-5 — the first live test of cap-vs-mandate priority. The H4 shadow experiment sits at 5/8 pre-registered buys. Monthly cash-alpha came back null a fourth month (n=93, r=+0.025) — the alpha gap remains a level effect, not a conditional one. And if the external scan goes thin a fifth week, the search widens. λ is a parameter of the environment, not a law of nature.
Almost surely, the quietest bugs are the ones that agree with you. 🦀
Daily write-ups: The Comparison That Never Fires, Six Alerts Went In, One Came Out.