Skip to main content

Flexible Fourier Form and Local GLS De-trended Unit Root Tests

Project description

Fourier GLS Unit Root Tests

Python 3.8+ License: MIT PyPI version

A Python implementation of the Flexible Fourier Form and Local Generalised Least Squares De-trended Unit Root Tests.

Reference

Rodrigues, P. M. M and Taylor, A. M. R. (2012)
"The Flexible Fourier Form and Local Generalised Least Squares De-trended Unit Root Tests."
Oxford Bulletin of Economics and Statistics, 74(5), 736-759.

Features

  • Fourier GLS Test: Local GLS de-trended unit root test with Fourier approximation for unknown structural breaks
  • Fourier DF Test: OLS de-trended Dickey-Fuller test with Fourier terms (Enders & Lee, 2009)
  • Fourier LM Test: First-difference de-trended LM test with Fourier terms (Schmidt & Phillips, 1992)
  • F-Test for Linearity: Test significance of Fourier terms
  • Data-Driven Frequency Selection: Automatic selection using Davies (1987) procedure
  • Critical Values: Complete tables from the original paper (Tables 1-3)
  • Publication-Ready Output: Formatted results suitable for academic papers

Installation

pip install fourier-gls

Or install from source:

git clone https://github.com/merwanroudane/fouriergls.git
cd fouriergls
pip install -e .

Quick Start

import numpy as np
from fourier_gls import fourier_gls

# Generate sample data (unit root with structural break)
np.random.seed(42)
T = 200
t = np.arange(1, T + 1)
y = np.cumsum(np.random.randn(T)) + 5 * np.sin(2 * np.pi * t / T)

# Run Fourier GLS test
result = fourier_gls(y, model=2)  # model=2 includes constant and trend

Output:

================================================================================
                    Fourier GLS Unit Root Test Results
================================================================================
Reference: Rodrigues & Taylor (2012), Oxford Bulletin of Economics and Statistics

Model:               Constant + Trend
Sample Size:         200
Selected Frequency:  k = 1
Selected Lags:       2

--------------------------------------------------------------------------------
Test Statistic:      -3.2456
--------------------------------------------------------------------------------

Critical Values:
    1%:   -4.5930
    5%:   -4.0410
    10%:  -3.7490

--------------------------------------------------------------------------------
Conclusion (5% level): Fail to reject H0: No evidence against unit root at 5% level
================================================================================

API Reference

Main Functions

fourier_gls(y, model=2, pmax=8, fmax=5, ic=3, verbose=True)

Performs the Fourier GLS unit root test with automatic frequency selection.

Parameters:

  • y : array-like - Time series data
  • model : int - 1 = Constant only, 2 = Constant and linear trend (default)
  • pmax : int - Maximum number of lags (default: 8)
  • fmax : int - Maximum Fourier frequency, 1-5 (default: 5)
  • ic : int - Information criterion: 1=AIC, 2=SIC, 3=t-stat (default: 3)
  • verbose : bool - Print results (default: True)

Returns: FourierGLSResult object

fourier_gls_f_test(y, model, k, p=0, verbose=True)

Tests significance of Fourier terms (H0: γ₁ = γ₂ = 0).

gls_detrend(y, z, cbar, return_ssr=False)

Performs GLS detrending using the Elliott, Rothenberg & Stock (1996) procedure.

Result Object

The FourierGLSResult object contains:

Attribute Description
statistic Test statistic (t-ratio)
frequency Selected Fourier frequency
lags Number of lags selected
critical_values Array of [1%, 5%, 10%] critical values
model Model specification (1 or 2)
T Sample size
conclusion Test conclusion at 5% level

Methods:

  • summary() : Returns formatted summary string
  • to_dict() : Converts results to dictionary

Critical Values

from fourier_gls import get_cbar, get_fourier_gls_critical_values

# Get c-bar parameter (Table 1)
cbar = get_cbar(model=2, k=1)  # Returns -22.00

# Get critical values (Table 2)
cv = get_fourier_gls_critical_values(T=200, model=2)

Model Specifications

Model 1: Constant Only

$$y_t = \delta_0 + \gamma_1 \sin\left(\frac{2\pi k t}{T}\right) + \gamma_2 \cos\left(\frac{2\pi k t}{T}\right) + x_t$$

Model 2: Constant and Trend

$$y_t = \delta_0 + \delta_1 t + \gamma_1 \sin\left(\frac{2\pi k t}{T}\right) + \gamma_2 \cos\left(\frac{2\pi k t}{T}\right) + x_t$$

where $x_t = \rho x_{t-1} + u_t$ and $u_t \sim \text{iid}(0, \sigma^2)$.

Examples

Basic Usage

import numpy as np
from fourier_gls import fourier_gls

# Load your data
y = np.loadtxt('your_data.csv')

# Test with constant + trend model
result = fourier_gls(y, model=2)
print(f"Test statistic: {result.statistic:.4f}")
print(f"Selected frequency: k = {result.frequency}")

Comparing Different Tests

from fourier_gls import fourier_gls, fourier_df, fourier_lm

y = np.random.randn(200).cumsum()

# GLS de-trended test
gls_result = fourier_gls(y, model=2, verbose=False)

# OLS de-trended test  
df_result = fourier_df(y, model=2, verbose=False)

# LM test
lm_result = fourier_lm(y, verbose=False)

print(f"GLS statistic: {gls_result.statistic:.4f}")
print(f"DF statistic:  {df_result.statistic:.4f}")
print(f"LM statistic:  {lm_result.statistic:.4f}")

Fixed Frequency Test

from fourier_gls import fourier_gls_fixed_k

# Use k=1 (single break-like behavior)
result = fourier_gls_fixed_k(y, model=2, k=1)

Testing for Fourier Term Significance

from fourier_gls import fourier_gls_f_test

# Test if Fourier terms are significant
f_result = fourier_gls_f_test(y, model=2, k=1, p=2)

Simulating Critical Values

from fourier_gls import simulate_critical_values

# Generate custom critical values
cv = simulate_critical_values(T=150, model=2, k=1, n_simulations=10000, seed=42)
print(f"Critical values (1%, 5%, 10%): {cv}")

Critical Values Tables

Table 1: Local GLS De-trending Parameters (c̄)

k Constant (c̄_κ) Constant + Trend (c̄_τ)
0 -7.00 -13.50
1 -12.25 -22.00
2 -8.25 -16.25
3 -7.75 -14.75
4 -7.50 -14.25
5 -7.25 -14.00

Table 2: Critical Values for t^{ERS}_f Tests

Sample critical values for T = 200, Constant + Trend model:

k 1% 5% 10%
1 -4.593 -4.041 -3.749
2 -4.191 -3.569 -3.228
3 -3.993 -3.300 -2.950
4 -3.852 -3.174 -2.852
5 -3.749 -3.075 -2.761

Compatibility

This implementation is designed to be fully compatible with the original GAUSS code by Saban Nazlioglu and matches the methodology in Rodrigues & Taylor (2012).

Requirements

  • Python >= 3.8
  • NumPy >= 1.20.0
  • SciPy >= 1.7.0

Author

Dr. Merwan Roudane
Email: merwanroudane920@gmail.com
GitHub: https://github.com/merwanroudane/fouriergls

License

MIT License - see LICENSE for details.

Citation

If you use this package in academic work, please cite:

@article{rodrigues2012flexible,
  title={The Flexible Fourier Form and Local Generalised Least Squares De-trended Unit Root Tests},
  author={Rodrigues, Paulo MM and Taylor, A M Robert},
  journal={Oxford Bulletin of Economics and Statistics},
  volume={74},
  number={5},
  pages={736--759},
  year={2012}
}

@software{roudane2024fouriergls,
  author = {Roudane, Merwan},
  title = {fourier\_gls: Python Implementation of Fourier GLS Unit Root Tests},
  year = {2024},
  url = {https://github.com/merwanroudane/fouriergls}
}

Related Papers

  1. Elliott, G., Rothenberg, T. J., & Stock, J. H. (1996). Efficient tests for an autoregressive unit root. Econometrica, 64, 813-836.

  2. Enders, W., & Lee, J. (2012). A Unit Root Test Using a Fourier Series to Approximate Smooth Breaks. Oxford Bulletin of Economics and Statistics, 74(4), 574-599.

  3. Becker, R., Enders, W., & Lee, J. (2006). A stationarity test in the presence of an unknown number of smooth breaks. Journal of Time Series Analysis, 27, 381-409.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fourier_gls-1.0.0.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fourier_gls-1.0.0-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file fourier_gls-1.0.0.tar.gz.

File metadata

  • Download URL: fourier_gls-1.0.0.tar.gz
  • Upload date:
  • Size: 26.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for fourier_gls-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c2eaae77fc8d37f039203654119ad877f61c8f2ad3a5dbb6844bd84cddbc9727
MD5 e0364abe09359fe8ed786ea528897a97
BLAKE2b-256 c22be2aaa371c1499013c3b01d85cf7ee9f2aaaaeb844307001ba250741b56c7

See more details on using hashes here.

File details

Details for the file fourier_gls-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: fourier_gls-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for fourier_gls-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 009f402b7b6911218b36ce62fe4b7b6c6f50e9515bb81eca477de1a2473c5716
MD5 92df2720dd1abddf620bcc222ac0a3fb
BLAKE2b-256 034936aeb1a306a11c21ce604f110560d9aeacbaf48cb99195f197ca7bd6131a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page