Skip to content

Commit

Permalink
updated copula code and modified README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kwoongbae committed Jul 7, 2024
1 parent 14eecb7 commit 76088dd
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
| ------------------------------------------------------------ | -------------------- | :----------------------------------------------------------- |
| [Alm (2015)](https://www.tandfonline.com/doi/abs/10.1080/03461238.2013.787367) | ***SAJ*** | [review](https://github.com/kwoongbae/risk-management-papers/issues/36) / [seminar file](./review/Seminar_20240626.pdf) |
| [Bermúdez et al. (2013)](https://www.cambridge.org/core/journals/astin-bulletin-journal-of-the-iaa/article/correlation-sensitivity-analysis-of-nonlife-underwriting-risk-in-solvency-capital-requirement-estimation/8C16299AF4E9DFCD13C5C7EA3697705E) | ***ASTIN Bulletin*** | [review](https://github.com/kwoongbae/risk-management-papers/issues/37) |
| [Eling and Schnell (2020)](https://www.tandfonline.com/doi/abs/10.1080/10920277.2019.1641416) | ***NAAJ*** | [review](https://github.com/kwoongbae/risk-management-papers/issues/32) / [code (R)](https://github.com/kwoongbae/risk-management-papers/blob/main/code/Eling_and_Schnell_NAAJ_2020.r) |
| [Eling and Schnell (2020)](https://www.tandfonline.com/doi/abs/10.1080/10920277.2019.1641416) | ***NAAJ*** | [review](https://github.com/kwoongbae/risk-management-papers/issues/32) / [code](./code/Eling_and_Schnell_NAAJ_2020.r) |

- **(시스템적) 사이버 리스크 관련 문헌**

Expand Down
Binary file added code/.RData
Binary file not shown.
100 changes: 100 additions & 0 deletions code/.Rhistory
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
rm(list=ls())
# Required packages
library(mvtnorm)
library(ggplot2)
library(ggExtra)
# ===================================================
# 1. Import libraries and SAS OpRisk Global dataset
# ===================================================
install.packages("mvtnorm")
# ===================================================
# 1. Import libraries and SAS OpRisk Global dataset
# ===================================================
install.packages("ggplot2")
install.packages("ggplot2")
# ===================================================
# 1. Import libraries and SAS OpRisk Global dataset
# ===================================================
install.packages("ggExtra")
# Required packages
library(mvtnorm)
library(ggplot2)
library(ggExtra)
library(sn)
# ===================================================
# 1. Import libraries and SAS OpRisk Global dataset
# ===================================================
install.packages("sn")
library(sn)
sim.GC <- function(n, rho, qmarg1, qmarg2){
R <- rbind(c(1,rho),c(rho,1))
dat <- rmvnorm(n, mean = c(0,0), sigma = R)
dat[,1] <- qmarg1(pnorm(dat[,1]))
dat[,2] <- qmarg2(pnorm(dat[,2]))
return(dat)
}
set.seed(1234)
q1 <- function(p) qunif(p)
q2 <- function(p) qunif(p)
q1
qunif(100)
ns <- 1000; rho = 0.7
sim <- sim.GC(n = ns, rho = rho,q1,q2)
df <- data.frame(x = sim[,1], y = sim[,2])
df
p <- ggplot(df, aes(x, y)) + geom_point() + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14)) +
xlab("X") + ylab("Y") + ggtitle(expression(paste(rho, "=0.5")))
ggExtra::ggMarginal(p, type = "histogram")
ns <- 1000; rho = 1
sim <- sim.GC(n = ns, rho = rho,q1,q2)
df <- data.frame(x = sim[,1], y = sim[,2])
p <- ggplot(df, aes(x, y)) + geom_point() + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14)) +
xlab("X") + ylab("Y") + ggtitle(expression(paste(rho, "=0.5")))
ggExtra::ggMarginal(p, type = "histogram")
ns <- 1000; rho = 0.7
sim <- sim.GC(n = ns, rho = rho,q1,q2)
df <- data.frame(x = sim[,1], y = sim[,2])
p <- ggplot(df, aes(x, y)) + geom_point() + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14)) +
xlab("X") + ylab("Y") + ggtitle(expression(paste(rho, "=0.5")))
ggExtra::ggMarginal(p, type = "histogram")
grid::grid.newpage()
ns <- 1000; rho = 0.75
sim <- sim.GC(n = ns,rho = rho,q1,q2)
df <- data.frame(x = sim[,1], y = sim[,2])
p <- ggplot(df, aes(x, y)) + geom_point() + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14)) +
xlab("X") + ylab("Y") + ggtitle(expression(paste(rho, "=0.75")))
ggExtra::ggMarginal(p, type = "histogram")
#--------------------
# Logistic marginals
#--------------------
q1 <- function(p) qlogis(p)
q2 <- function(p) qlogis(p)
ns <- 1000; rho = 0.5
sim <- sim.GC(n = ns,rho = rho,q1,q2)
df <- data.frame(x = sim[,1], y = sim[,2])
p <- ggplot(df, aes(x, y)) + geom_point() + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14)) +
xlab("X") + ylab("Y") + ggtitle(expression(paste(rho, "=0.5")))
ggExtra::ggMarginal(p, type = "histogram")
#----------------------------------------------------
# Student-t with 4 degrees of freedom marginals
#----------------------------------------------------
q1 <- function(p) qt(p, df = 4)
q2 <- function(p) qt(p, df = 4)
ns <- 1000; rho = 0.5
sim <- sim.GC(n = ns,rho = rho,q1,q2)
df <- data.frame(x = sim[,1], y = sim[,2])
p <- ggplot(df, aes(x, y)) + geom_point() + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14)) +
xlab("X") + ylab("Y") + ggtitle(expression(paste(rho, "=0.5")))
ggExtra::ggMarginal(p, type = "histogram")
#----------------------------------------------------
# Student-t with 4 degrees of freedom marginal for X
# Standard normal for Y
#----------------------------------------------------
q1 <- function(p) qt(p, df = 4)
q2 <- function(p) qnorm(p)
ns <- 1000; rho = 0.5
sim <- sim.GC(n = ns,rho = rho,q1,q2)
df <- data.frame(x = sim[,1], y = sim[,2])
p <- ggplot(df, aes(x, y)) + geom_point() + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14)) +
xlab("X") + ylab("Y") + ggtitle(expression(paste(rho, "=0.5")))
ggExtra::ggMarginal(p, type = "histogram")
96 changes: 96 additions & 0 deletions code/Copula.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# ===================================================
# Import libraries and SAS OpRisk Global dataset
# ===================================================
install.packages("sn")
set.seed(1234)
rm(list=ls())
# Required packages
library(mvtnorm)
library(ggplot2)
library(ggExtra)
library(sn)

# ===================================================
# normal margins
# ===================================================

sim.GC <- function(n, rho, qmarg1, qmarg2){
R <- rbind(c(1,rho),c(rho,1)) #rho가 두 변수 간의 상관관계를 의미함.
dat <- rmvnorm(n, mean = c(0,0), sigma = R)
dat[,1] <- qmarg1(pnorm(dat[,1]))
dat[,2] <- qmarg2(pnorm(dat[,2]))
return(dat)
}

q1 <- function(p) qunif(p)
q2 <- function(p) qunif(p)

ns <- 1000; rho = 0.7
sim <- sim.GC(n = ns, rho = rho,q1,q2)
df <- data.frame(x = sim[,1], y = sim[,2])
p <- ggplot(df, aes(x, y)) + geom_point() + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14)) +
xlab("X") + ylab("Y") + ggtitle(expression(paste(rho, "=0.5")))
ggExtra::ggMarginal(p, type = "histogram")


grid::grid.newpage()

ns <- 1000; rho = 0.75
sim <- sim.GC(n = ns,rho = rho,q1,q2)
df <- data.frame(x = sim[,1], y = sim[,2])
p <- ggplot(df, aes(x, y)) + geom_point() + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14)) +
xlab("X") + ylab("Y") + ggtitle(expression(paste(rho, "=0.75")))
ggExtra::ggMarginal(p, type = "histogram")



grid::grid.newpage()


# ===================================================
# Logistic marginals
# ===================================================

q1 <- function(p) qlogis(p)
q2 <- function(p) qlogis(p)

ns <- 1000; rho = 0.5
sim <- sim.GC(n = ns,rho = rho,q1,q2)
df <- data.frame(x = sim[,1], y = sim[,2])
p <- ggplot(df, aes(x, y)) + geom_point() + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14)) +
xlab("X") + ylab("Y") + ggtitle(expression(paste(rho, "=0.5")))
ggExtra::ggMarginal(p, type = "histogram")

grid::grid.newpage()


# ===================================================
# Student-t with 4 degrees of freedom marginals
# ===================================================

q1 <- function(p) qt(p, df = 4)
q2 <- function(p) qt(p, df = 4)

ns <- 1000; rho = 0.5
sim <- sim.GC(n = ns,rho = rho,q1,q2)
df <- data.frame(x = sim[,1], y = sim[,2])
p <- ggplot(df, aes(x, y)) + geom_point() + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14)) +
xlab("X") + ylab("Y") + ggtitle(expression(paste(rho, "=0.5")))
ggExtra::ggMarginal(p, type = "histogram")

grid::grid.newpage()


# ===================================================
# Student-t with 4 degrees of freedom marginal for X
# Standard normal for Y
# ===================================================
q1 <- function(p) qt(p, df = 4)
q2 <- function(p) qnorm(p)

ns <- 1000; rho = 0.5
sim <- sim.GC(n = ns,rho = rho,q1,q2)
df <- data.frame(x = sim[,1], y = sim[,2])
p <- ggplot(df, aes(x, y)) + geom_point() + theme(axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 14)) +
xlab("X") + ylab("Y") + ggtitle(expression(paste(rho, "=0.5")))
ggExtra::ggMarginal(p, type = "histogram")

0 comments on commit 76088dd

Please sign in to comment.