Long Memory Test

Test every series for long memory: whether its shocks fade so slowly that it is fractionally integrated, with a memory parameter d above 0 (persistent) or below 0 (anti-persistent), rather than having short memory as an ARMA process.

A fractionally integrated series \((1 - L)^{d} \cdot x_{t} = u_{t}\) has autocorrelations that decay hyperbolically, like \(k^{2 d - 1}\), instead of exponentially: \(d = 0\) is short memory, \(0 < d < 0.5\) long memory that is still stationary, \(0.5 \leq d < 1\) non-stationary but mean-reverting and \(d = 1\) a unit root. Returns of liquid assets usually have d close to 0, while their absolute or squared returns (volatility) and many macroeconomic series such as inflation have d between 0.2 and 0.5. The Hurst exponent of the series is \(H = d + 0.5\) (see get_hurst_exponent in the risk module); the fractional difference that removes the memory is get_fractional_difference.

The formula for the GPH test (Geweke and Porter-Hudak, 1983) is as follows:

\[I(\lambda_{j}) = \frac{\left\lvert \sum_{t=1}^{n} (x_{t} - \bar{x}) \cdot \exp\left(-i \cdot \lambda_{j} \cdot t\right)\right\rvert^{2}}{2 \cdot \pi \cdot n}\] \[\lambda_{j} = \frac{2 \cdot \pi \cdot j}{n}\] \[m = \left\lfloor n^{\texttt{power}}\right\rfloor\] \[\ln\left(I(\lambda_{j})\right) = c + d \cdot \left(-\ln\left(4 \cdot \sin\left(\frac{\lambda_{j}}{2}\right)^{2}\right)\right) + u_{j}\] \[\text{Standard Error} = \frac{\pi}{\sqrt{24 \cdot m}}\] \[\text{Statistic} = \frac{d}{\text{Standard Error}}\]

with I the periodogram at the Fourier frequencies \(\lambda_{j}\), \(j = 1\), …, m, i the imaginary unit, power = 0.5 by default and \(x_{t}\) the column series (Return by default). d is the least squares slope and \(u_{j}\) the error. The Standard Error is Robinson’s (1995a); the Statistic is standard normal without long memory, with a two-sided p-value.

The formula for the local Whittle test (Robinson, 1995b) is as follows:

\[R(d) = \ln\left(\frac{\sum_{j=1}^{m} \lambda_{j}^{2 \cdot d} \cdot I(\lambda_{j})}{m}\right) - \left(\frac{2 \cdot d}{m}\right) \cdot \sum_{j=1}^{m} \ln\left(\lambda_{j}\right)\] \[\hat{d} = \operatorname*{arg\,min}\left(R(d)\right)\] \[\text{Standard Error} = \frac{1}{2 \cdot \sqrt{m}}\] \[\text{Statistic} = \frac{\hat{d}}{\text{Standard Error}}\]

with the minimum over \(- 0.5 < d < 1\), the same frequencies and a two-sided p-value.

The formula for the modified rescaled range test (Lo, 1991) is as follows:

\[V = \frac{\max\left(S_{k}\right) - \min\left(S_{k}\right)}{\hat{\sigma}_{q} \cdot \sqrt{n}}\] \[\text{where}\;\; S_{k} = \sum_{j=1}^{k} (x_{j} - \bar{x})\] \[\hat{\sigma}_{q}^{2} = \hat{\gamma}_{0} + 2 \cdot \sum_{j=1}^{q} \left(1 - \frac{j}{q + 1}\right) \cdot \hat{\gamma}_{j}\] \[q = \left\lfloor \left(\frac{3 \cdot n}{2}\right)^{1/3} \cdot \left(\frac{2 \cdot \left\lvert \hat{\rho}\right\rvert}{1 - \hat{\rho}^{2}}\right)^{2/3}\right\rfloor\] \[F(v) = 1 + 2 \cdot \sum_{k=1}^{\infty} \left(1 - 4 \cdot k^{2} \cdot v^{2}\right) \cdot \exp\left(-2 \cdot k^{2} \cdot v^{2}\right)\] \[\text{P Value} = 2 \cdot \min\left(F(V), 1 - F(V)\right)\]

with the maximum and minimum over k. hat(sigma_q)^2 is the Newey-West variance with the autocovariances hat(gamma_j) (n in the denominator), so short-term autocorrelation alone does not reject; q comes from the first autocorrelation hat(rho) (Andrews, 1991) unless lags is given. Without long memory V follows the range of a Brownian bridge, with distribution function F, and the p-value is two-sided (V below 0.809 or above 1.862 rejects at 5%).

Also known as: long memory, long-range dependence, fractional integration, ARFIMA d, GPH, log-periodogram regression, local Whittle, Gaussian semiparametric estimator, Lo’s modified R/S, persistence.

Example · AAPL, MSFT · 2016 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_long_memory_test:

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["AAPL", "MSFT"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2016-01-01",
    end_date="2025-12-31",
)

toolkit.econometrics.get_long_memory_test()

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

Did the daily returns of Apple and Microsoft have long memory from 2016 to 2025, and what were their fractional differencing parameter and Hurst exponent?

Which returns:

Using Your Own Data

get_long_memory_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_long_memory_test()

Parameters

get_long_memory_test accepts the following parameters.

ParameterTypeDescriptionExample
methodstrThe test. Options are: “gph” (Geweke-Porter-Hudak log periodogram regression), “local_whittle” (Robinson’s local Whittle estimator), “modified_rescaled_range” (Lo’s modified rescaled range). Defaults to “gph”."gph"
periodstrThe data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”."weekly"
columnstrThe historical data column. Defaults to “Return”."Return"
powerfloatThe bandwidth \(m = \text{⌊} n^{\text{power}} \text{⌋}\) of the GPH and local Whittle tests, between 0 and 1: a larger power uses more frequencies, which lowers the standard error but lets short memory bias d. Defaults to 0.5.2
lagsint | NoneThe lags q of the modified rescaled range. Defaults to None, which takes Andrews’ (1991) choice.2
include_benchmarkboolWhether to include “Benchmark” among the assets. Defaults to False.True
roundingint | NoneThe number of decimals to round the results to. Defaults to None.2
show_columnsstr | list[str] | NoneThe 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 Geweke, J. and Porter-Hudak, S. (1983). “The Estimation and Application of Long Memory Time Series Models.” Journal of Time Series Analysis, 4(4), 221-238.
  • Paper Robinson, P.M. (1995a). “Log-Periodogram Regression of Time Series with Long Range Dependence.” The Annals of Statistics, 23(3), 1048-1072.
  • Paper Robinson, P.M. (1995b). “Gaussian Semiparametric Estimation of Long Range Dependence.” The Annals of Statistics, 23(5), 1630-1661.
  • Paper Lo, A.W. (1991). “Long-Term Memory in Stock Market Prices.” Econometrica, 59(5), 1279-1313.
  • Paper Andrews, D.W.K. (1991). “Heteroskedasticity and Autocorrelation Consistent Covariance Matrix Estimation.” Econometrica, 59(3), 817-858.
Share