Step 1 of 7, notebook 01_data
Prices and daily returns
Load 3,044 daily Bitcoin prices from Coin Metrics and turn them into daily returns. Every later number starts from this one column.
The return on the selected day
Click any line to see what it does. The tabs above hold the other cells of this step.
Output
3044 2017-09-01 00:00:00 2025-12-31 00:00:00 0
Output
0.0012212869405938628 0.0341958520865199 -0.3753495151221997 2020-03-12 00:00:00
Output

Cell 3, line 1
btc["ret"] = btc["price"].pct_change()
The daily return: today’s price divided by yesterday’s, minus 1. pct_change does this for every day at once. The very first day has no yesterday, so it is empty.
Step 2 of 7, notebook 02_stats
Risk statistics
Grow 1 USD with the daily returns, measure how far it fell from its peak, and summarise the risk: volatility, drawdown, value at risk and fat tails.
Recomputed in your browser. For 2018 to 2025 these match the notebook output exactly.
Drawdown: how far 1 USD is below its highest value so far
Click any line to see what it does. The tabs above hold the other cells of this step.
Output
annual vol 0.6533 CAGR 0.2582 max drawdown -0.8138 VaR 95% 0.0522 CVaR 95% 0.0793 skew -0.2851 excess kurtosis 8.1945 dtype: float64
Output

Output
0.025631074606433952
Cell 2, line 2
dd = wealth / wealth.cummax() - 1 # drawdown: distance below the highest point so far
Drawdown: how far wealth is below its highest point so far. cummax is the running peak; −0.30 means 30% below the peak.
Step 3 of 7, notebook 03_momentum, cells 1–2
Momentum signal, lined up with tomorrow
Today's 30-day momentum and volatility are used to predict tomorrow's return. The shift(-1) is what keeps the test honest: drop it and the regression looks brilliant.
One row of the regression table, for the selected day
Momentum t-statistic (HAC, 30 lags)
Training years 2018–2021, 1,461 days; the scatter shows every third day.
Click any line to see what it does. The tabs above hold the other cells of this step.
Output
1461
Output
const 0.00029 mom 0.00194 vol 0.03414 dtype: float64 const 0.09 mom 0.46 vol 0.43 dtype: float64 0.00026021003869713955
Cell 1, line 9
"y": r.shift(-1), # tomorrow's return (the thing we predict)
y is tomorrow’s return, the thing we try to predict. shift(−1) moves every value up one row, so each row holds the next day’s return. This one line prevents look-ahead bias.
Step 4 of 7, notebook 03_momentum, cells 3–5
Out-of-sample test
From 2022 on, refit the model every day using only the past, forecast tomorrow, and compare with a plain benchmark: the average return so far. R² out of sample above 0 means momentum beat the benchmark.
The forecast made on the selected day
R² out of sample, adding one day at a time from 1 Jan 2022
Validation 2022–23
0.009%
Clark–West t = 0.42
Test 2024–25
−0.017%
Clark–West t = 0.19
Both are close to zero and the t-values are far below 1.65, so momentum does not predict Bitcoin's daily return.
Click any line to see what it does. The tabs above hold the other cells of this step.
Output
1460
Output
validation 2022-23: (np.float64(0.009), np.float64(0.42)) test 2024-25: (np.float64(-0.017), np.float64(0.19))
Cell 3, line 4
past = data.loc[:t].iloc[:-1] # rows before today: their "tomorrow" is already known
All rows before today. Their “tomorrow” has already happened, so the model learns only from the past: an expanding window.
Step 5 of 7, notebook 04_volatility
Volatility forecasts
Two ways to forecast tomorrow's risk: the average of the last 30 squared returns, or EWMA, which keeps most of yesterday's estimate and mixes in today's news. QLIKE scores each forecast; lower is better. A GARCH model is added as a check.
Forecast volatility around the FTX collapse, annualised
The notebook chose λ = 0.97 on the validation years, then tested it once on 2024–25: Diebold–Mariano t = 2.45, so EWMA is the better forecast.
* Added afterwards as a robustness check (cell 6), with scores taken from the notebook. GARCH is no better than EWMA (Diebold–Mariano t = 0.17). Its fitted α + β ≈ 1 gives it the same structure as EWMA, but around FTX it jumps higher and fades faster, because it weights the newest shock more (α = 0.07 against 0.03).
The EWMA update on the selected day
Click any line to see what it does. The tabs above hold the other cells of this step.
Output
rolling -5.9977 0.9 -6.0395 0.94 -6.0922 0.97 -6.1351
Output
QLIKE rolling: -6.3612 EWMA: -6.4104 DM t: 2.45
Output

Output
omega 0.104 alpha[1] 0.071 beta[1] 0.929 nu 3.331 Name: params, dtype: float64 validation: -6.1367 test QLIKE GARCH: -6.4065 EWMA: -6.4104 DM t: 0.17 GARCH vs rolling, DM t: 1.35 days scored: 730

Cell 2, line 7
v = lam * v + (1 - lam) * x**2 # keep λ of the old belief, mix in (1-λ) of today's news
The EWMA update: keep λ of the old forecast and add (1 − λ) of today’s squared return. With λ = 0.97, each older day counts 3% less, so a shock fades gradually.
Step 6 of 7, notebook 05_strategy, cells 1–6
Strategy backtest
Volatility targeting holds 30% ÷ forecast volatility in Bitcoin, at most 100%, and the rest in T-bills. It is compared with buy-and-hold and with a fixed 39.1% mix, after trading costs.
Volatility targeting on the selected day
Test years 2024–25
Growth of 1 USD, 2024–25, log scale
1 bp is 0.01%: 25 bp means paying 0.25% of whatever is traded.
Click any line to see what it does. The tabs above hold the other cells of this step.
Output
0.391 0.666
Output
buy&hold fixed mix vol target CAGR 0.439 0.212 0.270 vol 0.478 0.187 0.306 Sharpe 0.907 0.886 0.788 max DD -0.321 -0.135 -0.270 turnover/yr 0.000 1.557 4.176 avg weight 1.000 0.391 0.666
Output
10 bp: {'buy&hold': np.float64(0.907), 'fixed mix': np.float64(0.898), 'vol target': np.float64(0.808)}
50 bp: {'buy&hold': np.float64(0.907), 'fixed mix': np.float64(0.865), 'vol target': np.float64(0.754)}
2022-25: {'buy&hold': np.float64(0.488), 'fixed mix': np.float64(0.468), 'vol target': np.float64(0.556)} Output

Cell 3, line 6
gross = w * r[t] + (1 - w) * rf[t] # BTC part + cash part
Gross return: weight × Bitcoin return + (1 − weight) × T-bill return.
Step 7 of 7, notebook 05_strategy, cells 7–9
Robustness
Is the gap between volatility targeting and the fixed mix real, or luck? Check other settings, each year on its own, and a block bootstrap of the Sharpe difference.
Sharpe ratio by year (25 bp costs)
Block bootstrap: 5,000 reshuffled histories of 2024–25 in 20-day blocks
Your browser's random numbers differ from NumPy's, so the interval can differ from the notebook's [−0.30, 0.10] in the second decimal.
Click any line to see what it does. The tabs above hold the other cells of this step.
Output
vol target fixed mix base 0.788 0.886 λ 0.94 0.770 0.886 λ 0.98 0.790 0.886 target 25% 0.782 0.884 target 35% 0.804 0.888 2-day delay 0.759 0.886
Output
2022 {'buy&hold': np.float64(-1.33), 'fixed mix': np.float64(-1.35), 'vol target': np.float64(-1.49)}
2023 {'buy&hold': np.float64(2.25), 'fixed mix': np.float64(2.23), 'vol target': np.float64(2.13)}
2024 {'buy&hold': np.float64(1.67), 'fixed mix': np.float64(1.65), 'vol target': np.float64(1.74)}
2025 {'buy&hold': np.float64(-0.04), 'fixed mix': np.float64(-0.06), 'vol target': np.float64(-0.21)} Output
-0.098 [-0.3 0.1]
Cell 9, line 7
for _ in range(5000): # 5,000 "alternative histories"
Repeats the experiment 5,000 times. Each repeat builds one alternative history of 2024–25 out of reshuffled 20-day blocks of the real days, then measures the Sharpe gap in it.