William Caron-Bastarache
FR EN
Personal Project · Phases A–D complete

Event-Driven Market Probability Engine

A reproducible research pipeline that estimates next-day market move probabilities, validates that estimate under conditions that do not flatter it, and reports the honest conclusion: the model has no tradeable edge.

Summary

A layered PostgreSQL warehouse and a walk-forward-validated probability model, built to answer one question honestly: is there a tradeable edge in next-day ETF moves? The measured answer is no, and reporting that is the point. Most of the engineering exists to make the verdict trustworthy rather than to make it flattering.

Architecture, data engineering, modeling, evaluation
PostgreSQL, Python (asyncio, pandas, psycopg, scikit-learn, matplotlib), SQL window functions, Make, pytest
15 ETFs · 32,295 rows · 2018–2026 · 36 tests · 6 database-level invariants
Phases A–D complete. Calibration next, then event ingestion.

The result

Five expanding walk-forward folds with a 60-day embargo, then a backtest with transaction costs, benchmarked against simply holding the market. No strategy beats the benchmark.

Cumulative return by strategy, each fold backtested separately, against an always-long benchmark
1.48 SharpeHolding the market
Hold all 15 ETFs every day. The benchmark, and the thing to beat. 75 trades.
0.66 SharpeDirectional rule
Go long when the model puts the chance of an up day above 55%, short when it falls below 45%, flat in between. 1,221 trades to underperform doing nothing.
1.22 SharpeVolatility filter
Hold the market, but step aside to cash whenever the model puts the chance of a large move above 10%. Never takes a view on which way. 898 trades.

The finding worth reporting

A real signal that still loses money

Next-day direction has no signal: ROC-AUC ~0.51, straddling chance, exactly as market efficiency predicts for price-only features on liquid ETFs. Large moves are genuinely predictable at ~0.57, in 14 of 15 instruments.

And it still does not convert. The label is unsigned: it knows a big move is coming but not which way, so stepping aside forgoes as much upside as downside. Being right about volatility is not the same as having an edge, and only a backtest could have shown that.

Calibration: ranking is not probability

Reliability diagram: predicted probability against realised frequency, for direction and large moves

The model sorts days correctly but exaggerates the gap: it claims its most turbulent tenth is 5.1x riskier than its calmest, where only 2.6x occurred. A threshold rule needs the ranking to be right; a sizing rule needs the value to be right. This model has the first and not the second.

Errors, and what caught them

Bugs that passed every test

Three of these four went straight through the test suite. In a data pipeline a wrong number looks exactly like a right one, so each failure below is paired with the guard that now fails the build if it comes back.

Tests: missed

One ticker's prices, fifteen times

yf.download() stages results in module-level state and resets it on entry, so concurrent calls overwrite each other's accumulator and every task can receive the same wrong frame. The warehouse ended up holding one ticker's prices under all fifteen symbols.

Nothing failed. A duplicated series is internally consistent, so every per-asset assertion held, row counts were right and no nulls appeared. The only symptom was the model getting better, which is the most dangerous symptom there is.

It was caught by noticing that SHY, a one to three year Treasury fund, reported the same volatility as XLE, an energy fund, to five decimal places.

0.67 AUClarge-move, corrupted
0.59 AUCrecorded baseline
0tests failed

Guard: a cross-asset fingerprint in sql/10_validations.sql hashes each symbol's whole series and rejects any two that match. Every other check in the project validates within one asset; this is the only one that looks across them.

Tests: missed

A day that hadn't ended yet

Yahoo serves the session in progress as an ordinary bar, with a partial close and partial volume. Two rebuilds an hour apart disagreed, and one label per asset was measured against a close that had not happened.

Guard: only settled sessions are ingested. The rule keys on the calendar date rather than on whether 16:00 has passed, because a time-of-day rule would make a 15:00 run and a 17:00 run disagree, which is the non-determinism being fixed.

Tests: missed

A ticker that quietly disappeared

Each fetch is wrapped so one bad symbol cannot abort the batch, which makes a failed download survivable and therefore silent. The asset still arrives with zero price rows, and zero rows satisfy every row-level check vacuously. Fifteen instruments could become fourteen with every metric still reporting cleanly.

Guard: every symbol declared in config/assets.csv must have at least one price row.

Found writing tests

Drawdown that started too late

Drawdown compares equity to the highest equity so far. The running peak started at day one's close instead of the starting capital, so day one's own loss was never counted. Start at 100, fall 10%, recover 2%: the peak becomes 90 and the reported drawdown is 0% rather than 10%.

Each of the five walk-forward folds is backtested separately, so each had its own day one. The error only ever ran one way, making strategies look safer than they were.

Guard: the running peak is floored at the starting capital, pinned by a case in tests/test_backtest.py with a hand-computed answer.

Full write-up in the README →

How it is built

Data flows one way through three schemas: raw as ingested, staging cleaned and re-keyed onto surrogate ids, analytics for features, labels, predictions and backtest results. A validation gate between raw and staging fails the build on bad input before it can reach a feature.
Features may only read data at or before t, using trailing-only window frames. Forward-looking values live in a separate table, and assertions recompute each stored value from its definition, failing the build when the two disagree.
Walk-forward expanding folds, never a random split, with a 60-day purge and embargo matched to the longest feature lookback so no test row's rolling window can reach into training data.
Stage order is declared as Make dependencies and every stage recomputes its own outputs, so a full rebuild is the normal path. Every figure on this page is generated from the warehouse, never exported by hand.
The event layer is not built yet, deliberately. An event feature is only worth something if you can measure what it adds, and that needs an honest baseline to measure against. This is that baseline. Events are intended to come from a separate agent system extracting structured, timestamped facts from FOMC statements and macro releases.

Contact Me

Interested in this project? Write me.