# [R-SIG-Finance] Newey-West Long-run variance

Jose Iparraguirre D'Elia Jose at erini.ac.uk
Tue Feb 24 12:54:20 CET 2009

```Thanks Matthieu. I had been poring over the sandwich library, but can't get around to estimating what I need.
Could you or any one else in the list help me with the following?
I am reproducing here Example 9 (Long-run variance of AR(1)) from Zivot and Wang (2001). They use the function asymp.var which unfortunately doesn't seem to be available in R (if anyone has an R code for this function, I'd be greatly appreciate it).
How can I replicate these results in R? In particular, the Newey-West estimate for the long-run variance of the series (=0.269)?
Perhaps the answer lies within the package sandwich, but I can't get through the crust enough to find any pleasure yet...
José

Example 9 - Long-run variance of AR(1)

Let yt be an AR(1) process created using

> set.seed(101)
> e = rnorm(100,sd=1)
> y.ar1 = 1 + arima.sim(model=list(ar=0.75),innov=e)

Here ψ(1) = 1/φ(1) = 1/1−φ

and

lrv(yt)= σ2/(1 − φ)2

For φ =0.75, σ2 =1, lrv(yt)=16 implies for T = 100 an asymptotic
standard error for ¯ y equal to SE(¯y)=0.40.If yt ~ WN(0, 1), then the
asymptotic standard error for ¯y is SE(¯y)=0.10.

lrvAR(yt) may be easily computed in S-PLUS using OLS to estimate the
AR(1) parameters:

> ar1.fit = OLS(y.ar1~ar(1))
> rho.hat = coef(ar1.fit)[2]
> sig2.hat = sum(residuals(ar1.fit)^2)/ar1.fit\$df.resid
> lrv.ar1 = sig2.hat/1-rho.hat)^2
> as.numeric(lrv.ar1)
[1] 13.75

Here lrvAR(yt)=13.75, and an estimate for SE(¯y) is SEAR(¯y)=0.371.

The S+FinMetrics function asymp.var may be used to compute the
nonparameteric Newey-West estimate lrvNW(yt). The arguments expected
by asymp.var are

> args(asymp.var)
function(x, bandwidth, window = "bartlett", na.rm = F)
where x is a “timeSeries”, bandwidth sets the truncation lag MT in (3.20)
and window specifies the weight function. Newey and West suggest setting
the bandwidth using the sample size dependent rule
MT =4(T/100)^2/9, which is equal to 4 in the present case.

The Newey-West long-run variance estimate is then
> lrv.nw = asymp.var(y.ar1, bandwidth=4)
> lrv.nw
[1] 7.238

and the Newey-West estimate of SE(¯y) is SENW(¯y)=0.269.

Reference:

Zivot, E. and Wang, J. (2002). Modelling Financial Time Series with
S-PLUS.

-----Original Message-----
From: Matthieu Stigler [mailto:matthieu.stigler at gmail.com]
Sent: 22 February 2009 18:03
To: Jose Iparraguirre D'Elia
Cc: r-sig-finance at stat.math.ethz.ch
Subject: Re: [R-SIG-Finance] Newey-West Long-run variance

see package sandwich

Jose Iparraguirre D'Elia a écrit :
> In S-plus + FinMetrics, there is a function (asymp.var) to compute the nonparametric Newey-West long-run variance of a time series (see example in Modelling Financial Time Series with S-PLUS by Eric Zivot and Jiahui Wang, Section 3.2.8).
> Is there a similar function in R? The NW estimator is used, for example, to obtain the variance as part of the Phillips-Perron unit root test in the tseries package, but how can that estimate be obtained? Has anyone written a code in R that does what asymp.var does in S-Plus? Regards,
> Jose
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>

```