Spot volatility estimation
spotVol(
data,
method = "detPer",
...,
on = "minutes",
k = 5,
marketOpen = "09:30:00",
marketClose = "16:00:00",
tz = "GMT"
)
Can be one of two input types, xts
or data.table
. It is assumed that the input comprises prices in levels. Irregularly spaced
observations are allowed. They will be aggregated to the level specified by
parameters on
and k
.
specifies which method will be used to estimate the spot
volatility. Options include "detPer"
and "stochper"
.
See 'Details'.
method-specific parameters (see 'Details').
string indicating the time scale in which k
is expressed.
Possible values are: "secs", "seconds", "mins", "minutes", "hours"
.
positive integer, indicating the number of periods to aggregate
over. E.g. to aggregate an xts
object to the 5 minute frequency, set
k = 5
and on = "minutes"
.
the market opening time. This should be in the time zone
specified by tz
. By default, marketOpen = "09:30:00"
.
the market closing time. This should be in the time zone
specified by tz
. By default, marketClose = "16:00:00"
.
string specifying the time zone to which the times in data
and/or marketOpen
/ marketClose
belong. Default = "GMT"
.
A spotVol
object, which is a list containing one or more of the
following outputs, depending on the method used:
spot
An xts
or matrix
object (depending on the input) containing
spot volatility estimates \(\sigma_{t,i}\), reported for each interval
\(i\) between marketOpen
and marketClose
for every day
\(t\) in data
. The length of the intervals is specified by k
and on
. Methods that provide this output: All.
daily
An xts
or numeric
object (depending on the input) containing
estimates of the daily volatility levels for each day \(t\) in data
,
if the used method decomposed spot volatility into a daily and an intraday
component. Methods that provide this output: "detPer"
.
periodic
An xts
or numeric
object (depending on the input) containing
estimates of the intraday periodicity factor for each day interval \(i\)
between marketOpen
and marketClose
, if the spot volatility was
decomposed into a daily and an intraday component. If the output is in
xts
format, this periodicity factor will be dated to the first day of
the input data, but it is identical for each day in the sample. Methods that
provide this output: "detPer"
.
par
A named list containing parameter estimates, for methods that estimate one
or more parameters. Methods that provide this output:
"stochper", "kernel"
.
cp
A vector containing the change points in the volatility, i.e. the observation
indices after which the volatility level changed, according to the applied
tests. The vector starts with a 0. Methods that provide this output:
"piecewise"
.
ugarchfit
A ugarchfit
object, as used by the rugarch
package, containing all output from fitting the GARCH model to the data.
Methods that provide this output: "garch"
.
The spotVol
function offers several methods to estimate spot
volatility and its intraday seasonality, using high-frequency data. It
returns an object of class spotVol
, which can contain various outputs,
depending on the method used. See 'Details' for a description of each method.
In any case, the output will contain the spot volatility estimates.
The input can consist of price data or return data, either tick by tick or sampled at set intervals. The data will be converted to equispaced high-frequency returns \(r_{t,i}\) (read: the \(i\)th return on day \(t\)).
The following estimation methods can be specified in method
:
Deterministic periodicity method ("detPer"
)
Parameters:
dailyvol |
A string specifying the estimation method for the daily
component \(s_t\). Possible values are "bipower", "rv", "medrv" .
Default = "bipower" . |
periodicvol |
A string specifying the estimation method for the
component of intraday volatility, that depends in a deterministic way on the
intraday time at which the return is observed. Possible values are
"TML", "SD", "WSD", "OLS" . See Boudt et al. (2011) for details.
Default = "TML" . |
P1 |
A positive integer corresponding to the number of cosinus terms used in the flexible Fourier specification of the periodicity function, see Andersen et al. (1997) for details. Default = 5. |
P2 |
Same as P1 , but for the sinus terms. Default = 5. |
Outputs (see 'Value' for a full description of each component):
spot
daily
periodic
The spot volatility is decomposed into a deterministic periodic factor \(f_{i}\) (identical for every day in the sample) and a daily factor \(s_{t}\) (identical for all observations within a day). Both components are then estimated separately. For more details, see Taylor and Xu (1997) and Andersen and Bollerslev (1997). The jump robust versions by Boudt et al. (2011) have also been implemented.
Stochastic periodicity method ("stochper"
)
Parameters:
P1 |
A positive integer corresponding to the number of cosinus terms used in the flexible Fourier specification of the periodicity function. Default = 5. |
P2 |
Same as P1 , but for the sinus terms. Default = 5. |
init |
A named list of initial values to be used in the
optimization routine ("BFGS" in optim ). Default =
list(sigma = 0.03, sigma_mu = 0.005, sigma_h = 0.005, sigma_k = 0.05,
phi = 0.2, rho = 0.98, mu = c(2, -0.5), delta_c = rep(0, max(1,P1)),
delta_s = rep(0, max(1,P2))) .
See Beltratti & Morana (2001) for a definition
of each parameter. init can contain any number of these parameters.
For parameters not specified in init , the default initial value will
be used. |
Outputs (see 'Value' for a full description of each component):
spot
par
This method by Beltratti and Morana (2001) assumes the periodicity factor to
be stochastic. The spot volatility estimation is split into four components:
a random walk, an autoregressive process, a stochastic cyclical process and
a deterministic cyclical process. The model is estimated using a
quasi-maximum likelihood method based on the Kalman Filter. The package
FKF
is used to apply the Kalman filter. In addition to
the spot volatility estimates, all parameter estimates are returned.
Nonparametric filtering ("kernel"
)
Parameters:
type |
String specifying the type of kernel to be used. Options
include "gaussian", "epanechnikov", "beta" . Default = "gaussian" . |
h |
Scalar or vector specifying bandwidth(s) to be used in kernel.
If h is a scalar, it will be assumed equal throughout the sample. If
it is a vector, it should contain bandwidths for each day. If left empty,
it will be estimated. Default = NULL . |
est |
String specifying the bandwidth estimation method. Possible
values include "cv", "quarticity" . Method "cv" equals
cross-validation, which chooses the bandwidth that minimizes the Integrated
Square Error. "quarticity" multiplies the simple plug-in estimator
by a factor based on the daily quarticity of the returns. est is
obsolete if h has already been specified by the user. Default =
"cv" . |
lower |
Lower bound to be used in bandwidth optimization routine, when using cross-validation method. Default is \(0.1n^{-0.2}\). |
upper |
Upper bound to be used in bandwidth optimization routine, when using cross-validation method. Default is \(n^{-0.2}\). |
Outputs (see 'Value' for a full description of each component):
spot
par
This method by Kristensen (2010) filters the spot volatility in a nonparametric way by applying kernel weights to the standard realized volatility estimator. Different kernels and bandwidths can be used to focus on specific characteristics of the volatility process.
Estimation results heavily depend on the bandwidth parameter \(h\), so it is important that this parameter is well chosen. However, it is difficult to come up with a method that determines the optimal bandwidth for any kind of data or kernel that can be used. Although some estimation methods are provided, it is advised that you specify \(h\) yourself, or make sure that the estimation results are appropriate.
One way to estimate \(h\), is by using cross-validation. For each day in
the sample, \(h\) is chosen as to minimize the Integrated Square Error,
which is a function of \(h\). However, this function often has multiple
local minima, or no minima at all (\(h -> \infty\)). To ensure a reasonable
optimum is reached, strict boundaries have to be imposed on \(h\). These
can be specified by lower
and upper
, which by default are
\(0.1n^{-0.2}\) and \(n^{-0.2}\) respectively, where \(n\) is the
number of observations in a day.
When using the method "kernel"
, in addition to the spot volatility
estimates, all used values of the bandwidth \(h\) are returned.
Piecewise constant volatility ("piecewise"
)
Parameters:
type |
String specifying the type of test to be used. Options
include "MDa", "MDb", "DM" . See Fried (2012) for details. Default =
"MDa" . |
m |
Number of observations to include in reference window.
Default = 40 . |
n |
Number of observations to include in test window.
Default = 20 . |
alpha |
Significance level to be used in tests. Note that the test
will be executed many times (roughly equal to the total number of
observations), so it is advised to use a small value for alpha , to
avoid a lot of false positives. Default = 0.005 . |
volest |
String specifying the realized volatility estimator to be
used in local windows. Possible values are "bipower", "rv", "medrv" .
Default = "bipower" . |
online |
Boolean indicating whether estimations at a certain point
\(t\) should be done online (using only information available at
\(t-1\)), or ex post (using all observations between two change points).
Default = TRUE . |
Outputs (see 'Value' for a full description of each component):
spot
cp
This nonparametric method by Fried (2012) assumes the volatility to be piecewise constant over local windows. Robust two-sample tests are applied to detect changes in variability between subsequent windows. The spot volatility can then be estimated by evaluating regular realized volatility estimators within each local window.
Along with the spot volatility estimates, this method will return the
detected change points in the volatility level. When plotting a
spotVol
object containing cp
, these change points will be
visualized.
GARCH models with intraday seasonality ("garch"
)
Parameters:
model |
String specifying the type of test to be used. Options
include "sGARCH", "eGARCH" . See ugarchspec in the
rugarch package. Default = "eGARCH" . |
garchorder |
Numeric value of length 2, containing the order of
the GARCH model to be estimated. Default = c(1,1) . |
dist |
String specifying the distribution to be assumed on the
innovations. See distribution.model in ugarchspec for
possible options. Default = "norm" . |
solver.control |
List containing solver options.
See ugarchfit for possible values. Default = list() . |
P1 |
A positive integer corresponding to the number of cosinus terms used in the flexible Fourier specification of the periodicity function. Default = 5. |
P2 |
Same as P1 , but for the sinus terms. Default = 5. |
Outputs (see 'Value' for a full description of each component):
spot
ugarchfit
This method generates the external regressors needed to model the intraday
seasonality with a Flexible Fourier form. The rugarch
package
is then employed to estimate the specified GARCH(1,1) model.
Along with the spot volatility estimates, this method will return the
ugarchfit
object used by the rugarch
package.
Realized Measures ("RM"
)
Parameters:
RM |
String denoting which realized measure to use to estimate the local volatility. Possible values are: "bipower", "medrv", "minrv", "rv" Default = "bipower" |
lookBackPeriod |
positive integer denoting the amount of sub-sampled returns to use for the estimation of the local volatility. Default = 10. |
dontIncludeLast |
logical indicating whether to omit the last return in the calculation of the local volatility. This is done in e.g. Lee-Mykland (2008) to produce jump-robust estimates of spot volatility. Setting this to TRUE will then use lookBackPeriod - 1 returns in the construction of the realized measures. Default = FALSE |
Outputs (see 'Value' for a full description of each component):
spot
RM
lookBackPeriod
This method returns the estimates of the spot volatility, a string containing the realized measure used, and the lookBackPeriod.
(Non-overlapping) Pre-Averaged Realized Measures ("PARM"
)
Parameters:
RM |
String denoting which realized measure to use to estimate the local volatility. Possible values are: "bipower", "medrv", "minrv", "rv" Default = "BPV" |
lookBackPeriod |
positive integer denoting the amount of sub-sampled returns to use for the estimation of the local volatility. Default = 50. |
Outputs (see 'Value' for a full description of each component):
spot
RM
lookBackPeriod
kn
Andersen, T. G. and T. Bollerslev (1997). Intraday periodicity and volatility persistence in financial markets. Journal of Empirical Finance 4, 115-158.
Beltratti, A. and C. Morana (2001). Deterministic and stochastic methods for estimation of intraday seasonal components with high frequency data. Economic Notes 30, 205-234.
Boudt K., Croux C. and Laurent S. (2011). Robust estimation of intraweek periodicity in volatility and jump detection. Journal of Empirical Finance 18, 353-367.
Fried, Roland (2012). On the online estimation of local constant volatilities. Computational Statistics and Data Analysis 56, 3080-3090.
Kristensen, Dennis (2010). Nonparametric filtering of the realized spot volatility: A kernel-based approach. Econometric Theory 26, 60-93.
Taylor, S. J. and X. Xu (1997). The incremental volatility information in one million foreign exchange quotations. Journal of Empirical Finance 4, 317-340.
# NOT RUN {
# Default method, deterministic periodicity
vol1 <- spotVol(sampleReal5MinPrices)
plot(vol1)
# Compare to stochastic periodicity
# }
# NOT RUN {
init <- list(sigma = 0.03, sigma_mu = 0.005, sigma_h = 0.007,
sigma_k = 0.06, phi = 0.194, rho = 0.986, mu = c(1.87,-0.42),
delta_c = c(0.25, -0.05, -0.2, 0.13, 0.02),
delta_s = c(-1.2, 0.11, 0.26, -0.03, 0.08))
# next method will take around 110 iterations
vol2 <- spotVol(sampleReal5MinPrices, method = "stochper", init = init)
plot(as.numeric(vol1$spot[1:780]), type="l")
lines(as.numeric(vol2$spot[1:780]), col="red")
legend("topright", c("detPer", "stochper"), col = c("black", "red"), lty=1)
# }
# NOT RUN {
# Various kernel estimates
# }
# NOT RUN {
h1 <- bw.nrd0((1:nrow(sampleReal5MinPrices))*(5*60))
vol3 <- spotVol(sampleReal5MinPrices, method = "kernel", h = h1)
vol4 <- spotVol(sampleReal5MinPrices, method = "kernel", est = "quarticity")
vol5 <- spotVol(sampleReal5MinPrices, method = "kernel", est = "cv")
plot(vol3, length = 2880)
lines(as.numeric(t(vol4$spot))[1:2880], col = "red")
lines(as.numeric(t(vol5$spot))[1:2880], col = "blue")
legend("topright", c("h = simple estimate", "h = quarticity corrected",
"h = crossvalidated"), col = c("black", "red", "blue"), lty=1)
# }
# NOT RUN {
# Piecewise constant volatility
# }
# NOT RUN {
vol6 <- spotVol(sampleReal5MinPrices, method = "piecewise", m = 200, n = 100,
online = FALSE)
plot(vol6)
# }
# NOT RUN {
# Compare regular GARCH(1,1) model to eGARCH, both with external regressors
# }
# NOT RUN {
vol7 <- spotVol(sampleReal5MinPrices, method = "garch", model = "sGARCH")
vol8 <- spotVol(sampleReal5MinPrices, method = "garch", model = "eGARCH")
plot(as.numeric(t(vol7$spot)), type = "l")
lines(as.numeric(t(vol8$spot)), col = "red")
legend("topleft", c("GARCH", "eGARCH"), col = c("black", "red"), lty=1)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab