In Subsection 1.3 we briefly discussed diagnostics to
check for the correct specification of a time series model. There we
found for the lynx
data set that the nonlinear autoregressive
model of order one (2) is of too low order to capture
the linear correlation in the data. For practical flexible time series
modelling it is therefore necessary to allow for higher order
nonlinear autoregressive models (1).
Their estimation
and the selection of relevant lags will be discussed in this section.
To simplify notation, we introduce the vector of lagged variables
such that
(1) can be written as
|
The local linear estimator with
is derived from the weighted
minimization
Under suitable conditions which are listed in Subsection 2.2 the Nadaraya-Watson estimator (19) and local linear estimator (21) have an asymptotic normal distribution
The quantlets
regxestp
and
lregxestp
compute the Nadaraya-Watson
estimator (19) and local linear estimator
(21) for higher order autoregressions. They are called by
mh = regxestp(x{, h, K, v})
or
mh = lregxestp(x{, h, K, v})
with input variables
Since we found in Subsection 1.3 that a NAR(1) model is not sufficient to capture the dynamics of the lynx trappings, we compute and plot in the following quantlet the autoregression function for lag 1 and 2 for both estimators using the crude bandwidth of 20% of the data range. Note that you have to click on the graph and rotate it in order to see the regression surface.
library("smoother")
library("plot")
setsize(640,480)
; data preparation
lynx = read("lynx.dat")
lynxrows = rows(lynx)
lag1 = lynx[1:lynxrows-2] ; vector of first lag
lag2 = lynx[2:lynxrows-1] ; vector of second lag
y = lynx[3:lynxrows] ; vector of dep. var.
data = lag1~lag2~y
data = log(data)
; estimation
h = 0.2*(max(data[,1])-min(data[,1])) ; crude bandwidth
mh = regxestp(data,h) ; local constant estimation
mhlp = lregxestp(data,h) ; local constant estimation
; graphics
mhplot = createdisplay(1,1)
mh = setmask(mh,"surface","blue")
show(mhplot,1,1,data,mh) ; surface plot
setgopt(mhplot,1,1,"title",
"Nadaraya-Watson estimate -- ROTATE!")
mhlpplot = createdisplay(1,1)
mhlp = setmask(mhlp,"surface","red")
show(mhlpplot,1,1,data,mhlp) ; surface plot
setgopt(mhlpplot,1,1,"title",
"Local linear estimate -- ROTATE!")
Figures 9 and 10 show
three-dimensional plots of the observations and the estimated regression
function. In Figure 9 one can clearly see the problem of
boundary effects, i.e. in regions where are no or only few data
points the estimated function values may easily become erratic if the
bandwidth is too small. Therefore, a selected bandwidth may be
appropriate for regions with plenty of observations while
inappropriate elsewhere. As can be seen from Figure
10, this boundary problem turns out to be
worse for the local linear estimator where one observes a large
outlier for one grid point. Such terrible estimates happen if the
inversion in (20) is imprecise due to a too small
bandwidth. One then has to increase the bandwidth. Try the quantlet
flts08.xpl
with replacing in the crude bandwidth choice
the factor 0.2 by 2. Note that increasing the bandwidth makes the
estimated regression surfaces of the two estimators look flat and
closer to linearity, respectively. This, however, can increase the estimation
bias. Therefore, an appropriate bandwidth choice is important. It will
be discussed in the next section.
|
For comparing the quality of competing lag specifications, one needs an appropriate measure of fit, as for example the final prediction error (FPE)
![]() |
|||
![]() |
one obtains the
decomposition
In the literature mainly two approaches were suggested for estimating
the unknown
or variants thereof, namely
cross-validation (Vieu, 1994),
(Yao and Tong, 1994) or estimation of an asymptotic expression
of the
(Auestad and Tjøstheim, 1990),
(Tjøstheim and Auestad, 1994),
(Tschernig and Yang, 2000). Given Assumptions (A1) to
(A6),
Tschernig and Yang (2000, Theorem 2.1) showed that
for the local constant estimator,
, and the local linear estimator,
, one has
where
| (31) |
From (28) it is possible to determine the
asymptotically optimal bandwidth
by minimizing the
asymptotic MISE, i.e. solving the
variance-bias tradeoff between
and
. The asymptotically
optimal bandwidth is given by
In order to obtain the plug-in bandwidth
one has to
estimate the unknown constants
and
. A local linear estimate of
(29) is obtained from
denoting the geometric mean of the standard deviation of the
regressors.
For the local linear estimator (21),
(30) can be consistently estimated by
![]() |
(34) |
![]() |
|||
The plug-in bandwidth
is then given by
In order to select the adequate lag vector, one computes
(38) for all possible lag combinations with
and chooses the lag vector with the smallest
. Given
Assumptions (A1) to (A7) and a further technical condition,
Tschernig and Yang (2000, Theorem 3.2)
showed that this procedure is weakly consistent, i.e. the probability of choosing the correct lag vector if it is included
in the set of lags considered approaches one with increasing sample
size. This consistency result may look surprising since the linear FPE
is known to be inconsistent. However, in the present case the rate of
the penalty term in (38) depends on the number of
lags
. Thus, if one includes
lags in addition to
correct
ones, the rate of the penalty term becomes slower which implies that
too large models are ruled out asymptotically. Note that this feature
is intrinsic to the local estimation approach since the number of lags
influence the rate of convergence, see (22). We remark that the consistency
result breaks down if Assumption (A7) is violated e.g. if the
stochastic process is linear. In this case overfitting (including
superfluous lags in addition to the correct ones) is more likely. The
breakdown of consistency can be avoided if one uses the
Nadaraya-Watson instead of the local linear estimator since the former
is also biased in case of linear processes.
Furthermore, Tschernig and Yang (2000) show that asymptotically it is more likely to overfit than to underfit (miss some correct lags). In order to reduce overfitting and therefore increase correct fitting, they suggest to correct the AFPE and estimate the Corrected Asymptotic FPE
We note that if one allows the maximal lag
to grow with sample
size, then one has a doubled nonparametric problem of nonparametric
function estimation and nonparametric lag selection.
The nonparametric lag selection criterion
can be computed
using the quantlet
tp/cafpe/cafpe. The quantlet
tp/cafpe/cafpefull
also allows to use
. Both are part
of the third party quantlib
tp/cafpe/cafpe
which contains various quantlets for lag and bandwidth
selection for nonlinear autoregressive models (16).
The quantlet
tp/cafpe/cafpe
is called as
{crmin, crpro} = cafpe(y, truedat, xdataln, xdatadif,
xdatastand, lagmax, searchmethod, dmax)
with the input variables:
For computing
TY follow
Tjøstheim and Auestad (1994) and implement two additional
features for robustification. For estimating
the kernel estimator
If one is only interested in computing the plug-in bandwidth
, then one can directly use the quantlet
tp/cafpe/hoptest. However, before it can be called it requires to
prepare the time series accordingly so that it is easier to run the
lag selection which automatically delivers the plug-in bandwidth for
the chosen lag vector as well. For the definition of its variables the
reader is referred to the helpfile of
tp/cafpe/hoptest.
We are now ready to run the quantlet
tp/cafpe/cafpe
on the
lynx data set. The following quantlet conducts a full search among the
first six lags
pathcafpe = "tp/cafpe/" ; path of CAFPE quantlets
; load required quantlibs
library("xplore")
library("times")
func(pathcafpe + "cafpeload") ; load XploRe files of CAFPE
cafpeload(pathcafpe)
setenv("outheadline","") ; no header for each output file
setenv("outlineno","") ; no numbering of output lines
; set parameters
truedat = "lynx.dat" ; name of data file
y = 0
xdataln = "yes"; ; take logarithms
xdatadif = "no"; ; don't take first differences
xdatastand = "no"; ; don't standardize data
lagmax = 6 ; the largest lag considered is 6
searchmethod = "full" ; consider all possible lag comb.
dmax = 6 ; consider at most 6 lags
; conduct lag selection
{ crmin,crpro } = cafpe(y,truedat,xdataln,xdatadif,xdatastand,
lagmax,searchmethod,dmax)
"selected lag vector, estimated CAFPE "
crmin[,1:dmax+1]
"number of lags, chosen lag vector, estimated CAFPE,
plug-in bandwidth"
(0:dmax)~crpro[,1:dmax|(dmax+4)|(dmax+1)]
|
{hplugin,hB,hC,xs,resid} = plotloclin(xdata,xresid,xdataln,
xdatadif,xdatastand,volat,lags,h,xsconst,
gridnum,gridmax,gridmin)
with the input variables
Figure 12 shows the plot of the conditional
mean function for an NAR(2) model of the lynx data on a grid covering
all observations. The autocorrelation function of the residuals is
shown in Figure 13. These graphs and a
plot of the standardized residuals are computed with the following
quantlet. It also returns the Jarcque-Bera test statistic of 2.31 with
-value of 0.32.
pathcafpe = "tp/cafpe/" ; path of CAFPE quantlets
; load required quantlibs
library("xplore")
library("times")
func("jarber")
func(pathcafpe + "cafpeload"); load XploRe files of CAFPE
cafpeload(pathcafpe)
setenv("outheadline","") ; no header for each output file
setenv("outlineno","") ; no numbering of output lines
; set parameters
lynx = read("lynx.dat");
xresid = 0
xdataln = "yes"; ; take logarithms
xdatadif = "no"; ; don't take first differences
xdatastand = "no"; ; don't standardize data
lags = 1|2 ; lag vector for regression function
h = 0
xsconst = 1e-100|1e-100 ; 1e-100 for the lags which are
; varied for those kept fixed it
; includes the chosen constant
gridnum = 30 ; number of gridpoints in one dir.
gridmax = 9 ; maximum of grid
gridmin = 4 ; minimum of grid
; compute opt. bandwidth and plot regression fct. for given lags
{ hplugin,hB,hC,xs,resid } = plotloclin(lynx,xresid,xdataln,
xdatadif,xdatastand,volat,lags,h,
xsconst,gridnum,gridmax,gridmin)
"plug-in bandwidth" hplugin
; diagnostics
acfplot(resid) ; compute and plot acf of residuals
{jb,probjb,sk,k} = jarber(resid,1)
; compute Jarque-Bera test for normality of residuals
|
So far we have considered the estimation and lag selection for the
conditional mean function
. Finally, we turn our
attention to modelling the function of the conditional standard
deviation
. The conditional standard deviation
plays an important role in financial modelling, e.g. for computing
option prices. As an example we consider 300 logged observations
dmus58-300
of a 20 minutes spaced sample of the
Deutschemark/US-Dollar exchange rate. Figures 14
and 15 display the logged observations and its
first differences. The figures are generated with the quantlet
library("plot")
library("times")
setsize(640,480)
fx = read("dmus58-300.dat"); read data
d1 = createdisplay(1,1)
x1 = #(1:300)~fx
setmaskl (x1, (1:rows(x1))', 0, 1)
show(d1,1,1,x1) ; plot data
setgopt(d1,1,1,"title",
"20 min. spaced sample of DM/US-Dollar rate")
setgopt(d1,1,1,"xlabel","Periods","ylabel","levels")
d2 = createdisplay(1,1)
x2 = #(2:300)~tdiff(fx)
setmaskl (x2, (1:rows(x2))', 0, 1)
show(d2,1,1,x2) ; plot data
setgopt(d2,1,1,"title","20 min. spaced sample of
DM/US-Dollar rate - first differences")
setgopt(d2,1,1,"xlabel","Periods","ylabel","first differences")
In the following we assume that the conditional mean function
is known and subtracted from
. Thus, we obtain
. After squaring (16) and
rearranging we have
is a necessary condition for applying
{crmin,crpro,crstore,crstoreadd,hstore,hstoretest} =
cafpefull(y,truedat,xresid,trueres,xdataln,xdatadif,xdatastand,
lagmax,volat,searchmethod,dmax,selcrit,robden,perA,
perB,startval,noutputf,outpath)
and has input variables
The quantlet
flts12.xpl
(for brevity not shown) conducts a lag
selection for the conditional mean function
and
finds lag 1 and 3 with bandwidth
.
If you run the quantlet, you will obtain the
XploRe
warning
``quantlet fvllc: inversion in local linear estimator did not work
because probably the bandwidth is too small''. This means that
for one of the checked combinations of lags, one of the rule-of-thumb
bandwidths or the plug-in bandwidth was too small so that the
matrix
in the local linear estimator (21)
is near singular and the matrix inversion failed. In this case, the
relevant bandwidth is doubled (at most 30 times) until the near
singularity disappears.
Therefore, lag selection for the conditional volatility function
is done with replacing the observations
in model (41) by the estimated residuals
. The computations are carried out with the
following quantlet which also generates a plot of the conditional mean
function on the range
displayed in Figure
16 and plots the autocorrelation function of
the residuals (not shown). The latter plot does not show significant
autocorrelation.
pathcafpe = "tp/cafpe/" ; path of CAFPE quantlets
; load required quantlibs
library("xplore")
library("times")
func("jarber")
func(pathcafpe + "cafpeload") ;load XploRe files of CAFPE
cafpeload(pathcafpe)
; set output format
setenv("outheadline","") ; no header for each output file
setenv("outlineno","") ; no numbering of output lines
; load data
x = read("dmus58-300.dat") ; name of data file
y = tdiff(x) ; compute first differences
xresid = 0
truedat = "" ; name of potential data file
trueres = "" ; name of potential residuals file
xdataln = "no" ; don't take logarithms
xdatadif = "no" ; don't take first differences
xdatastand = "no" ; don't standardize data
lagmax = 6 ; the largest lag considered is 6
searchmethod = "full" ; consider all possible lag comb.
dmax = 6 ; consider at most 6 lags
volat = "no" ; plot cond. mean function
selcrit = "lqcafpe" ; use CAFPE with plug-in bandwidth
robden = "yes" ; robustify density estimation
perA = 0
perB = 0.05 ; screen off data with lowest density
startval = "different"
noutputf = "" ; name of output file
outpath = "test" ; path for output file
lags = 1|3 ; lag vector for regression function
h = 0
xsconst = 1e-100|1e-100 ; 1e-100 for the lags which are
; varied for those kept fixed it
; includes the chosen constant
gridnum = 30 ; number of gridpoints in one direction
gridmax = 0.0015 ; maximum of grid
gridmin = -0.0015 ; minimum of grid
; compute optimal bandwidth and plot cond. mean for given lags
{ hplugin,hB,hC,xs,resid } = plotloclin(y,xresid,xdataln,
xdatadif,xdatastand,volat,lags,h,xsconst,gridnum,
gridmax,gridmin)
"plug-in bandwidth for conditional mean" hplugin
; diagnostics
acfplot(resid); compute and plot acf of residuals
{jb,probjb,sk,k} = jarber(resid,1)
; compute Jarque-Bera test for normality of residuals
; conduct lag selection for cond. standard deviation
xresid = resid
volat = "resid" ; conduct lat selection for cond. vol.
{crmin,crpro,crstore,crstoreadd,hstore,hstoretest}
= cafpefull(y,truedat,xresid,trueres,xdataln,
xdatadif,xdatastand,lagmax,volat,
searchmethod,dmax,selcrit,robden,
perA,perB,startval,noutputf,outpath)
"Lag selection for cond. standard deviation using residuals"
"selected lag vector, estimated CAFPE "
crmin[,1:dmax+1]
"number of lags, chosen lag vector, estimated CAFPE,
plug-in bandwidth"
(0:dmax)~crpro[,1:dmax|(dmax+4)|(dmax+1)]
pathcafpe = "tp/cafpe/" ; path of CAFPE quantlets
; load required quantlets
library("xplore")
library("times")
func("jarber")
func(pathcafpe + "cafpeload"); load XploRe files of CAFPE
cafpeload(pathcafpe)
setenv("outheadline","") ; no header for each output file
setenv("outlineno","") ; no numbering of output lines
; set parameters
x = read("dmus58-300.dat");
y = tdiff(x)
xresid = 0
xdataln = "no" ; don't take logarithms
xdatadif = "no" ; don't take first differences
xdatastand= "no" ; don't standardize data
volat = "no" ; compute cond. standard deviation
lags = 1|3 ; lag vector for regression function
h = 0 ; compute plug-in bandwidths
xsconst = 1e-100|1e-100
; 1e-100 for the lags which are varied
; for those kept fixed it includes the
; chosen constant
gridnum = 30 ; number of gridpoints in one direction
gridmax = 0.0015 ; maximum of grid
gridmin = -0.0015 ; minimum of grid
; compute optimal bandwidth and plot cond. mean for given lags
{ hplugin,hB,hC,xs,resid } = plotloclin(y,xresid,xdataln,
xdatadif,xdatastand,volat,lags,h,xsconst,gridnum,
gridmax,gridmin)
"plug-in bandwidth for mean" hplugin
; compute plug-in bandwidth and
; plot cond. standard deviation for given lags
lags = 2|6 ; lags for cond. volatility
xresid = resid
volat = "resid"
gridmax = 0.0008 ; maximum of grid
gridmin = -0.0008 ; minimum of grid
{ hplugin,hB,hC,xs,resid } = plotloclin(y,xresid,xdataln,
xdatadif,xdatastand,volat,lags,h,xsconst,gridnum,
gridmax,gridmin)
"plug-in bandwidth for conditional volatility" hplugin
; diagnostics
acfplot(resid); compute and plot acf of residuals
{jb,probjb,sk,k} = jarber(resid,1)
; compute Jarque-Bera test for normality of residuals
The surface plot of the conditional standard deviation is computed on
the range
in order to avoid boundary effects.
Inspecting the range of the standardized residuals in Figure
18 indicates that the analysis may be
strongly influenced by outliers which also may explain the extreme
increase of the conditional standard deviation in Figure
17 in one corner. Moreover, Figure
19 shows some significant
autocorrelation in the residuals. One explanation for this finding
could be the presence of long memory in the squared observations. This
topic is treated in detail in Chapter
. Therefore, one
should continue to improve the current function estimates by excluding
extreme observations and using models that allow for many lags in the
function of the conditional standard deviation such as, for example,
Yang, Härdle and Nielsen (1999).
|
|
![]() |
MD*TECH Method and Data Technologies |
| http://www.mdtech.de mdtech@mdtech.de |