Risk

Misc

  • Also see
  • Packages
    • {PerformanceAnalytics} - Econometric Tools for Performance and Risk Analysis
      • Lots of vignettes, but there’s also a substantial amount of material in the introduction section of the Reference Manual

Value at Risk (VaR)

Copulas

  • Also see Association, Copulas

  • Copula Workflow

    • Data Collection and Preprocessing:
      • Collect historical data for the two variables of interest.
      • Clean the data by handling missing values, outliers, and ensuring consistency.
    • Marginal Distribution Estimation:
      • Estimate the marginal distributions of each variable independently.
      • Fit appropriate probability distributions to the marginal data.
    • Copula Selection and Fitting:
      • Choose a copula family (e.g., Gaussian, t, Clayton, Gumbel, etc.).
      • Fit the copula model to the data, estimating the copula parameters.
    • Simulation and Analysis:
      • Generate joint samples from the fitted copula model.
      • Use the joint distribution to compute risk measures such as VaR and CVaR.
  • Example: Value at Risk and Conditional Value at Risk Using Copulas

    set.seed(123)
    n <- 1000
    asset1 <- 
      rnorm(n, 
            mean = 0.001, 
            sd = 0.02)
    asset2 <- 
      rnorm(n, 
            mean = 0.001, 
            sd = 0.03)
    data <- data.frame(asset1, asset2)
    
    1margins <- list(m1 = fitdistrplus::fitdist(asset1, "norm"),
                    m2 = fitdistrplus::fitdist(asset2, "norm"))
    
    2normal.cop <- copula::normalCopula(param = 0.5, dim = 2)
    
    u1 <- 
      pnorm(asset1, 
            mean = margins$m1$estimate["mean"], 
    3        sd = margins$m1$estimate["sd"])
    u2 <- 
      pnorm(asset2, 
            mean = margins$m2$estimate["mean"], 
            sd = margins$m2$estimate["sd"])
    fit.cop <- 
      copula::fitCopula(normal.cop, 
                        cbind(u1, u2), 
                        method = "ml")
    
    copula.samples <- 
    4  copula::rCopula(n, fit.cop@copula)
    
    5simulated.returns <- data.frame(
      asset1 = qnorm(copula.samples[, 1], 
                     mean = margins$m1$estimate["mean"], 
                     sd = margins$m1$estimate["sd"]),
      asset2 = qnorm(copula.samples[, 2], 
                     mean = margins$m2$estimate["mean"], 
                     sd = margins$m2$estimate["sd"])
    )
    simulated.portfolio.returns <- rowMeans(simulated.returns)
    
    6VaR_95 <- quantile(simulated.portfolio.returns, probs = 0.05)
    CVaR_95 <- mean(simulated.portfolio.returns[simulated.portfolio.returns <= VaR_95])
    1
    Estimate marginal distributions (assuming normal for simplicity)
    2
    normalCopula doesn’t have it’s own listing in the reference manual. It’s under ellipCopula, or you can just use ?normalCopula.
    3
    Fit the copula to the data
    4
    Generate samples from the fitted copula. The @ operator is used to access copula object since it’s a S4 object. Also, rCopula doesn’t have it’s own listing in the reference manual. It’s under Copula, or you can just use ?rCopula.
    5
    Simulate portfolio returns by ransforming copula samples back to original scale and averaging (i.e. equal weighting)
    6
    Calculate VaR and CVaR at 95% confidence level
    • {PerformanceAnalytics} also has functions for calculation the VaR and CVaR values

      VaR_95 <- VaR(simulated.portfolio.returns, 
                    p = 0.95, 
                    method = "historical")
      CVaR_95 <- ES(simulated.portfolio.returns, 
                    p = 0.95, 
                    method = "historical")