-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
86 lines (61 loc) · 3.02 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# tcopula
<!-- badges: start -->
[![Travis build status](https://travis-ci.com/Reckziegel/tcopula.svg?branch=main)](https://travis-ci.com/Reckziegel/tcopula)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/y5m45mjh0v4q7ae0?svg=true)](https://ci.appveyor.com/project/Reckziegel/tcopula)
[![Codecov test coverage](https://codecov.io/gh/Reckziegel/tcopula/branch/main/graph/badge.svg?token=yhLyvgUz3J)](https://codecov.io/gh/Reckziegel/tcopula?branch=master)
[![R-CMD-check](https://github.com/Reckziegel/tcopula/workflows/R-CMD-check/badge.svg)](https://github.com/Reckziegel/tcopula/actions)
<!-- badges: end -->
## Installation
You can install the development version of `tcopula` from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("Reckziegel/tcopula")
```
## Case Study
Consider 7 constant maturities swap rates (`1y`, `2y`, `5y`, `7y`, `10y`, `15y` and `30y`) from `1995-05-01` to `2005-04-21`, for a total of 2501 daily realizations.
```{r}
library(tcopula)
data("swap")
head(swap, 2)
tail(swap, 2)
```
To achieve stationarity, the risk-driver (`swap`) has to be differentiated once:
```{r}
swap_diff <- swap[2:nrow(swap), ] - swap[1:nrow(swap) - 1, ]
head(swap_diff)
```
Because the first 3 principal components explain most of the variations in yield-curve (see [here](https://www.math.nyu.edu/faculty/avellane/Litterman1991.pdf)) it's common to shrink the dimension of `swap_diff` to avoid noisy signals from eigenvalues that are not well defined.
By setting `k = 3` in `struct_t_mle()`, the main sources of relevant information (aka level, steepness and curvature) are still taken into account, while the remaining factors are assumed to follow an isotropic structure:
```{r}
fit <- struct_t_mle(x = swap_diff, k = 3, tolerance = 1e-10)
fit
```
As the output shows, the commovements in interest-rates variations are
quite high. The optimal degree of freedom for `swap_diff` is $v=49$, which may indicate that
tick-tails are not an issue for this particular dataset.
The imposed structure stands-out in the image that follows:
```{r, out.height="80%", out.width="80%", fig.align="center"}
library(ggplot2)
df <- data.frame(
factors = as.factor(1:7),
eigenvalues = eigen(fit$C)$values
)
ggplot(data = df, aes(x = factors, y = eigenvalues, fill = factors)) +
geom_col() +
scale_fill_viridis_d(option = "E")
```
## References
- Attilio Meucci (2020). [Estimation of Structured t-Copulas](https://www.mathworks.com/matlabcentral/fileexchange/19751-estimation-of-structured-t-copulas), MATLAB Central File Exchange. Retrieved October 14, 2020.
- Meucci, Attilio, _Estimation of Structured T-Copulas_ (April 2008). Available at SSRN: https://www.ssrn.com/abstract=1126401 or http://dx.doi.org/10.2139/ssrn.1126401.