Title: | Rmetrics - Modelling Trends and Unit Roots |
---|---|
Description: | Provides four addons for analyzing trends and unit roots in financial time series: (i) functions for the density and probability of the augmented Dickey-Fuller Test, (ii) functions for the density and probability of MacKinnon's unit root test statistics, (iii) reimplementations for the ADF and MacKinnon Test, and (iv) an 'urca' Unit Root Test Interface for Pfaff's unit root test suite. |
Authors: | Diethelm Wuertz [aut] (original code), Tobias Setz [aut], Yohan Chalabi [aut], Georgi N. Boshnakov [cre] |
Maintainer: | Georgi N. Boshnakov <[email protected]> |
License: | GPL (>= 2) |
Version: | 4040.81 |
Built: | 2024-12-14 03:02:56 UTC |
Source: | https://github.com/r-forge/rmetrics |
The Rmetrics "fUnitRoots" package is a collection of functions to model trends and to analyze unit roots.
The 'fUnitroots' provides four addons for analyzing trends and unit roots in financial time series: (i) functions for the density and probability of the augmented Dickey-Fuller Test, (ii) functions for the density and probability of MacKinnon's unit root test statistics, (iii) reimplementations for the ADF and MacKinnon Test, and (iv) an 'urca' Unit Root Test Interface for Pfaff's unit root test suite.
The section provides functions to compute the distribution and quantile functions for the ADF unit root test statistics.
padf returns the cumulative probability for the ADF test qadf returns the quantiles for the ADF test adfTable tables p values for ADF test
The section provides functions to compute the distribution and quantile functions for MacKinnon's unit root test statistics.
punitroot returns the cumulative probability qunitroot returns the quantiles of the unit root test statistics unitrootTable tables p values from MacKinnon's response surface
This section provides two functions for unit root testing of financial time series, the ADF tests based on Banerjee's et al. tables and the unit root tests based on J.G. McKinnons' tables:
adfTest augmented Dickey-Fuller test for unit roots unitrootTest the same based on McKinnons's test statistics
This is an interface to the unitroot tests suite implemented by Bernhard Pfaff available through the R package "urca"
urdfTest Augmented Dickey-Fuller test for unit roots urersTest Elliott--Rothenberg-Stock test for unit roots urkpssTest KPSS unit root test for stationarity urppTest Phillips-Perron test for unit roots urspTest Schmidt-Phillips test for unit roots urzaTest Zivot-Andrews test for unit roots
The fUnitroots
Rmetrics package is written for educational
support in teaching "Computational Finance and Financial Engineering"
and licensed under the GPL.
A collection and description of functions
to compute the distribution and quantile
function for the ADF unit root test statistics.
The functions are:
padf |
the returns cumulative probability for the ADF test, |
qadf |
the returns quantiles for the ADF test, |
adfTable |
tables p values for ADF test. |
padf(q, N = Inf, trend = c("nc", "c", "ct"), statistic = c("t", "n")) qadf(p, N = Inf, trend = c("nc", "c", "ct"), statistic = c("t", "n")) adfTable(trend = c("nc", "c", "ct"), statistic = c("t", "n"), includeInf = TRUE)
padf(q, N = Inf, trend = c("nc", "c", "ct"), statistic = c("t", "n")) qadf(p, N = Inf, trend = c("nc", "c", "ct"), statistic = c("t", "n")) adfTable(trend = c("nc", "c", "ct"), statistic = c("t", "n"), includeInf = TRUE)
includeInf |
a logical flag. Should the asymptotic value be included into the table? |
N |
the number of observations in the sample from which the
quantiles are to be computed. |
p |
a numeric vector of probabilities. Missing values are allowed. |
q |
vector of quantiles or test statistics. Missing values are allowed. |
statistic |
a character string describing the type of test statistic.
Valid choices are |
trend |
a character string describing the regression from which the
quantiles are to be computed. Valid choices are: |
The function padf
returns the cumulative probability of
the finite sample distribution of the unit root test statistics.
The function qadf
returns the quantiles of the finite sample
distribution of the unit root test statistics, given the probabilities.
The functions padf
and qadf
use the tables from
A. Banerjee et al. (1993).
Diethelm Wuertz for the Rmetrics R-port.
Banerjee A., Dolado J.J., Galbraith J.W., Hendry D.F. (1993); Cointegration, Error Correction, and the Econometric Analysis of Non-Stationary Data, Oxford University Press, Oxford.
Dickey, D.A., Fuller, W.A. (1979); Distribution of the estimators for autoregressive time series with a unit root, Journal of the American Statistical Association 74, 427–431.
## ADF dftesTable - adfTable()
## ADF dftesTable - adfTable()
A collection and description of functions
to compute the distribution and quantile
function for MacKinnon's unit root test statistics.
The functions are:
punitroot |
the returns cumulative probability, |
qunitroot |
the returns quantiles of the unit root test statistics, |
unitrootTable |
tables of p values from MacKinnon's response surface. |
punitroot(q, N = Inf, trend = c("c", "nc", "ct", "ctt"), statistic = c("t", "n"), na.rm = FALSE) qunitroot(p, N = Inf, trend = c("c", "nc", "ct", "ctt"), statistic = c("t", "n"), na.rm = FALSE) unitrootTable(trend = c("c", "nc", "ct", "ctt"), statistic = c("t", "n"))
punitroot(q, N = Inf, trend = c("c", "nc", "ct", "ctt"), statistic = c("t", "n"), na.rm = FALSE) qunitroot(p, N = Inf, trend = c("c", "nc", "ct", "ctt"), statistic = c("t", "n"), na.rm = FALSE) unitrootTable(trend = c("c", "nc", "ct", "ctt"), statistic = c("t", "n"))
N |
the number of observations in the sample from which the
quantiles are to be computed. |
na.rm |
a logical value. If set to |
p |
a numeric vector of probabilities. Missing values are allowed. |
q |
vector of quantiles or test statistics. Missing values are allowed. |
statistic |
a character string describing the type of test statistic.
Valid choices are |
trend |
a character string describing the regression from which the
quantiles are to be computed. Valid choices are: |
The function punitroot
returns the cumulative probability
of the asymptotic or finite sample distribution of the unit root
test statistics.
The function qunitroot
returns the quantiles of the
asymptotic or finite sample distribution of the unit root test
statistics, given the probabilities.
The function punitroot
and qunitroot
use Fortran
routines and the response surface approach from J.G. MacKinnon (1988).
Many thanks to J.G. MacKinnon putting his code and tables under the
GPL license, which made this implementation possible.
J.G. MacKinnon for the underlying Fortran routine and the tables,
Diethelm Wuertz for the Rmetrics R-port.
Dickey, D.A., Fuller, W.A. (1979); Distribution of the estimators for autoregressive time series with a unit root, Journal of the American Statistical Association 74, 427–431.
MacKinnon, J.G. (1996); Numerical distribution functions for unit root and cointegration tests, Journal of Applied Econometrics 11, 601–618.
Phillips, P.C.B., Perron, P. (1988); Testing for a unit root in time series regression, Biometrika 75, 335–346.
## qunitroot - # Asymptotic quantile of t-statistic qunitroot(0.95, trend = "nc", statistic = "t") ## qunitroot - # Finite sample quantile of n-statistic qunitroot(0.95, N = 100, trend = "nc", statistic = "n") ## punitroot - # Asymptotic cumulative probability of t-statistic punitroot(1.2836, trend = "nc", statistic = "t") ## punitroot - # Finite sample cumulative probability of n-statistic punitroot(1.2836, N = 100, trend = "nc", statistic = "n") ## Mac Kinnon's unitrootTable - unitrootTable(trend = "nc")
## qunitroot - # Asymptotic quantile of t-statistic qunitroot(0.95, trend = "nc", statistic = "t") ## qunitroot - # Finite sample quantile of n-statistic qunitroot(0.95, N = 100, trend = "nc", statistic = "n") ## punitroot - # Asymptotic cumulative probability of t-statistic punitroot(1.2836, trend = "nc", statistic = "t") ## punitroot - # Finite sample cumulative probability of n-statistic punitroot(1.2836, N = 100, trend = "nc", statistic = "n") ## Mac Kinnon's unitrootTable - unitrootTable(trend = "nc")
A collection and description of functions
for unit root testing. The family of tests
includes ADF tests based on Banerjee's et al.
tables and on J.G. McKinnons' numerical
distribution functions.
The functions are:
adfTest |
Augmented Dickey-Fuller test for unit roots, |
unitrootTest |
the same based on McKinnons's test statistics. |
unitrootTest(x, lags = 1, type = c("nc", "c", "ct"), title = NULL, description = NULL) adfTest(x, lags = 1, type = c("nc", "c", "ct"), title = NULL, description = NULL)
unitrootTest(x, lags = 1, type = c("nc", "c", "ct"), title = NULL, description = NULL) adfTest(x, lags = 1, type = c("nc", "c", "ct"), title = NULL, description = NULL)
description |
a character string which allows for a brief description. |
lags |
the maximum number of lags used for error term correction. |
title |
a character string which allows for a project title. |
type |
a character string describing the type of the unit root
regression. Valid choices are |
x |
a numeric vector or time series object. |
The function adfTest()
computes test statistics and p values
along the implementation from Trapletti's augmented Dickey-Fuller
test for unit roots. In contrast to Trapletti's function three kind
of test types can be selected.
The function unitrootTest()
computes test statistics and p values
using McKinnon's response surface approach.
The tests return an object of class "fHTEST"
with the
following slots:
@call |
the function call. |
@data |
a data frame with the input data. |
@data.name |
a character string giving the name of the data frame. |
@test |
a list object which holds the output of the underlying test function. |
@title |
a character string with the name of the test. |
@description |
a character string with a brief description of the test. |
The entries of the @test
slot include the following components:
$statistic |
the value of the test statistic. |
$parameter |
the lag order. |
$p.value |
the p-value of the test. |
$method |
a character string indicating what type of test was performed. |
$data.name |
a character string giving the name of the data. |
$alternative |
a character string describing the alternative hypothesis. |
$name |
the name of the underlying function, which may be wrapped. |
$output |
additional test results to be printed. |
Adrian Trapletti for the tests adapted from R's "tseries" package,
Diethelm Wuertz for the Rmetrics R-port.
Banerjee A., Dolado J.J., Galbraith J.W., Hendry D.F. (1993); Cointegration, Error Correction, and the Econometric Analysis of Non-Stationary Data, Oxford University Press, Oxford.
Dickey, D.A., Fuller, W.A. (1979); Distribution of the estimators for autoregressive time series with a unit root, Journal of the American Statistical Association 74, 427–431.
MacKinnon, J.G. (1996); Numerical distribution functions for unit root and cointegration tests, Journal of Applied Econometrics 11, 601–618.
Said S.E., Dickey D.A. (1984); Testing for Unit Roots in Autoregressive-Moving Average Models of Unknown Order, Biometrika 71, 599–607.
## Time Series # A time series which contains no unit-root: x = rnorm(1000) # A time series which contains a unit-root: y = cumsum(c(0, x)) ## adfTest - adfTest(x) adfTest(y) ## unitrootTest - unitrootTest(x) unitrootTest(y)
## Time Series # A time series which contains no unit-root: x = rnorm(1000) # A time series which contains a unit-root: y = cumsum(c(0, x)) ## adfTest - adfTest(x) adfTest(y) ## unitrootTest - unitrootTest(x) unitrootTest(y)
A collection and description of functions for unit root testing. This is an interface to the unitroot tests implemented by B. Pfaff available through the R package urca which is required here.
Added functions based on the urca package include:
urdfTest |
Augmented Dickey-Fuller test for unit roots, |
urersTest |
Elliott-Rothenberg-Stock test for unit roots, |
urkpssTest |
KPSS unit root test for stationarity, |
urppTest |
Phillips-Perron test for unit roots, |
urspTest |
Schmidt-Phillips test for unit roots, |
urzaTest |
Zivot-Andrews test for unit roots. |
urdfTest(x, lags = 1, type = c("nc", "c", "ct"), doplot = TRUE) urersTest(x, type = c("DF-GLS", "P-test"), model = c("constant", "trend"), lag.max = 4, doplot = TRUE) urkpssTest(x, type = c("mu", "tau"), lags = c("short", "long", "nil"), use.lag = NULL, doplot = TRUE) urppTest(x, type = c("Z-alpha", "Z-tau"), model = c("constant", "trend"), lags = c("short", "long"), use.lag = NULL, doplot = TRUE) urspTest(x, type = c("tau", "rho"), pol.deg = c(1, 2, 3, 4), signif = c(0.01, 0.05, 0.1), doplot = TRUE) urzaTest(x, model = c("intercept", "trend", "both"), lag, doplot = TRUE)
urdfTest(x, lags = 1, type = c("nc", "c", "ct"), doplot = TRUE) urersTest(x, type = c("DF-GLS", "P-test"), model = c("constant", "trend"), lag.max = 4, doplot = TRUE) urkpssTest(x, type = c("mu", "tau"), lags = c("short", "long", "nil"), use.lag = NULL, doplot = TRUE) urppTest(x, type = c("Z-alpha", "Z-tau"), model = c("constant", "trend"), lags = c("short", "long"), use.lag = NULL, doplot = TRUE) urspTest(x, type = c("tau", "rho"), pol.deg = c(1, 2, 3, 4), signif = c(0.01, 0.05, 0.1), doplot = TRUE) urzaTest(x, model = c("intercept", "trend", "both"), lag, doplot = TRUE)
doplot |
[ur*Test] - |
lag.max |
[urersTest] - |
lag |
[urzaTest] - |
lags |
[urkpssTest][urppTest] - |
model |
[urersTest] - |
pol.deg |
[urspTest] - |
signif |
[urspTest] - |
type |
[urkpssTest] - |
use.lag |
[urkpssTest] - |
x |
a numeric vector or time series object. |
Unit Root Tests from Berhard Pfaff's "urca" Package:
Elliott-Rothenberg-Stock Test for Unit Roots:
To improve the power of the unit root test, Elliot, Rothenberg and
Stock proposed a local to unity detrending of the time series. ERS
developed a feasible point optimal test, "P-test"
, which
takes serial correlation of the error term into account. The second
test type is the "DF-GLS"
test, which is an ADF-type test
applied to the detrended data without intercept. Critical values
for this test are taken from MacKinnon in case of model="constant"
and else from Table 1 of Elliot, Rothenberg and Stock. [urca:ur.ers]
KPSS Test for Unit Roots:
Performs the KPSS unit root test, where the Null hypothesis is
stationarity. The test types specify as deterministic component
either a constant "mu"
or a constant with linear trend
"tau"
. lags="short"
sets the number of lags to
root 4 of [4 times (n/100), whereas lags="long"
sets the number of lags to root 4 of [12 times (n/100)].
If lags="nil"
is choosen, then no error correction is made.
Furthermore, one can specify a different number of maximum lags
by setting use.lag accordingly. [urca:ur.kpss]
Phillips-Perron Test for Unit Roots:
Performs the Phillips and Perron unit root test. Beside the
Z statistics Z-alpha and Z-tau, the Z statistics for the
deterministic part of the test regression are computed, too.
For correction of the error term a Bartlett window is used. [urca:ur.pp]
Schmidt-Phillips Test for Unit Roots:
Performs the Schmidt and Phillips unit root test, where under
the Null and Alternative Hypothesis the coefficients of the
deterministic variables are included. Two test types are available:
the "rho-test"
and the "tau-test"
. Both tests are
extracted from the LM principle. [urca:ur.sp]
Zivot-Andrews Test for Unit Roots:
Performs the Zivot and Andrews unit root test, which allows a
break at an unknown point in either the intercept, the linear
trend or in both. This test is based upon the recursive estimation
of a test regression. The test statistic is defined as the
minimum t-statistic of the coeffcient of the lagged endogenous
variable. [urca:ur.za]
All tests return an object of class "fHTEST"
with the
following slots:
@call |
the function call. |
@data |
a data frame with the input data. |
@data.name |
a character string giving the name of the data frame. |
@test |
a list object which holds the output of the underlying test function. |
@title |
a character string with the name of the test. |
@description |
a character string with a brief description of the test. |
The entries of the @test
slot include the following components:
$statistic |
the value of the test statistic. |
$parameter |
the lag order. |
$p.value |
the p-value of the test. |
$method |
a character string indicating what type of test was performed. |
$data.name |
a character string giving the name of the data. |
$alternative |
a character string describing the alternative hypothesis. |
$name |
the name of the underlying function, which may be wrapped. |
$output |
additional test results to be printed. |
The functions ur*Test()
fullfill the naming conventions
of Rmetrics, return an S4 object named fHTEST
as any other
hypothesis test from Rmetrics, and allow for timeSeries
objects
as input. These are the only differences to the original implementation
of the functions.
Fur further details we refer to the manual pages of the urca package which is required for all these.
Bernhard Pfaff for the tests implemented in R's "urca" package,
Diethelm Wuertz for the Rmetrics R-port.
Banerjee A., Dolado J.J., Galbraith J.W., Hendry D.F. (1993); Cointegration, Error Correction, and the Econometric Analysis of Non-Stationary Data, Oxford University Press, Oxford.
Dickey, D.A., Fuller, W.A. (1979); Distribution of the estimators for autoregressive time series with a unit root, Journal of the American Statistical Association 74, 427–431.
Kwiatkowski D., Phillips P.C.B, Schmidt P., Shin Y. (1992); Testing the Null Hypothesis of Stationarity against the Alternative of a Unit Root, Journal of Econometrics 54, 159–178.
Perron P. (1988); Trends and Random Walks in Macroeconomic Time Series, Journal of Economic Dynamics and Control 12, 297–332.
Phillips P.C.B., Perron P. (1988); Testing for a unit root in time series regression, Biometrika 75, 335–346.
Said S.E., Dickey D.A. (1984); Testing for Unit Roots in Autoregressive-Moving Average Models of Unknown Order, Biometrika 71, 599–607.
Schwert G.W. (1989); Tests for Unit Roots: A Monte Carlo Investigation, Journal of Business and Economic Statistics 2, 147–159.
## Time Series # A time series which contains no unit-root: x <- rnorm(1000) # A time series which contains a unit-root: y <- cumsum(c(0, x)) ## ERS Test: if(require("urca")) { urersTest(x) urersTest(y) }
## Time Series # A time series which contains no unit-root: x <- rnorm(1000) # A time series which contains a unit-root: y <- cumsum(c(0, x)) ## ERS Test: if(require("urca")) { urersTest(x) urersTest(y) }