[Returnanalytics-commits] r3675 - in pkg/Dowd: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Jun 15 21:18:04 CEST 2015
Author: dacharya
Date: 2015-06-15 21:18:04 +0200 (Mon, 15 Jun 2015)
New Revision: 3675
Added:
pkg/Dowd/R/GParetoES.R
pkg/Dowd/R/GParetoMEFPlot.R
pkg/Dowd/man/GParetoES.Rd
pkg/Dowd/man/GParetoMEFPlot.Rd
Modified:
pkg/Dowd/NAMESPACE
Log:
GParetoES and GParetoMEFPlot: source and documentation
Modified: pkg/Dowd/NAMESPACE
===================================================================
--- pkg/Dowd/NAMESPACE 2015-06-15 10:05:49 UTC (rev 3674)
+++ pkg/Dowd/NAMESPACE 2015-06-15 19:18:04 UTC (rev 3675)
@@ -22,6 +22,8 @@
export(FrechetESPlot2DCl)
export(FrechetVaR)
export(FrechetVaRPlot2DCl)
+export(GParetoES)
+export(GParetoMEFPlot)
export(GaussianCopulaVaR)
export(GumbelCopulaVaR)
export(HSES)
Added: pkg/Dowd/R/GParetoES.R
===================================================================
--- pkg/Dowd/R/GParetoES.R (rev 0)
+++ pkg/Dowd/R/GParetoES.R 2015-06-15 19:18:04 UTC (rev 3675)
@@ -0,0 +1,48 @@
+#' @title Expected Shortfall for Generalized Pareto
+#'
+#' @description Estimates the ES of a portfolio assuming losses are distributed as a generalised Pareto.
+#'
+#' @param Ra Vector of daily Profit/Loss data
+#' @param beta Assumed scale parameter
+#' @param zeta Assumed tail index
+#' @param threshold.prob Threshold probability
+#' @param cl VaR confidence level
+#'
+#' @return Expected Shortfall
+#'
+#' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
+#'
+#' McNeil, A., Extreme value theory for risk managers. Mimeo, ETHZ, 1999.
+#'
+#' @author Dinesh Acharya
+#' @examples
+#'
+#' # Computes ES assuming generalised Pareto for following parameters
+#' Ra <- 5 * randn(100)
+#' beta <- 1.2
+#' zeta <- 1.6
+#' threshold.prob <- .85
+#' cl <- .99
+#' GParetoES(Ra, beta, zeta, threshold.prob, cl)
+#'
+#' @export
+GParetoES <- function(Ra, beta, zeta, threshold.prob, cl){
+
+ if ( max(cl) >= 1){
+ stop("Confidence level(s) must be less than 1")
+ }
+ if ( min(cl) <= 0){
+ stop("Confidence level(s) must be greater than 0")
+ }
+
+ x <- as.vector(Ra)
+ n <- length(x)
+ x <- sort(x)
+ Nu <- threshold.prob * n
+ Nu <- ((Nu >= 0) * floor(Nu) + (Nu < 0) * ceiling(Nu))
+ u <- x[n - Nu]
+ y=(u + (beta / zeta) * ((((1 / threshold.prob) * (1 - cl))^(-zeta))
+ - 1))/(1 - zeta)+(beta - zeta * u) / (1 - zeta);
+ return(y)
+
+}
\ No newline at end of file
Added: pkg/Dowd/R/GParetoMEFPlot.R
===================================================================
--- pkg/Dowd/R/GParetoMEFPlot.R (rev 0)
+++ pkg/Dowd/R/GParetoMEFPlot.R 2015-06-15 19:18:04 UTC (rev 3675)
@@ -0,0 +1,50 @@
+#' @title Plot of Emperical and Generalised Pareto mean excess functions
+#'
+#' @description Plots of emperical mean excess function and Generalized mean excess function.
+#'
+#' @param Ra Vector of daily Profit/Loss data
+#' @param mu Location parameter
+#' @param beta Scale parameter
+#' @param zeta Assumed tail index
+#'
+#' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
+#'
+#' @author Dinesh Acharya
+#' @examples
+#'
+#' # Computes ES assuming generalised Pareto for following parameters
+#' Ra <- 5 * randn(100)
+#' mu <- 1
+#' beta <- 1.2
+#' zeta <- 1.6
+#' GParetoMEFPlot(Ra, mu, beta, zeta)
+#'
+#' @export
+GParetoMEFPlot <- function(Ra, mu, beta, zeta) {
+ x <- as.vector(Ra)
+ x <- sort(x)
+ u <- x
+ n <- length(u)
+ mef <- double(n - 1)
+
+ for (i in 1:(n - 1)) {
+ x <- x[which(x > u[i])]
+ mef[i] <- mean(x) - u[i]
+ }
+
+ u <- t(u)
+ u <- u[u!=max(u)]
+ gpmef <- (1 + zeta * (u - mu) / beta)/(1 - zeta);
+ # Plot
+ # Limits of axis
+ xlims <- c(min(u),max(u))
+ ylims <- c(min(mef, gpmef), max(mef, gpmef))
+ plot(u , mef, xlims, ylims, type = "l", xlab = "Threshold (u)",
+ col = 6, ylab = "e(u)")
+ par(new = TRUE)
+ plot(u , gpmef, xlims, ylims, type = "l", xlab = "Threshold (u)",
+ col = 3, ylab = "e(u)")
+ title("Emperical and Generalised Pareto Mean Excess Functions")
+ legend("topright", legend = c("Emperical MEF", "Generalized Pareto MEF"), text.col = c(6,3))
+
+}
\ No newline at end of file
Added: pkg/Dowd/man/GParetoES.Rd
===================================================================
--- pkg/Dowd/man/GParetoES.Rd (rev 0)
+++ pkg/Dowd/man/GParetoES.Rd 2015-06-15 19:18:04 UTC (rev 3675)
@@ -0,0 +1,43 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/GParetoES.R
+\name{GParetoES}
+\alias{GParetoES}
+\title{Expected Shortfall for Generalized Pareto}
+\usage{
+GParetoES(Ra, beta, zeta, threshold.prob, cl)
+}
+\arguments{
+\item{Ra}{Vector of daily Profit/Loss data}
+
+\item{beta}{Assumed scale parameter}
+
+\item{zeta}{Assumed tail index}
+
+\item{threshold.prob}{Threshold probability}
+
+\item{cl}{VaR confidence level}
+}
+\value{
+Expected Shortfall
+}
+\description{
+Estimates the ES of a portfolio assuming losses are distributed as a generalised Pareto.
+}
+\examples{
+# Computes ES assuming generalised Pareto for following parameters
+ Ra <- 5 * randn(100)
+ beta <- 1.2
+ zeta <- 1.6
+ threshold.prob <- .85
+ cl <- .99
+ GParetoES(Ra, beta, zeta, threshold.prob, cl)
+}
+\author{
+Dinesh Acharya
+}
+\references{
+Dowd, K. Measuring Market Risk, Wiley, 2007.
+
+McNeil, A., Extreme value theory for risk managers. Mimeo, ETHZ, 1999.
+}
+
Added: pkg/Dowd/man/GParetoMEFPlot.Rd
===================================================================
--- pkg/Dowd/man/GParetoMEFPlot.Rd (rev 0)
+++ pkg/Dowd/man/GParetoMEFPlot.Rd 2015-06-15 19:18:04 UTC (rev 3675)
@@ -0,0 +1,35 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/GParetoMEFPlot.R
+\name{GParetoMEFPlot}
+\alias{GParetoMEFPlot}
+\title{Plot of Emperical and Generalised Pareto mean excess functions}
+\usage{
+GParetoMEFPlot(Ra, mu, beta, zeta)
+}
+\arguments{
+\item{Ra}{Vector of daily Profit/Loss data}
+
+\item{mu}{Location parameter}
+
+\item{beta}{Scale parameter}
+
+\item{zeta}{Assumed tail index}
+}
+\description{
+Plots of emperical mean excess function and Generalized mean excess function.
+}
+\examples{
+# Computes ES assuming generalised Pareto for following parameters
+ Ra <- 5 * randn(100)
+ mu <- 1
+ beta <- 1.2
+ zeta <- 1.6
+ GParetoMEFPlot(Ra, mu, beta, zeta)
+}
+\author{
+Dinesh Acharya
+}
+\references{
+Dowd, K. Measuring Market Risk, Wiley, 2007.
+}
+
More information about the Returnanalytics-commits
mailing list