← Back to HMM Trader

Lesson 01

Returns & Price Math

Financial models don't operate on raw prices — they operate on returns. Understanding why, and the difference between arithmetic and log returns, is the first step in quantitative finance.

Why returns, not prices?

Raw prices are non-stationary — Bitcoin at $30,000 vs $60,000 tells you nothing comparable. A $1,000 move means 3.3% in one case and 1.7% in another. Returns normalise these comparisons and make the data suitable for statistical modelling.

Non-stationarity problem. Statistical models (including HMMs) assume the data's statistical properties don't change over time. Prices trend upward indefinitely. Returns fluctuate around a stable mean — they're approximately stationary.
Price (synthetic random walk)
Mean
Std Dev
Min / Max

The formulas

Arithmetic return: rt = (Pt − Pt-1) / Pt-1
Log return: rt = ln(Pt / Pt-1)
Approximation: ln(1 + r) ≈ r   for small r
Why ln(Pn/P0) = Σ ln(Pt/Pt-1)
Step 1 — The key log property
ln(a · b) = ln(a) + ln(b)
Logarithm converts multiplication into addition. This is the only fact you need.
Step 2 — Rewrite the ratio as a product (telescoping)
Pn/P0  =  Pn/Pn−1  ·  Pn−1/Pn−2  ·  ···  ·  P1/P0
Every intermediate price appears once in a numerator and once in a denominator — they cancel out, leaving only Pn and P0.
Step 3 — Apply the log property to the product
ln(Pn/P0)  =  ln(Pn/Pn−1) + ln(Pn−1/Pn−2) + ··· + ln(P1/P0)
                =  Σ ln(Pt/Pt−1)
Each term is one period's log return. The total log return is just their sum.
Why arithmetic returns don't add
+5% then −5%  ≠  0%
(1 + 0.05)(1 − 0.05) − 1 = −0.25%   small but real loss

ln(1.05) + ln(0.95) = 0.0488 − 0.0513 = −0.0025   log returns give the same answer, correctly
Practical payoff: Because log returns add, you can sum any window of hourly bars to get the exact log return for that period, average them across assets, and run standard linear statistics — all without worrying about the order of multiplication.
Arithmetic returns compound multiplicatively. Total return = Π(1 + rt) − 1. Leverage and compounding effects require arithmetic returns for accurate P&L calculation.
Which to use? HMMs and statistical models typically use log returns for their additive property and near-symmetry. P&L calculations use arithmetic returns. Our system uses arithmetic returns for feature engineering (log returns add minimal benefit at hourly resolution) but log returns are standard in academic literature.

The return distribution

Plot a histogram of returns and you see something that looks almost like a bell curve — but not quite. Financial returns have "fat tails": extreme moves happen more often than a pure Gaussian predicts. This is why the HMM uses 7 states rather than 1 — different states capture different parts of this complex distribution.

Why 7 states — and not 1, or 12?
Why not 1 state?
A single Gaussian fits one μ and one σ to everything. It cannot distinguish a quiet accumulation day from a panic crash — both get averaged together. The model becomes blind to regime.
One state = "the market is always the same kind of thing." Clearly wrong.
What the 7 states actually represent
The HMM doesn't receive state labels — it discovers clusters in the data. After training, we inspect the mean return of each state and name them. A typical 7-state fit on BTC finds roughly:
State Astrong bull — high positive μ, moderate σ State Bweak bull — small positive μ, low σ State Cranging / accumulation — μ ≈ 0, low σ State Dchoppy / high noise — μ ≈ 0, high σ State Eweak bear — small negative μ State Fstrong bear — large negative μ, high σ State Gcrash / capitulation — extreme negative μ, very high σ
The exact split varies with each training run and dataset. Auto-labelling ranks by mean return and calls the top state "Bull Run", the bottom "Bear/Crash", and the rest "Chop/Noise".
Why not 12 states?
More states = more parameters to estimate. Each state needs its own 3-element mean vector and 3×3 covariance matrix — 12 parameters per state. At 12 states that's 144 parameters from ~17,000 bars. The model starts fitting noise rather than genuine regime structure, a problem called overfitting.

The practical test: adding states beyond 7–8 produces states that are rarely visited (< 1% of bars) and whose Gaussians overlap heavily with neighbours. They add complexity without adding predictive signal. Rule of thumb: n_states × 12 parameters ≪ n_samples. At 17,000 bars, 7 states (84 params) is well-supported; 20+ states would not be.
7 is a balance, not a magic number. It gives enough granularity to separate strong trends from weak trends from noise from crashes, without demanding more data than hourly BTC history can reliably provide. The dashboard lets you change it — try 5 for simpler regimes, 9 for finer detail.
Histogram of returns
Returns over time
Volatility clustering. Notice how large returns cluster together — periods of high volatility are followed by more high volatility. This is one of the most robust facts in financial data, and exactly the kind of structure HMMs are designed to capture.