Created
November 6, 2016 17:10
-
-
Save BioSciEconomist/d0dde81959df70c6ce933480253929f1 to your computer and use it in GitHub Desktop.
Copula functions, R, and the financial crisis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# *------------------------------------------------------------------ | |
# | PROGRAM NAME: R_COPULA_BASIC | |
# | DATE: 1/25/11 | |
# | CREATED BY: Matt Bogard | |
# | PROJECT FILE: http://econometricsense.blogspot.com/2011/03/copula-functions-r-and-financial-crisis.html | |
# *---------------------------------------------------------------- | |
# | PURPOSE: copula graphics | |
# | | |
# *------------------------------------------------------------------ | |
# | COMMENTS: | |
# | | |
# | 1: REFERENCES: Emjoy the Joy of Copulas: With a Package copula | |
# | Journal of Statistical Software Oct 2007, vol 21 Issue 1 | |
# | http://www.jstatsoft.org/v21/i04/paper | |
# | 2: | |
# | 3: | |
# |*------------------------------------------------------------------ | |
# | DATA USED: | |
# | | |
# | | |
# |*------------------------------------------------------------------ | |
# | CONTENTS: | |
# | | |
# | PART 1: | |
# | PART 2: | |
# | PART 3: | |
# *----------------------------------------------------------------- | |
# | UPDATES: | |
# | | |
# | | |
# *------------------------------------------------------------------ | |
library("copula") | |
set.seed(1) | |
# *------------------------------------------------------------------ | |
# | | |
# |scatterplots | |
# | | |
# | | |
# *----------------------------------------------------------------- | |
# normal (Gausian?) Copula | |
norm.cop <- normalCopula(2, dim =3) | |
norm.cop | |
x <- rcopula(norm.cop, 500) | |
plot(x) | |
title("Gaussian Copula") | |
# Clayton Copula | |
clayton.cop <- claytonCopula(2, dim = 2) | |
clayton.cop | |
y <- rcopula(clayton.cop,500) | |
plot(y) | |
title("Clayton Copula") | |
# Frank Copula | |
frank.cop <- frankCopula(2, dim = 2) | |
frank.cop | |
f <- rcopula(frank.cop,500) | |
plot(f) | |
title("Frank Copula") | |
# Gumbel Copula | |
gumbel.cop <- gumbelCopula(2, dim = 2) | |
gumbel.cop | |
g <- rcopula(gumbel.cop,500) | |
plot(g) | |
title('Gumbel Copula') | |
# *------------------------------------------------------------------ | |
# | | |
# | contour plots | |
# | | |
# | | |
# *----------------------------------------------------------------- | |
# clayton copula contour | |
myMvd1 <- mvdc(copula = archmCopula(family = "clayton", param = 2), | |
margins = c("norm", "norm"), paramMargins = list(list(mean = 0, | |
sd = 1), list(mean = 0, sd = 1))) | |
contour(myMvd1, dmvdc, xlim = c(-3, 3), ylim = c(-3, 3)) | |
title("Clayton Copula") | |
# frank copula contour | |
myMvd2 <- mvdc(copula = archmCopula(family = "frank", param = 5.736), | |
margins = c("norm", "norm"), paramMargins = list(list(mean = 0, | |
sd = 1), list(mean = 0, sd = 1))) | |
contour(myMvd2, dmvdc, xlim = c(-3, 3), ylim = c(-3, 3)) | |
title("Frank Copula") | |
# gumbel copula | |
myMvd3 <- mvdc(copula = archmCopula(family = "gumbel", param = 2), | |
margins = c("norm", "norm"), paramMargins = list(list(mean = 0, | |
sd = 1), list(mean = 0, sd = 1))) | |
contour(myMvd3, dmvdc, xlim = c(-3, 3), ylim = c(-3, 3)) | |
title("Gumbel Copula") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment