# Basic Time Series Copula Processes In tscopula: Time Series Copula Models

knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(tscopula)  This library currently implements 3 basic kinds of time series copula process: ARMA copula processes and d-vine copula processes of type 1 and type 2. These are described in the next 3 sections. ## 1. ARMA Copula Processes ### AR(1) Example An ARMA copula is specified by a list of two vectors, the first named ar and the second ma. The following example creates an AR(1) copula process specification and then displays the spec. ar1 <- armacopula(list(ar = 0.7)) ar1  A realization can be generated with the generic command sim. set.seed(13) data1 <- sim(ar1, 1000) ts.plot(data1)  A model specification can be fitted to data with the generic command fit. ar1spec <- armacopula(list(ar = 0)) ar1fit <- fit(ar1spec, data1) ar1fit  ### ARMA(1,1) Example The next example simulates and fits an ARMA(1,1) copula process, giving standard errors for the parameter estimates. arma11 <- armacopula(list(ar = 0.95, ma = -0.85)) data2 <- sim(arma11, 1000) ts.plot(data2) arma11spec <- armacopula(list(ar = 0.1, ma = 0.1)) arma11fit <- fit(arma11spec, data2, tsoptions = list(hessian = TRUE)) arma11fit  Coefficients of the fitted model are obtained with the command coef, residuals with the command resid and various plots are generated by the generic command plot. coef(arma11fit) res <- resid(arma11fit) acf(res) acf(abs(res)) plot(arma11fit) plot(arma11fit, plottype = "kendall") mu_t <- resid(arma11fit, trace = TRUE) ts.plot(mu_t)  The data for these plots come from applying the Kalman filter command kfilter. head(kfilter(arma11fit@tscopula, data2))  ## 2. D-Vine Copula Processes (type 1) ### Construction We construct a copula of order$p = 3$in which the copulas are respectively Clayton, Frank, and Gauss. The parameters are given in a list. Individual copulas can be rotated through 180 degrees. copmod <- dvinecopula( family = c("Clayton","Frank", "Gaussian"), pars = list(1.2, 2, 0.15), rotation = c(180,0, 0) ) copmod  ### Simulation A realization can be generated with the generic command sim. set.seed(29) data1 <- sim(copmod, n = 2000) hist(data1) ts.plot(data1)  ### Estimation A model spec can be fitted to data with the generic command fit. copspec <- dvinecopula( family = c("Clayton","Frank", "Gaussian"), pars = list(0.5, 1, 0), rotation = c(180, 0, 0) ) copfit <- fit(copspec, data1, tsoptions = list(hessian = TRUE), control = list(maxit = 2000)) copfit coef(copfit) coef(copmod)  ### Plotting Various plots are generated by the generic command plot. plot(copfit) plot(copfit, plottype = "kendall")  Here is the generalized lag plot. plot(copfit, plottype = "glag")  ## 3. D-Vine Copula Processes (type 2) ### Construction We construct a model using the Joe copula and the Kendall partial autocorrelation function (KPACF) of a Gaussian ARMA process with autogressive (ar) parameter 0.9 and moving average (ma) parameter -0.85. The KPACF is truncated at lag 20, so this is a process of finite order. We can also set$\text{maxlag} = \inf\$ but this leads to much slower simulation.

copmod <- dvinecopula2(family = "joe",
kpacf = "kpacf_arma",
pars = list(ar = 0.9, ma = -0.85),
maxlag = 20)
copmod


### Simulation

A realization can be generated with the generic command sim.

set.seed(13)
data1 <- sim(copmod, n = 2000)
hist(data1)
ts.plot(data1)


### Estimation

A model spec can be fitted to data with the generic command fit.

copspec_Gauss <- dvinecopula2(family = "gauss",
pars = list(ar = 0, ma = 0),
maxlag = 20)
fitGauss <- fit(copspec_Gauss, data1)
fitGauss

copspec_Joe <- dvinecopula2(family = "joe",
pars = list(ar = 0, ma = 0),
maxlag = 20)
fitJoe <- fit(copspec_Joe, data1)
fitJoe

AIC(fitGauss, fitJoe)


### Plotting

Various plots are generated by the generic command plot.

plot(fitJoe)
plot(fitJoe, plottype = "kendall")


## Try the tscopula package in your browser

Any scripts or data that you put into this service are public.

tscopula documentation built on May 7, 2022, 5:06 p.m.