Download the notebook here
!
Interactive online version:
Sampling¶
We show how to construct correlated sample with Gaussian copula.
[1]:
import chaospy as cp
import numpy as np
from econsa.correlation import gc_correlation
First we specify the marginal distributions and correlation matrix.
[2]:
corr = [[1.0, 0.6, 0.2], [0.6, 1.0, 0.0], [0.2, 0.0, 1.0]]
marginals = (
cp.Normal(mu=1230),
cp.Normal(mu=0.0135),
cp.Uniform(lower=1.15, upper=3.15),
)
We then transform the correlation matrix using equation (4.5) in Kucherenko et al. (2012).
[3]:
corr_transformed = gc_correlation(marginals, corr)
Now we are ready to use transformed correlation matrix to sample from a Gaussian copula.
[4]:
copula = cp.Nataf(cp.J(*marginals), corr_transformed)
corr_copula = np.corrcoef(copula.sample(100000))
np.round(corr_copula, decimals=4)
[4]:
array([[ 1. , 0.6018, 0.2013],
[ 0.6018, 1. , -0.0018],
[ 0.2013, -0.0018, 1. ]])