Directional Accuracy Test
Calculate a directional accuracy test: whether a return forecast predicts the direction of the next return better than chance, with the Pesaran-Timmermann or the Anatolyev-Gerko test.
A forecast that is right about the sign more than half of the time is not necessarily useful: in a rising market a forecast that is always positive is right on most days. The Pesaran-Timmermann test compares the share of correct signs with the share expected if the forecast and the returns were independent. The Anatolyev-Gerko test weighs each sign by the size of the return: it is the excess return of going long when the forecast is positive and short when it is negative over that of the same share of long positions held at random, so it asks whether the forecast would have made money.
The formula is as follows (with the default momentum forecast and daily returns, for which the window is 252):
\[\text{Forecast}_{t} = \operatorname{mean}(\text{Return}_{t-252},\; \ldots,\; \text{Return}_{t-1})\] \[P = \frac{1}{n} \sum 1 \{\text{Forecast}_{t} \cdot \text{Return}_{t} > 0\},\;\; P^{*} = P_{y} P_{x} + (1 - P_{y}) (1 - P_{x})\] \[\text{Pesaran-Timmermann Statistic} = \frac{P - P^{*}}{\sqrt{V(P) - V(P^{*})}}\] \[\text{Anatolyev-Gerko Statistic} = \frac{A - B}{\sqrt{V}},\;\; \text{with}\;\; A = \frac{1}{n} \sum \;\operatorname{sign}(\text{Forecast}_{t}) \;\text{Return}_{t}\;\;\text{and}\;\; B = \operatorname{mean}(\operatorname{sign}(\text{Forecast})) \cdot \operatorname{mean}(\text{Return})\] \[\text{P-Value} = P(N(0,\; 1) > \text{Statistic})\]Where \(P_{y}\) and \(P_{x}\) are the shares of positive returns and forecasts, \(V (P) = P^{*} (1 - P^{*}) / n\), V(P*) = (2 P_y - 1)^2 \(P_{x} (1 - P_{x}) / n\) + (2 P_x - 1)^2 \(P_{y} (1 - P_{y}) / n + 4 P_{y} P_{x} (1 - P_{y}) (1 - P_{x}) / n^{2}\) and \(V = 4 p (1 - p) \Sigma\) (Return_t - mean(Return))^2 / \(n^{2}\) with p = (1 + mean(sign(Forecast))) / 2. The autoregressive forecast predicts each return with a + b · Return_(t-1), the least-squares AR(1) over the window pairs of returns before it. Both statistics are standard normal under the null hypothesis of no directional predictability; the p-value is one-sided.
Also known as: directional accuracy test, market timing test, sign test, PT test, AG test, DAC test.
Example · QQQ, TLT, GLD, USO · 2010 to 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_directional_accuracy_test:
from financetoolkit import Toolkit
toolkit = Toolkit(
["QQQ", "TLT", "GLD", "USO"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2010-01-01",
end_date="2025-12-31",
)
toolkit.econometrics.get_directional_accuracy_test(period="monthly", window=12)
Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:
Did a 12-month momentum signal predict the direction of the monthly returns of the Invesco QQQ, iShares 20+ Year Treasury Bond (TLT), SPDR Gold Shares (GLD) and United States Oil Fund (USO) ETFs from 2010 to 2025, according to the Pesaran-Timmermann test?
Which returns:
| Item | QQQ | TLT | GLD | USO |
|---|---|---|---|---|
| Pesaran-Timmermann Statistic | 0.7683 | -1.1950 | 1.3070 | -0.9591 |
| P-Value | 0.2211 | 0.8839 | 0.0956 | 0.8312 |
| Directional Accuracy | 0.6313 | 0.4581 | 0.5475 | 0.4637 |
| Observations | 179.0000 | 179.0000 | 179.0000 | 179.0000 |
4 rows
Using Your Own Data
get_directional_accuracy_test runs on any data, not only prices: ratios, economic indicators, yield curves or your own dataset. Pass a DataFrame, a Series or a dictionary of them to Econometrics as data, with the dates in the rows or the columns, and set changes to how its changes are calculated: "percentage", "log", "difference" for rates and ratios, or None when the data are changes already. For example, for the monthly unemployment rates of the United States and Germany:
from financetoolkit import Economics, Econometrics
economics = Economics(start_date="2000-01-01")
unemployment = economics.get_unemployment_rate(
countries=["United States", "Germany"], period="monthly"
)
econometrics = Econometrics(data=unemployment, changes="difference")
econometrics.get_directional_accuracy_test()
Parameters
get_directional_accuracy_test accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
period | str | The data frequency for returns (daily, weekly, monthly, quarterly or yearly). Defaults to “daily”. | "weekly" |
method | str | The test. Options are: “pesaran_timmermann” (Pesaran-Timmermann), “anatolyev_gerko” (Anatolyev-Gerko). Defaults to “pesaran_timmermann”. | "pesaran_timmermann" |
forecast | str | The return forecast. Options are: “momentum” (the mean of the previous window returns), “autoregressive” (the rolling AR(1)). Defaults to “momentum”. | "momentum" |
window | int | None | The number of returns of every forecast window, at least 2. Defaults to None, which uses a year of observations with a minimum of 20 (252 daily, 52 weekly and 20 monthly, quarterly or yearly returns). | 20 |
include_benchmark | bool | Whether to include “Benchmark” among the assets tested. Defaults to False. | True |
rounding | int | None | The number of decimals to round the results to. Defaults to None. | 2 |
show_columns | str | list[str] | None | The columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column. | None, which keeps every column |
References
- Paper Pesaran, M.H. and Timmermann, A. (1992). “A Simple Nonparametric Test of Predictive Performance.” Journal of Business & Economic Statistics, 10(4), 461-465.
- Paper Anatolyev, S. and Gerko, A. (2005). “A Trading Approach to Testing for Predictability.” Journal of Business & Economic Statistics, 23(4), 455-461.
- Paper Moskowitz, T.J., Ooi, Y.H. and Pedersen, L.H. (2012). “Time Series Momentum.” Journal of Financial Economics, 104(2), 228-250.
- Library Referenced against rugarch (R)’s DACTest