Classic Estimator for the Hurst Effect
Functions to estimate the rescaled range (R/S) statistic and the Hurst coefficient. The estimator is based on the original work by Hurst (1951) and is included for historical reasons. Moreover, the estimator by the variance plot is also provided. The estimators are only recommended for illustration purposes.
LongMemory.ClassicEstimators — Module
ClassicEstimators
This module contains functions to estimate the Hurst coefficient, closely related to the long memory parameter, of a time series using the rescaled range (R/S) statistic.
Author
LongMemory.ClassicEstimators.andrews_bandwidth — Method
andrews_bandwidth(x::AbstractArray)Computes the data-dependent number of lags of Andrews (1991) for the Bartlett long-run variance estimator, based on an AR(1) approximation: floor((3T/2)^{1/3} |2ρ/(1-ρ²)|^{2/3}), where ρ is the first-order autocorrelation. Internal function used by lo_rs_test and vs_test.
References
Andrews, D. W. K. (1991). Heteroskedasticity and autocorrelation consistent covariance matrix estimation. Econometrica, 59(3), 817-858.
LongMemory.ClassicEstimators.autocorrelation — Function
autocorrelation(x::AbstractArray, k::Int=30)Computes the autocorrelation function of a time series at lags 0, 1, ..., k-1.
Arguments
x::Array: The time series.k::Int: The number of lags (including lag 0). Default is 30.
Output
acf::Array: The autocorrelation function.
Notes
To plot the autocorrelation function use autocorrelation_plot.
Examples
julia> autocorrelation(randn(100), 10)LongMemory.ClassicEstimators.autocorrelation_plot — Method
autocorrelation_plot(x::AbstractArray, k::Int)Computes the autocorrelation function of a time series.
Requires Plots.jl to be loaded, e.g. with using LongMemory, Plots.
Arguments
x::Array: The time series.k::Int: The lag of the autocorrelation.
Output
p1::Plots.Plot: The autocorrelation function.
Examples
julia> autocorrelation_plot(randn(100), 10)LongMemory.ClassicEstimators.autocovariance — Method
autocovariance(x::AbstractArray, k::Int)Computes the autocovariance of a time series at lags 0, 1, ..., k-1.
Arguments
x::Array: The time series.k::Int: The number of lags (including lag 0).
Output
acv::Array: The autocovariances at lags 0, ...,k-1.
Examples
julia> autocovariance(randn(100), 2)LongMemory.ClassicEstimators.bartlett_lrv — Method
bartlett_lrv(x::AbstractArray, q::Int)Computes the Bartlett (Newey-West) estimator of the long-run variance of x with q lags. Internal function used by lo_rs_test and vs_test.
LongMemory.ClassicEstimators.brownian_bridge_range_cdf — Method
brownian_bridge_range_cdf(v::Real)Distribution function of the range of a Brownian bridge (Kuiper's distribution), 1 + 2 Σ_{k≥1} (1 - 4k²v²) exp(-2k²v²). Internal function used by lo_rs_test.
LongMemory.ClassicEstimators.brownian_bridge_variance_cdf — Method
brownian_bridge_variance_cdf(x::Real)Distribution function of the variance of a Brownian bridge, 1 + 2 Σ_{k≥1} (-1)^k exp(-2k²π²x). Internal function used by vs_test.
LongMemory.ClassicEstimators.dfa_est — Method
dfa_est(x::AbstractArray; k::Int = 20)Estimates the long memory parameter of a time series using detrended fluctuation analysis (DFA).
Arguments
x::Array: The time series.
Optional arguments
k::Int: The number of box sizes, log-spaced between 10 andT/4. Default is 20.
Output
d::Real: The estimated long memory parameter.
Notes
The profile (the cumulative sum of the demeaned series) is split into non-overlapping boxes of size n, a linear trend is fitted by OLS in each box, and the fluctuation F(n) is the root mean squared residual. The slope α of the regression of log F(n) on log n estimates the Hurst coefficient H = d + 1/2, so d = α - 1/2. See dfa_fluctuation for the fluctuation function.
References
Peng, C.-K., Buldyrev, S. V., Havlin, S., Simons, M., Stanley, H. E., and Goldberger, A. L. (1994). Mosaic organization of DNA nucleotides. Physical Review E, 49(2), 1685-1689.
Examples
julia> dfa_est(randn(500))LongMemory.ClassicEstimators.dfa_fluctuation — Method
dfa_fluctuation(x::AbstractArray; k::Int = 20)Computes the fluctuation function of detrended fluctuation analysis (DFA) with linear detrending.
Arguments
x::Array: The time series.
Optional arguments
k::Int: The number of box sizes, log-spaced between 10 andT/4. Default is 20.
Output
nt::Array: The box sizes.F::Array: The fluctuation function at the box sizes.
Examples
julia> dfa_fluctuation(randn(500))LongMemory.ClassicEstimators.dfa_plot — Method
dfa_plot(x::AbstractArray; k::Int = 20, slope::Bool = false, slope2::Bool = false)Produces the detrended fluctuation analysis (DFA) plot of a time series.
Requires Plots.jl to be loaded, e.g. with using LongMemory, Plots.
Arguments
x::Array: The time series.
Output
p1::Plots.Plot: The DFA plot.
Optional arguments
k::Int: The number of box sizes. Default is 20.slope::Bool: If true, the slope of the linear regression is displayed.slope2::Bool: If true, the theoretical slope for a short memory process is displayed.
Notes
The slope of the regression estimates the Hurst coefficient H = d + 1/2. See dfa_est.
Examples
julia> dfa_plot(randn(500))LongMemory.ClassicEstimators.lo_rs_test — Method
lo_rs_test(x::AbstractArray; q::Int = andrews_bandwidth(x))Computes Lo's (1991) modified rescaled range test of the null hypothesis of short memory.
Arguments
x::Array: The time series.
Optional arguments
q::Int: The number of lags in the Bartlett estimator of the long-run variance. By default, it is chosen with the data-dependent rule of Andrews (1991) as suggested by Lo (1991), seeandrews_bandwidth.
Output
V::Real: The test statistic,R / (σ̂(q) √T), whereRis the range of the partial sums of the demeaned series andσ̂²(q)the Bartlett estimator of the long-run variance.pval::Real: The two-sided p-value from the asymptotic distribution under the null, the range of a Brownian bridge.
Notes
Under the null of short memory, V converges to the range of a Brownian bridge, with 2.5% and 97.5% quantiles 0.809 and 1.862. Large values of V indicate long memory and small values antipersistence. In contrast to the classic R/S statistic, the test is robust to short-range dependence through the long-run variance estimator.
References
Lo, A. W. (1991). Long-term memory in stock market prices. Econometrica, 59(5), 1279-1313.
Examples
julia> lo_rs_test(randn(500))LongMemory.ClassicEstimators.log_variance_est — Method
log_variance_est(x::AbstractArray; m::Int=100)Computes the long memory estimate using the log-variance.
Arguments
x::Array: The time series.
Output
d_var::Real: The estimated long memory parameter computed as (beta+1)/2, where beta is the slope of the linear regression of the log-variance plot.
Optional arguments
m::Int: The number of partitions of the time series. Default is 100. A value of m ≈ length(x)/2 is recommended.
Notes
This function uses the linear regression method on the log-variance to estimate the long memory parameter.
Examples
julia> log_variance_est(randn(100,1); m = 40)LongMemory.ClassicEstimators.log_variance_plot — Method
log_variance_plot(x::AbstractArray; m::Int=100, slope::Bool=false, slope2::Bool=false)Produces the log-variance plot of a time series.
Requires Plots.jl to be loaded, e.g. with using LongMemory, Plots.
Arguments
x::Array: The time series.
Output
p1::Plots.Plot: The log-variance plot.
Optional arguments
m::Int: The number of partitions of the time series. Default is 100. A value of m ≈ length(x)/2 is recommended.slope::Bool: If true, the slope of the linear regression is displayed.slope2::Bool: If true, the theoretical slope for a short memory process is displayed.
Notes
This function uses the linear regression method on the log of the variance plot to estimate the long memory parameter.
Examples
julia> log_variance_plot(randn(100,1); m = 40)LongMemory.ClassicEstimators.rescaled_range — Method
rescaled_range(x::AbstractArray; k::Int = 20)Computes the rescaled range (R/S) statistic of a time series on the subsamples x[1:n] for an increasing grid of n.
Arguments
x::Array: The time series.
Optional arguments
k::Int: The number of partitions of the time series. Default is 20.
Output
RS::Array: The rescaled range statistic.
Examples
julia> rescaled_range(randn(100))LongMemory.ClassicEstimators.rescaled_range_est — Method
rescaled_range_est(x::AbstractArray; k::Int = 20)Estimates the long memory parameter of a time series using the rescaled range (R/S) statistic.
Arguments
x::Array: The time series.
Output
d::Real: The estimated long memory parameter.
Optional arguments
k::Int: The number of partitions of the time series. Default is 20.
Notes
This function uses the linear regression method on the log of the rescaled range to estimate the long memory parameter. The Hurst coefficient is related to the long memory parameter d by the formula H = d + 1/2.
Examples
julia> rescaled_range_est(randn(100))LongMemory.ClassicEstimators.rescaled_range_plot — Method
rescaled_range_plot(x::AbstractArray; k::Int = 100, slope::Bool = false, slope2::Bool = false)Produces the rescaled range plot of a time series.
Requires Plots.jl to be loaded, e.g. with using LongMemory, Plots.
Arguments
x::Array: The time series.
Output
p1::Plots.Plot: The rescaled range plot.
Optional arguments
k::Int: The number of partitions of the time series. Default is 100.slope::Bool: If true, the slope of the linear regression is displayed.slope2::Bool: If true, the theoretical slope for a short memory process is displayed.
Notes
This function uses the linear regression method on the log of the rescaled range to estimate the long memory parameter. The Hurst coefficient is related to the long memory parameter d by the formula H = d + 1/2.
Examples
julia> rescaled_range_plot(randn(300,1))LongMemory.ClassicEstimators.smean — Method
smean(x::AbstractArray)Computes the sample mean of a time series.
Arguments
x::Array: The time series.
Output
mean::Real: The sample mean.
Examples
julia> smean(randn(100))LongMemory.ClassicEstimators.sstd — Method
sstd(x::AbstractArray; k::Int=0)Computes the sample standard deviation of a time series.
Arguments
x::Array: The time series.
Output
std::Real: The sample standard deviation.
Optional arguments
k::Int: The bias-correction term.
Notes
This function divides by T instead of T-1 if no bias-correction term is provided.
Examples
julia> sstd(randn(100))LongMemory.ClassicEstimators.sstdk — Method
sstdk(x::AbstractArray, m::Int)Computes the sample variance of the means of the non-overlapping blocks of size m of a time series.
Arguments
x::Array: The time series.m::Int: The block size.
Output
s2k::Real: The sample variance of the block means.
Notes
Only complete blocks are used, i.e. the last length(x) % m observations are discarded.
Examples
julia> sstdk(randn(100), 20)LongMemory.ClassicEstimators.vs_test — Method
vs_test(x::AbstractArray; q::Int = andrews_bandwidth(x))Computes the V/S test of Giraitis, Kokoszka, Leipus and Teyssière (2003) of the null hypothesis of short memory.
Arguments
x::Array: The time series.
Optional arguments
q::Int: The number of lags in the Bartlett estimator of the long-run variance. By default, it is chosen with the data-dependent rule of Andrews (1991), seeandrews_bandwidth.
Output
M::Real: The test statistic, the sample variance of the partial sums of the demeaned series divided byT σ̂²(q).pval::Real: The p-value from the asymptotic distribution under the null.
Notes
Under the null of short memory, M converges to the variance of a Brownian bridge, with distribution function 1 + 2 Σ_{k≥1} (-1)^k exp(-2k²π²x). The 5% critical value is 0.1869; large values indicate long memory. The test is a modification of the KPSS test that uses the variance of the partial sums instead of their second moment, which makes it more sensitive to shifts in the variance of the partial sums.
References
Giraitis, L., Kokoszka, P., Leipus, R., and Teyssière, G. (2003). Rescaled variance and related tests for long memory in volatility and levels. Journal of Econometrics, 112(2), 265-294.
Examples
julia> vs_test(randn(500))Hurst, H.E. (1951). Long-term storage capacity of reservoirs. Transactions of the American Society of Civil Engineers, 116, 770-799.
Documentation for LongMemory.jl.