| Title: | Time-Varying Garch Models Through a State-Space Representation |
|---|---|
| Description: | Estimates the time-varying (tv) parameters of the GARCH(1,1) model, enabling the modeling of non-stationary volatilities by allowing the model parameters to change gradually over time. The estimation and prediction processes are facilitated through the application of the Kalman filter and state-space equations. This package supports the estimation of tv parameters for various deterministic functions, which can be identified through exploratory analysis of different time periods or segments of return data. The methodology is grounded in the framework presented by Ferreira et al. (2017) <doi:10.1080/00949655.2017.1334778>. |
| Authors: | Guillermo Ferreira [aut], Tomás Arancibia [aut, cre] |
| Maintainer: | Tomás Arancibia <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.0.1 |
| Built: | 2026-06-10 08:50:17 UTC |
| Source: | https://github.com/tomas-udec/tvgarchkf |
The data covers the period from March 2000 to October 2014, totaling 3186 observations.
indipsaindipsa
A time series object with 3186 elements
It's a stock market index that tracks the performance of a select group of Chilean companies.
Yahoo Finance
Simulate from a tv-Garch(1,1) model.
tvGarch_Sim( n, gamma, alpha, beta, type = c("polynomial", "NoLineal", "trigonometric"), exponentes = NULL, trig = NULL, arg = NULL )tvGarch_Sim( n, gamma, alpha, beta, type = c("polynomial", "NoLineal", "trigonometric"), exponentes = NULL, trig = NULL, arg = NULL )
n |
integer |
gamma |
Vector containing coefficents of c. |
alpha |
Vector containing coefficents of alpha. |
beta |
Vector containing coefficents of beta. |
type |
Vector of function type for c, alpha and beta. |
exponentes |
Vector for exponenets in NoLineal. |
trig |
Type of trigonometric function. |
arg |
Value of argument for the trigonometric function. |
An object of class 'zoo' with two components: the first component represents returns, while the second component denotes conditional variance.
## Simulate from a tv-GARCH(1,1) model lineal: alpha_sim <- c(0.2, 0.2) beta_sim <- c(0.45, 0.5, -0.85) type_sim <- c("polynomial","polynomial","polynomial") Sim1 <- tvGarch_Sim(n = 6000, gamma = 0.1, alpha = alpha_sim, beta = beta_sim, type = type_sim) plot(Sim1[,1], type="l", main="Simulated tvGARCH(1, 1) process", ylim=c(-max(Sim1[,2]), max(Sim1[,2]))) lines(Sim1[,2], type="l", col="red") legend("topright",legend=c("tvGARCH(1,1)",expression(sigma(u))), col=c("black","red"),lty=1,bty="n",lwd=1) ## Simulate from a tv-GARCH(1,1) model non linear: alpha_sim2 <- c(0.75, 0.08) beta_sim2 <- c(0.05, 0.03, 0.06) type_sim2 <- c("polynomial","polynomial","NoLineal") expo <- c(0, 1, 1/2) Sim2<-tvGarch_Sim(n=6000,gamma=0.05,alpha=alpha_sim2,beta=beta_sim2,type=type_sim2,exponentes=expo) plot(Sim2[,1], type="l", main="Simulated tvGARCH(1, 1) process", ylim=c(-max(Sim2[,2]),max(Sim2[,2]))) lines(Sim2[,2], type="l", col="red") legend("topright",legend=c("tvGARCH(1,1)",expression(sigma(u))), col=c("black","red"),lty=1,bty="n",lwd=1)## Simulate from a tv-GARCH(1,1) model lineal: alpha_sim <- c(0.2, 0.2) beta_sim <- c(0.45, 0.5, -0.85) type_sim <- c("polynomial","polynomial","polynomial") Sim1 <- tvGarch_Sim(n = 6000, gamma = 0.1, alpha = alpha_sim, beta = beta_sim, type = type_sim) plot(Sim1[,1], type="l", main="Simulated tvGARCH(1, 1) process", ylim=c(-max(Sim1[,2]), max(Sim1[,2]))) lines(Sim1[,2], type="l", col="red") legend("topright",legend=c("tvGARCH(1,1)",expression(sigma(u))), col=c("black","red"),lty=1,bty="n",lwd=1) ## Simulate from a tv-GARCH(1,1) model non linear: alpha_sim2 <- c(0.75, 0.08) beta_sim2 <- c(0.05, 0.03, 0.06) type_sim2 <- c("polynomial","polynomial","NoLineal") expo <- c(0, 1, 1/2) Sim2<-tvGarch_Sim(n=6000,gamma=0.05,alpha=alpha_sim2,beta=beta_sim2,type=type_sim2,exponentes=expo) plot(Sim2[,1], type="l", main="Simulated tvGARCH(1, 1) process", ylim=c(-max(Sim2[,2]),max(Sim2[,2]))) lines(Sim2[,2], type="l", col="red") legend("topright",legend=c("tvGARCH(1,1)",expression(sigma(u))), col=c("black","red"),lty=1,bty="n",lwd=1)
The tv-Garch(1,1) model, the parameters vary slowly over time according to linear or non-linear functions.
These parameters are denoted by , and which correspond to the model
.
tvGarchKalmanFit( series, c, alpha, beta, type = c("polynomial", "NoLineal", "trigonometric"), exponentes, trig, arg, predict = 0, trace.log = FALSE )tvGarchKalmanFit( series, c, alpha, beta, type = c("polynomial", "NoLineal", "trigonometric"), exponentes, trig, arg, predict = 0, trace.log = FALSE )
series |
Time series. |
c |
Vector containing coefficents of c. |
alpha |
Vector containing coefficents of alpha. |
beta |
Vector containing coefficents of beta. |
type |
Vector of function type for c, alpha and beta. |
exponentes |
Vector for exponenets in NoLineal. |
trig |
Type of trigonometric function. |
arg |
Value of argument for the trigonometric function. |
predict |
Value for time to generate predict. |
trace.log |
Variable to print names of coefficients. |
The types of functions for the tv-parameters are: linear, non-linear, trigonometric, and exponential. For the case of the linear model, the tv-parameters follow the following structure:
where , with .
For the non-linear case, it is as follows:
where it is positive value and , and are non linear function set.
For the trigonometric case, it is as follows:
where it is a trigonometric function, or .
Return fit values of omega, alpha and beta
ipsa<-diff(log(indipsa)) c <- c(0.05,0.05) alpha <- c(0.05,0.05) beta <- c(0.05,0.05) type_fit <- c("trigonometric","trigonometric","trigonometric") fit<-tvGarchKalmanFit(ipsa,c=c,alpha=alpha,beta=beta,type=type_fit,trig="cos",arg="3*(1-log(u))")ipsa<-diff(log(indipsa)) c <- c(0.05,0.05) alpha <- c(0.05,0.05) beta <- c(0.05,0.05) type_fit <- c("trigonometric","trigonometric","trigonometric") fit<-tvGarchKalmanFit(ipsa,c=c,alpha=alpha,beta=beta,type=type_fit,trig="cos",arg="3*(1-log(u))")
It is the function to use in the process to fit coefficients.
tvGarchKalmanLoglike( x, series, c, alpha, beta, nsample = length(series), type = c("polynomial", "NoLineal", "trigonometric"), exponentes, trig, arg, predict, trace.log = FALSE )tvGarchKalmanLoglike( x, series, c, alpha, beta, nsample = length(series), type = c("polynomial", "NoLineal", "trigonometric"), exponentes, trig, arg, predict, trace.log = FALSE )
x |
Vector of coefficents to fit. |
series |
Time series. |
c |
Vector containing coefficents of c. |
alpha |
Vector containing coefficents of alpha. |
beta |
Vector containing coefficents of beta. |
nsample |
Value of time series length. |
type |
Vector of function type for c, alpha and beta. |
exponentes |
Vector for exponenets in NoLineal. |
trig |
Type of trigonometric function. |
arg |
Value of argument for the trigonometric function. |
predict |
Value for time to generate predict. |
trace.log |
Variable to print names of coefficients. |
Value of loglike in model.
This function is designed to print the outputs of the tv-Garch model, which include the returns, conditional variance, log-likelihood value, and mean squared error (MSE).
tvGarchKalmanPrint( x, series, c, alpha, beta, nsample = length(series), type = c("polynomial", "NoLineal", "trigonometric"), exponentes, trig, arg, trace.log = FALSE, predict )tvGarchKalmanPrint( x, series, c, alpha, beta, nsample = length(series), type = c("polynomial", "NoLineal", "trigonometric"), exponentes, trig, arg, trace.log = FALSE, predict )
x |
Vector of coefficents to fit. |
series |
Time series. |
c |
Vector containing coefficents of c. |
alpha |
Vector containing coefficents of alpha. |
beta |
Vector containing coefficents of beta. |
nsample |
Value of time series length. |
type |
Vector of function type for c, alpha and beta. |
exponentes |
Vector for exponenets in NoLineal. |
trig |
Type of trigonometric function. |
arg |
Value of argument for the trigonometric function. |
trace.log |
Variable to print names of coefficients. |
predict |
Value for time to generate predict. |
A data frame containing the following columns:
X: State vector of Kalman equations.
Fm: Value of MSE
sigma: Conditional variance.
loglike: Value of the loglike.
data(ipsa) ipsa<-diff(log(indipsa)) c<-c(0.05,0.05) alpha<-c(0.05,0.05) beta<-c(0.05,0.05) type_fit<-c("trigonometric","trigonometric","trigonometric") fit<-tvGarchKalmanFit(ipsa,c=c,alpha=alpha,beta=beta,type=type_fit,trig="cos",arg="3*(1-log(u))") arg_model<-"3*(1-log(u))" model<-tvGarchKalmanPrint(fit,ipsa,c=c,alpha=alpha,beta=beta,type=type_fit,trig="cos",arg=arg_model) plot(ipsa,ylab="",xlim=c(2000,2015)) lines(ts(model$sigma, star=2000, freq=225), col="red", lwd=2) lines(ts(model$sigma*(-1), star=2000, freq=225), col="red", lwd=2)data(ipsa) ipsa<-diff(log(indipsa)) c<-c(0.05,0.05) alpha<-c(0.05,0.05) beta<-c(0.05,0.05) type_fit<-c("trigonometric","trigonometric","trigonometric") fit<-tvGarchKalmanFit(ipsa,c=c,alpha=alpha,beta=beta,type=type_fit,trig="cos",arg="3*(1-log(u))") arg_model<-"3*(1-log(u))" model<-tvGarchKalmanPrint(fit,ipsa,c=c,alpha=alpha,beta=beta,type=type_fit,trig="cos",arg=arg_model) plot(ipsa,ylab="",xlim=c(2000,2015)) lines(ts(model$sigma, star=2000, freq=225), col="red", lwd=2) lines(ts(model$sigma*(-1), star=2000, freq=225), col="red", lwd=2)
This function performs an exploratory analysis to uncover the dynamic structure of the time-varying GARCH(1,1) parameters. Specifically, the observation domain is partitioned into overlapping blocks, each of length , with a constant shift of size between consecutive blocks. The relation between these quantities satisfies . The midpoint of the -th block, for , is denoted . For each block, a local estimation of the stationary GARCH(1,1) model is performed using the observations within that block. The resulting sequence of local estimates, evaluated across all blocks, provides an empirical trajectory that reflects the underlying evolution of the time-varying parameters. This trajectory can serve as a guide for selecting flexible function classes capable of capturing their temporal variation.
tvParameter(data, S, N, plot = TRUE)tvParameter(data, S, N, plot = TRUE)
data |
Represents the financial return series employed to investigate the temporal evolution of the parameters in the tv-GARCH(1,1) model. |
S |
The number of observations by which the analysis window is shifted to define the starting point of the next block; also known as the step size or shift parameter. |
N |
The total number of observations contained within each data block, representing the block or window length over which local model estimation is performed. |
plot |
A Boolean flag indicating whether a graphical representation of the estimation results should be generated. |
Data frame who contains omega, alpha, beta of GARCH(1,1) model and midpoint each block.
ipsa<-diff(log(indipsa))*100 S = 100 N = 800 tv <- tvParameter(ipsa,S,N)ipsa<-diff(log(indipsa))*100 S = 100 N = 800 tv <- tvParameter(ipsa,S,N)