DPredict · Guide test 216
Pesaran–Timmermann test
Tests whether predicted directions and realized directions are associated beyond chance.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Forecast accuracy comparison — Is one set of forecasts really more accurate than another, or do they predict the direction of change better than chance?
In Forecast accuracy comparison, choose Test = Pesaran–Timmermann directional.
Do it in CodeSplash Run this test on your own data, in Python or R.
Bench
Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.
Bench · Pesaran–Timmermann test
Your data
Simulated with a known ρIf H₀ were true
- The reference: how z varies across samples when H₀ is true.
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .003).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- share of correctly called signs
- share expected if forecasts and outcomes were independent
The verdict
z = 2.80, p = .003, P̂ = 0.63
p ≤ α = .050: reject H₀
Effect size: share of directions called right P̂ = 0.625
A forecast can call directions well and still have large errors; this tests only the signs. Here x is the outcome and y the forecast.
- Statistic
- 2.796
- p-value
- 0.0026
Pesaran–Timmermann test on 120 (x, y) pairs: z = 2.80, p = .003, P̂ = 0.63. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: forecast direction and realized direction are independent.
Assumptions
Independent binary direction pairs for the standard variance formula; stationary weak-dependence extensions require adjusted covariance.
Formula
Parameters and notation
P̂ is directional hit fraction, py observed-up fraction,pf forecast-up fraction. V(P̂)=P̂*(1−P̂*)/T; V(P̂*)=[(2py−1)²pf(1−pf)+(2pf−1)²py(1−py)]/T+4py pf(1−py)(1−pf)/T².
Structure of the method
Convert realized and predicted changes into binary directions under a declared zero rule, form the hit rate, derive the chance hit rate from estimated marginal up frequencies, and divide their difference by the appropriate variance. This is an association test on direction pairs, not a regression fit.
Estimated and nuisance parameters
Estimate realized-up and forecast-up probabilities, the joint agreement probability, and the variance terms accounting for estimated margins. The predictive model itself is upstream. Constant forecasts or outcomes can make the denominator degenerate, so marginal rates and the full direction contingency table should accompany the statistic.
Settings and design choices
Choose horizon, zero/tie treatment, one-sided better-than-chance versus a two-sided association question, and dependence calibration. Changing a threshold away from zero changes the question and must be prespecified. Trying multiple assets, horizons, thresholds, or forecast methods creates a family of comparisons.
Fitting and adaptation
Obtain forecasts using only information available at their forecast origins. There is no model fine-tuning inside the standard test; adapting a forecasting system means refitting it separately and evaluating on held-out direction pairs. Use a dependence-robust extension or justified block-based procedure when the standard iid direction-pair variance is unsuitable.
Sensitivity and robustness
Highly imbalanced directions can yield impressive hit rates with little skill. Serial dependence and overlapping forecast horizons change uncertainty. The synthetic example lets forecast values depend directly on realized values and is therefore a mathematical illustration, not evidence of an operational forecast strategy.
How to use and calibrate
Use an asymptotic normal upper tail for better-than-chance directional forecasting.
Example application
Evaluate whether forecasts correctly predict increases/decreases beyond marginal up/down frequencies.
Interpretation and pitfalls
Watch out
A high hit rate alone can result from persistent upward movement. Serial dependence and ties at zero need explicit treatment.
What changed in edition 2
- New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.
Python and R
Pesaran–Timmermann directional-accuracy statistic with one-sided alternative of better-than-independent sign prediction. Zero signs are assigned to the nonpositive category here; specify that convention.
Validated — Executed successfully in the validation environment · needs numpy, scipy
import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
actual=rng.normal(size=200);forecast=.3*actual+rng.normal(size=200)
a=actual>0;f=forecast>0;n=len(a);pa=a.mean();pf=f.mean();ph=(a==f).mean();p0=pa*pf+(1-pa)*(1-pf)
v=p0*(1-p0)/n;v0=(2*pa-1)**2*pf*(1-pf)/n+(2*pf-1)**2*pa*(1-pa)/n+4*pa*pf*(1-pa)*(1-pf)/n**2
z=(ph-p0)/np.sqrt(v-v0);print(z,stats.norm.sf(z))
Output
4.251728730580279 1.0606335449900707e-05
Validated — Executed successfully in the validation environment · needs Base/standard library
set.seed(2026)
actual<-rnorm(200);forecast<-actual*.3+rnorm(200);a<-actual>0;f<-forecast>0;n<-length(a);pa<-mean(a);pf<-mean(f);ph<-mean(a==f);p0<-pa*pf+(1-pa)*(1-pf);v<-p0*(1-p0)/n;v0<-(2*pa-1)^2*pf*(1-pf)/n+(2*pf-1)^2*pa*(1-pa)/n+4*pa*pf*(1-pa)*(1-pf)/n^2;z<-(ph-p0)/sqrt(v-v0);print(c(z=z,p=pnorm(z,lower.tail=FALSE)))
Output
z p 2.693883277 0.003531245
Sources
- cran.r-project.org/package=tstestscran.r-project.org
- package=tstestscran.r-project.org
- Statistics guide v4 (historical):
- R: Executed successfully in the validation environment
- Reference's record:
- Edition 2 review: Python: executed · R: not executed (Rscript unavailable). Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.
From the CodeSplash statistics guide (v4), entry 216, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT216.