Reference no: EM132255410
Time Series and Prediction Computing Homework - Questions
Q1. Write a function in R called "my.garch11.filter" to compute the 1-step ahead conditional variance of a GARCH(1,1) model as well as the log-likelihood. The GARCH(1,1) conditional variance is given by
σt2 = ω + αYt-12 + βσt-12
for t = 1 to T. To start the recursion σ12 is set equal to the sample variance of the time series {Yt}. The log-likelihood is defined
LT(θ) = -(T/2)log2π - ½t=1ΣTlogσt2 - ½t=1ΣT Yt2/σt2.
The function "my.garch11.filter"
- requires as input (in this order)
(a) vector containing the time series data Y1, . . . , YT
(b) vector of GARCH(1,1) parameter (ω, α, β)' (in this order)
- returns as output a list containing
(a) sig2: vector of GARCH(1,1) 1-step conditional variances σt2 for t = 1, . . . , T
(b) z: vector of GARCH(1,1) standardized innovations zt = Yt/√(σt2) for t = 1, . . . , T
(c) loglik: scalar log-likelihood
Q2. Write a function in R called "my.garch11.objective" to compute the GARCH(1,1) objective function to be minimized numerically by the R optimizer.
The function "my.garch11.objective"
- requires as inputs (in this order)
(a) vector containing the time series data Y1, . . . , YT
(b) vector of GARCH(1,1) filter parameters (ω, α, β)' (in this order)
- returns as output a the negative of the log-likelihood
The function has to perform these checks on the input parameter
(a) check if all the parameters of the param vector are finite (check the function is.finite in R)
(b) check if the parameters of the GARCH(1,1) satisfies the following constraints: ω > 0, α > 0, β > 0, α + β < 1.
If the vector of parameters fails to satisfy any of these conditions then the function should return "infinity" (Inf).
Q3. Write a function in R called "my.garch11.mle" to estimate the GARCH(1,1) parameters using the nlminb optimizer in R.
The function "my.garch11.mle"
- requires as inputs (in this order)
(a) vector containing the time series data Y1, . . . , YT
(b) a vector of initial values of the GARCH(1,1) parameter (ω, α, β)' (in this order)
- returns as output a vector containing the maximum likelihood estimate of the GARCH(1,1) parameters
The function "my.garch11.mle" has to minimise the objective function "my.garch11.objective" using the nlminb routine. When calling the nlminb routine makes sure that:
(a) You set the lower and upper bound of all the GARCH(1,1) parameters, respectively, to 10-4 and 1.
(b) You start the minimization from the initial value provided by the function.
It is highly recommended to check the help page of the nlminb function including the examples to understand how this function precisely works.
Q4. Write a function in R called "my.garch11.stderr" to estimate the GARCH(1,1) standard errors using numerical second order derivatives.
The function "my.garch11.stderr"
- requires as inputs (in this order)
(a) vector containing the time series data Y1, . . . , YT
(b) vector of containing the MLE estimates of the GARCH(1,1) parameters (ω, α, β)' (in this order)
(c) a scalar parameter h which is the step size used for the numerical approximation of the Hessian
- returns as output the vector of standard errors of the GARCH(1,1) parameters
The standard errors are computed using the asymptotic variance covariance matrix of the ML estimator based on the Hessian of the log-likelihood, that is,
(Var)^(θ^) = [-HT(θ^)]-1
where HT(θ^) is the Hessian evaluated at θ^.
The Hessian HT(θ^) is approximated numerically using finite differences. Let ∈ be defined as θ^h where θ^ is the ML estimator and h is the numerical step size. Let D be a 3x3 dimensional diagonal matrix whose diagonal is equal to ∈. Let ei denote a 3 dimensional vector with 1 in position i and zero otherwise. Then, the (I, j) entry of Ht(θ^) is approximated as
[HT(θ^)]i,j ≈ (LT(θ(1)) - LT(θ(2)) - LT(θ(3)) + LT(θ(4)))/4∈i∈j
where θ(1), θ(2), θ(3), θ(4) are defined as
θ(1) = θ^ + Dei + Dej
θ(2) = θ^ + Dei - Dej
θ(3) = θ^ - Dei + Dej
θ(4) = θ^ - Dei - Dej
Note - The R files attached contain codes for this assignment. The code is given in attached file to test the functions. The code is also used to evaluate the accuracy of the submission.
Attachment:- Assignment Files.rar