---
title: "Can you beat a random walk at FX forecasting? Run the test in 30 lines"
description: "The classic result says a \"no change\" forecast beats every model out of sample. Here is the code to put that to the test yourself, against live daily rates."
canonical: "https://exchangerate.dev/learn/beat-the-random-walk-fx-forecasting"
---

# Can you beat a random walk at FX forecasting? Run the test in 30 lines

The classic result says a "no change" forecast beats every model out of sample. Here is the code to put that to the test yourself, against live daily rates.

6 Jul 2026 · 7 min read

The bar any exchange-rate forecast has to clear is the **random walk**: the do-nothing forecast that tomorrow's rate equals today's. Since Meese and Rogoff (1983) almost nothing beats it at short horizons, and a 2025 Fed working paper reconfirmed it for modern machine learning. This is the hands-on companion to [the forty-year wall](https://exchangerate.dev/learn/can-you-predict-exchange-rates): about **30 lines of Python** that pull the data, build the benchmark, and score a model honestly.

- The benchmark every FX forecast must beat is the random walk: tomorrow's rate equals today's. On daily major pairs it is remarkably hard to beat.
- Run this five-year test with Plus or Pro: pull the series, build the benchmark, then score with out-of-sample R² and a Clark-West test.
- Drop forward-filled weekend and holiday rows (the `is_forward_filled` flag) or your model quietly learns from flat Sundays.
- Adding model complexity makes out-of-sample accuracy worse, not better. You watch overfitting happen in real time.
- The companion post runs this on five currency pairs and shows how easily a couple of defensible choices can manufacture a "significant" edge.

## The benchmark: "tomorrow equals today"

In 1983, [Meese and Rogoff](https://scholar.harvard.edu/rogoff/publications/empirical-exchange-rate-models-seventies-do-they-fit-out-sample) showed that no macro model could out-forecast a model that says tomorrow's exchange rate will be whatever it is today. Interest-rate differentials, money supply, purchasing-power parity: none of them helped. That "model" is the random walk, and forty years of increasingly clever economics has mostly bounced off it. We cover why in [Can you predict exchange rates?](https://exchangerate.dev/learn/can-you-predict-exchange-rates) This guide is the practical half: the code to check the claim yourself.

In September 2025 a Fed economist put modern machine learning through the same test. The paper, [*Virtue or Mirage? Complexity in Exchange Rate Prediction*](https://www.federalreserve.gov/econres/feds/files/2025089pap.pdf) (Rehim Kılıç, FEDS 2025-089), pitted Ridge regression on Random Fourier Features against the random walk, judged by out-of-sample R² and the Clark-West and Diebold-Mariano tests. The verdict was careful: complexity gave "only modest, localized gains" that were "fragile and rarely statistically significant," and never translated into a systematic edge over the random walk.

**What we can and cannot reproduce**

The paper uses monthly macro fundamentals a rates API does not serve, so we cannot replicate it exactly. But we can test the load-bearing question, the one most builders actually hit: using only price history, can a trained model beat "tomorrow equals today"?

## Pull the data

Five years of daily EUR/USD from `/v1/range` require a Plus or Pro API key.

```pythonfetchadailyseries title="python, fetch a daily series"
import os, requests, numpy as np, pandas as pd

def fetch_range(base, symbol, start, end, key):
    rows, cursor = [], None
    headers = {"Authorization": f"Bearer {key}"}
    while True:
        p = {"base": base, "symbols": symbol, "start_date": start, "end_date": end}
        if cursor: p["cursor"] = cursor
        d = requests.get("https://api.exchangerate.dev/v1/range",
                         params=p, headers=headers, timeout=30).json()
        rows += [{"date": r["date"], "rate": r["rates"][symbol]} for r in d["data"]]
        if not d.get("has_more"): break
        cursor = d["next_cursor"]
    df = pd.DataFrame(rows).drop_duplicates("date")
    df["date"] = pd.to_datetime(df["date"])
    return df.sort_values("date").set_index("date")

fx = fetch_range("EUR", "USD", "2021-01-01", "2026-01-01", os.environ["EXCHANGERATE_API_KEY"])
```

One thing worth doing right: each row carries an `is_forward_filled` flag and a `source` field. Weekends and holidays are forward-filled, so a serious study drops those rows. You do not want your model "learning" from a flat Sunday, a small version of the look-ahead traps covered in [Backfill without look-ahead bias](https://exchangerate.dev/learn/backfill-without-lookahead).

## Build the benchmark and a challenger

The random walk predicts a zero return every day (the driftless martingale Meese and Rogoff used). Give the challenger every cheap edge from the price series alone, momentum, mean reversion, realized volatility, and let Ridge (the paper's own estimator) predict tomorrow's return.

```pythonfeaturesandaridgemodel title="python, features and a Ridge model"
from sklearn.linear_model import Ridge

fx["ret"] = np.log(fx["rate"]).diff()
f = pd.DataFrame(index=fx.index)
for lag in (1, 2, 3, 5, 10): f[f"lag{lag}"] = fx["ret"].shift(lag)
f["mom5"], f["mom20"] = fx["ret"].rolling(5).sum().shift(1), fx["ret"].rolling(20).sum().shift(1)
f["vol10"], f["y"] = fx["ret"].rolling(10).std().shift(1), fx["ret"]
f = f.dropna()

split = int(len(f) * 0.7)
X = [c for c in f.columns if c != "y"]
m = Ridge(alpha=1.0).fit(f.iloc[:split][X], f.iloc[:split]["y"])
pred, y = m.predict(f.iloc[split:][X]), f.iloc[split:]["y"].values
```

## Score it honestly

Out-of-sample R² against the random walk (positive means you won), plus the Clark-West test, the right one when the random walk is nested inside your model.

```pythonoutofsamplerandclarkwest title="python, out-of-sample R² and Clark-West"
from scipy import stats
r2 = 1 - np.sum((y - pred)**2) / np.sum(y**2)
f_hat = y**2 - ((y - pred)**2 - pred**2)
t = f_hat.mean() / (f_hat.std(ddof=1) / np.sqrt(len(f_hat)))
print(f"OOS R2 {r2:+.4%} | Clark-West t {t:+.2f} p {1-stats.norm.cdf(t):.3f}")
```

Run it across EUR/USD, GBP/USD, USD/JPY and a few windows. The pattern is stubborn. Out-of-sample R² sits at or below zero, from roughly flat to a couple of percent negative, meaning the trained model usually did worse than assuming no change at all. The Clark-West stat rarely clears significance, and the cells that flirt with it move around when you nudge the split or the standard errors. Crank up the feature count to add "complexity" and out-of-sample only gets worse. You are watching overfitting happen in real time. We [ran the full test on five pairs](https://exchangerate.dev/learn/we-tried-to-beat-the-random-walk) and published every number.

## Why this matters if you are building

If you ship a "predicted rate" feature, the baseline you have to beat is `return today's rate`, and on daily major-pair data that baseline is remarkably hard to beat. A forecast endpoint that quietly does worse is a confidently wrong number sitting in someone's checkout flow or treasury dashboard.

The defensible value is elsewhere. Serve the level accurately and fast, since the best point forecast for the next rate really is the current one. Quantify uncertainty instead of point-forecasting: volatility and confidence bands are genuinely useful and do not require beating the random walk. And be honest about horizon, because predictability is roughly nil day-to-day and only creeps up over months, which is where the literature finds what little edge exists.

> That flat random-walk line is information. It is the market saying today's price already holds most of what is knowable about tomorrow's. For a data provider, the winning move is to publish that price more accurately and faster than anyone, and to be straight about the limits of prediction.

## Questions

### What is the random-walk benchmark in FX forecasting?

It is the simplest possible forecast: tomorrow's exchange rate equals today's, with no parameters and no fundamentals. Because it is so hard to beat out of sample, it is the standard benchmark any serious forecasting claim must be measured against.

### Can machine learning beat a random walk for currencies?

Not systematically at short horizons. A 2025 Federal Reserve working paper found the apparent edge from complex models to be a "mirage" that fades as the test window grows, and in a simple price-only test you can reproduce, adding features makes out-of-sample accuracy worse rather than better.

### How do I test an FX forecast against a random walk in Python?

Pull a daily series (for example from the exchangerate.dev /v1/range endpoint), split it chronologically so the model never sees the test window, forecast the next return, then score with out-of-sample R² against a zero-return random walk and a Clark-West significance test. The full code is in this guide.

### Why drop forward-filled rows before backtesting?

Weekend and holiday rates are forward-filled from the last trading day. Leaving them in feeds your model flat, repeated values it could never have traded on, which inflates apparent accuracy. Each API response flags these with is_forward_filled so you can drop them.

## Keep reading

- [We tried to beat the random walk on five pairs](https://exchangerate.dev/learn/we-tried-to-beat-the-random-walk)
- [Can you predict exchange rates? The forty-year wall](https://exchangerate.dev/learn/can-you-predict-exchange-rates)
- [Backfill FX rates without look-ahead bias](https://exchangerate.dev/learn/backfill-without-lookahead)

Source: https://exchangerate.dev/learn/beat-the-random-walk-fx-forecasting
