mlfinlab.data_generation.vines
Implementation of generating financial correlation matrices from “Generating random correlation matrices based on vines and extended onion method” by Daniel Lewandowski, Dorota Kurowicka, Harry Joe. https://www.sciencedirect.com/science/article/pii/S0047259X09000876 and “Generating random correlation matrices based partial correlations” by Harry Joe. https://www.sciencedirect.com/science/article/pii/S0047259X05000886
Module Contents
Functions
|
Generates uniform correlation matrices using the D-vine method. |
|
Generates uniform correlation matrices using the C-vine method. |
|
Generates uniform correlation matrices using extended onion method. |
- sample_from_dvine(dim=10, n_samples=1, beta_dist_fixed=None)
-
Generates uniform correlation matrices using the D-vine method.
It is reproduced with modifications from the following paper: Joe, H., 2006. Generating random correlation matrices based on partial correlations. Journal of Multivariate Analysis, 97(10), pp.2177-2189.
It uses the partial correlation D-vine to generate partial correlations. The partial correlations are sampled from a uniform beta distribution and adjusted to thr range [-1, 1]. Then these partial correlations are converted into raw correlations by using a recursive formula based on its location on the vine.
- Parameters:
-
-
dim – (int) Dimension of correlation matrix to generate.
-
n_samples – (int) Number of samples to generate.
-
beta_dist_fixed – (tuple) Overrides the beta distribution parameters. The input is two float parameters (alpha, beta), used in the distribution. (None by default)
-
- Returns:
-
(np.array) Generated correlation matrices of shape (n_samples, dim, dim).
- sample_from_cvine(dim=10, eta=2, n_samples=1, beta_dist_fixed=None)
-
Generates uniform correlation matrices using the C-vine method.
It is reproduced with modifications from the following paper: Lewandowski, D., Kurowicka, D. and Joe, H., 2009. Generating random correlation matrices based on vines and extended onion method. Journal of multivariate analysis, 100(9), pp.1989-2001.
It uses the partial correlation C-vine to generate partial correlations. The partial correlations are sampled from a uniform beta distribution proportional to its determinant and the factor eta. and adjusted to thr range [-1, 1]. Then these partial correlations are converted into raw correlations by using a recursive formula based on its location on the vine.
- Parameters:
-
-
dim – (int) Dimension of correlation matrix to generate.
-
eta – (int) Corresponds to uniform distribution of beta. Correlation matrix S has a distribution proportional to [det C]^(eta - 1)
-
n_samples – (int) Number of samples to generate.
-
beta_dist_fixed – (tuple) Overrides the beta distribution parameters. The input is two float parameters (alpha, beta), used in the distribution. (None by default)
-
- Returns:
-
(np.array) Generated correlation matrices of shape (n_samples, dim, dim).
- sample_from_ext_onion(dim=10, eta=2, n_samples=1)
-
Generates uniform correlation matrices using extended onion method.
It is reproduced with modifications from the following paper: Lewandowski, D., Kurowicka, D. and Joe, H., 2009. Generating random correlation matrices based on vines and extended onion method. Journal of multivariate analysis, 100(9), pp.1989-2001.
It uses the extended onion to generate correlations sampled from a uniform beta distribution. It starts with a one-dimensional matrix, and it iteratively grows the matrix by adding extra rows and columns by sampling from the convex, closed, compact and full-dimensional set on the surface of a k-dimensional hypersphere.
- Parameters:
-
-
dim – (int) Dimension of correlation matrix to generate.
-
eta – (int) Corresponds to uniform distribution of beta. Correlation matrix S has a distribution proportional to [det C]^(eta - 1)
-
n_samples – (int) Number of samples to generate.
-
- Returns:
-
(np.array) Generated correlation matrices of shape (n_samples, dim, dim).