Fin285a:Computer Simulations and Risk Assessment Section 7.2...
Transcript of Fin285a:Computer Simulations and Risk Assessment Section 7.2...
Fin285a:Computer Simulations andRisk Assessment
Section 7.2Copulas
Danı́elson, 1.8
Overview
Fall 2016: LeBaron Fin285a: 7.2-5 list – 2 / 27
Copula objectives
Copula lesson 1: Generate a distribution
Copula lesson 2: Generate two random variables
Copula lesson 3: Empirical distributions (data)
Copula details
Matlab functions and fitting copulas
Copula wrap-up
Copula objectives
Copula objectives
Copula lesson 1:Generate adistribution
Copula lesson 2:Generate tworandom variables
Copula lesson 3:Empiricaldistributions (data)
Copula details
Matlab functions andfitting copulas
Copula wrap-up
Fall 2016: LeBaron Fin285a: 7.2-5 list – 3 / 27
Objectives
Fall 2016: LeBaron Fin285a: 7.2-5 list – 4 / 27
⊲ Generate dependence between X and Y⊲ Fix distribution of X alone, and Y alone
(Marginal distributions)⊲ Example
• Fit returns to a student-t• Then adjust dependence between them
Copula lesson 1: Generate adistribution
Copula objectives
Copula lesson 1:Generate adistribution
Copula lesson 2:Generate tworandom variables
Copula lesson 3:Empiricaldistributions (data)
Copula details
Matlab functions andfitting copulas
Copula wrap-up
Fall 2016: LeBaron Fin285a: 7.2-5 list – 5 / 27
Generate a distribution
Fall 2016: LeBaron Fin285a: 7.2-5 list – 6 / 27
⊲ F (x) is cumulative distribution function for some RVX
⊲ Generate a uniform random variablezi ∼ Uniform[0, 1]
⊲ Generate yi = F−1(zi)⊲ yi’s will follow the distribution represented by F ()⊲ matlab: copulaex1.m
Copula example 1
Fall 2016: LeBaron Fin285a: 7.2-5 list – 7 / 27
% Simple motivating example for copula technology
% Convert a uniform random variable into a student-t
nsample = 10000;
z = rand(nsample,1);
y = tinv(z,3);
histfit(y);
Message
Fall 2016: LeBaron Fin285a: 7.2-5 list – 8 / 27
⊲ Can turn a uniform into any distribution you want⊲ This can be useful sometimes in monte-carlo’s
Copula lesson 2: Generatetwo random variables
Copula objectives
Copula lesson 1:Generate adistribution
Copula lesson 2:Generate tworandom variables
Copula lesson 3:Empiricaldistributions (data)
Copula details
Matlab functions andfitting copulas
Copula wrap-up
Fall 2016: LeBaron Fin285a: 7.2-5 list – 9 / 27
Convert two normals to student-t
Fall 2016: LeBaron Fin285a: 7.2-5 list – 10 / 27
⊲ Generate (w1, w2) from a multivariate Normal⊲ Get u = F (w1), v = F (w2) where F (x) is normal
CDF⊲ Generate y = G−1(u), z = G−1(v)
G(x) is the student-t CDF⊲ matlab: copulaex2.m
Copula example 2
Fall 2016: LeBaron Fin285a: 7.2-5 list – 11 / 27
% Basic bivariate copula
% Normal copula, student-t marginals, matlab scatter plot
nsample = 10000;
% build variance/covariance matrix for normals
rho = 0.5; % correlation
omega = [1 rho; rho 1];
mn = [ 0 0];
% draw normals to vector w
w = normal(nsample,mn,omega);
% map to uniforms using the cdf
u = normcdf(w(:,1),0,1);
v = normcdf(w(:,2),0,1);
% map back to student-t (4 degrees of freedom)
y = tinv(u,4);
z = tinv(v,4);
% nice matlab routine for plotting
scatterhist(y,z);
Copula lesson 3: Empiricaldistributions (data)
Copula objectives
Copula lesson 1:Generate adistribution
Copula lesson 2:Generate tworandom variables
Copula lesson 3:Empiricaldistributions (data)
Copula details
Matlab functions andfitting copulas
Copula wrap-up
Fall 2016: LeBaron Fin285a: 7.2-5 list – 12 / 27
Generate desired correlation with empirical marginals
Fall 2016: LeBaron Fin285a: 7.2-5 list – 13 / 27
⊲ Generate (w1, w2) from a multivariate Normal⊲ Get u = F (w1), v = F (w2) where F (x) is normal
CDF⊲ Generate usret1mc = G−1(u), emretmc = G−1(v)
• G(x) is empirical CDF from data• Like bootstrap
⊲ matlab: copulaex3.m
What is an empirical CDF?
Fall 2016: LeBaron Fin285a: 7.2-5 list – 14 / 27
⊲ Rt vector of returns⊲ p = G(x) = fraction(Rt ≤ x)⊲ R̃(p) = G−1(p) = quantile(Rt, p)
Copula details
Copula objectives
Copula lesson 1:Generate adistribution
Copula lesson 2:Generate tworandom variables
Copula lesson 3:Empiricaldistributions (data)
Copula details
Matlab functions andfitting copulas
Copula wrap-up
Fall 2016: LeBaron Fin285a: 7.2-5 list – 15 / 27
The steps to generate X, Y
Fall 2016: LeBaron Fin285a: 7.2-5 list – 16 / 27
⊲ Draw (U, V ) from a joint distribution C(U, V ) wherethe marginal distributions of both U and V areU [0, 1]
⊲ Then send U, V through an inverse CDF,
• X = G−1(U)• Y = F−1(V )
⊲ The distribution C(U, V ) is tricky, this is whatcontrols dependence at the uniform density stage
⊲ C(U, V ) is the copula function
What was the copula?
Fall 2016: LeBaron Fin285a: 7.2-5 list – 17 / 27
F (), G() are marginal CDF’s for X,Y
(U, V ) = (F (X), G(Y )) (7.2.1)
Pr(U ≤ u, V ≤ v) = C(u, v) (7.2.2)
Pr(X ≤ x, Y ≤ y) = C(F (x), G(y)) = H(x, y) (7.2.3)
C() is the copula function and controls the joint distribution.Sklar’s Thm: any multivariate CDF, H(x1, x2, . . . , xd) can be writtenas
H(x1, x2, . . . , xd) = C(F1(x1), F2(x2), . . . , Fd(xd)) (7.2.4)
Picture of the Gaussian Copula
Fall 2016: LeBaron Fin285a: 7.2-5 list – 18 / 27
Uniform World (u, v) (dependence)
Multivariate Normal (Σ)
(w1, w2) → Normal CDF(Φ), u = Φ(w1), v = Φ(w2)
Target Marginal Inverse CDF’s
y = G−1(u)z = F−1(v)
Copula varieties
Fall 2016: LeBaron Fin285a: 7.2-5 list – 19 / 27
⊲ GaussianC(u) = ΦΣ(Φ
−1(u1),Φ−1(u2))
ΦΣ(x) is multivariate Normal CDF, mean zero,,var=1, var/cvar= Σ, Φ(x) is univariate N(0, 1)
⊲ Student-t: Same as Gaussian but student-t CDF⊲ Clayton (Archemedian class)
C(u) = ψ(ψ−1(u1) + ψ−1(u2))ψ(x) = (1 + x)−1/θ
ψ−1(x) = x−θ − 1⊲ Joe⊲ Gumbel
Matlab functions and fittingcopulas
Copula objectives
Copula lesson 1:Generate adistribution
Copula lesson 2:Generate tworandom variables
Copula lesson 3:Empiricaldistributions (data)
Copula details
Matlab functions andfitting copulas
Copula wrap-up
Fall 2016: LeBaron Fin285a: 7.2-5 list – 20 / 27
copulafit and copularnd
Fall 2016: LeBaron Fin285a: 7.2-5 list – 21 / 27
% program = copulaexfit.m
% map returns to uniforms using empirical cdf
eqret = (wldeqp(2:end,2:end)-(wldeqp(1:end-1,2:end)))./...
wldeqp(1:end-1,2:end);
uret(:,1) = empcdf(eqret(:,1),eqret(:,1));
uret(:,2) = empcdf(eqret(:,2),eqret(:,2));
% Fit a gaussian copula
[paramhat] = copulafit(’Gaussian’,uret);
umc = copularnd(’Gaussian’,paramhat,nmc);
% Fit a student-t copula (nu = degrees of freedom)
[paramhat, nu] = copulafit(’t’,uret);
umc = copularnd(’t’,paramhat,nu,nmc);
% Fit a Clayton copula (fatter left tail)
[paramhat] = copulafit(’clayton’,uret);
umc = copularnd(’clayton’,paramhat,nmc);
Matlab implementation
Fall 2016: LeBaron Fin285a: 7.2-5 list – 22 / 27
⊲ matlab: copulaexfit.m⊲ Fit 3 copulas (Clayton, Student-t, Gaussian) to
uniform CDF⊲ Estimate extreme right and left tail probabilities⊲ Estimate VaR (extreme)⊲ Scatter plots
Copula wrap-up
Copula objectives
Copula lesson 1:Generate adistribution
Copula lesson 2:Generate tworandom variables
Copula lesson 3:Empiricaldistributions (data)
Copula details
Matlab functions andfitting copulas
Copula wrap-up
Fall 2016: LeBaron Fin285a: 7.2-5 list – 23 / 27
Advantages
Fall 2016: LeBaron Fin285a: 7.2-5 list – 24 / 27
⊲ Separates problems
• Fitting marginal distribution• Modeling dependence
⊲ May beat the bootstrap for small samples
• Generating joint (x, y) extreme observations• Using actual data as marginals distributions!!
⊲ Key problem: Which copula do you use?
Puzzles in multivariate returns
Fall 2016: LeBaron Fin285a: 7.2-5 list – 25 / 27
⊲ Do correlations change with volatility and risk?⊲ Some think yes
• When volatility is high, correlations are high?• Ability to diversify risk is low
⊲ This gets more complex⊲ Changing copulas⊲ ”Risk on/risk off” behavior
Risk on/risk off
Fall 2016: LeBaron Fin285a: 7.2-5 list – 26 / 27
⊲ Traders appear to correlate in buying and sellingrisky assets
⊲ Statistic: Days where more than 90 percent ofstocks are moving in the same direction
• Up to 2006 this is about 3-5 days per year• 2008-2011 this is above 30 (or about 1/7 (14
percent)trading days)
⊲ Matlab: rollcorr.m
Overview
Fall 2016: LeBaron Fin285a: 7.2-5 list – 27 / 27
Copula objectives
Copula lesson 1: Generate a distribution
Copula lesson 2: Generate two random variables
Copula lesson 3: Empirical distributions (data)
Copula details
Matlab functions and fitting copulas
Copula wrap-up