[Returnanalytics-commits] r3672 - in pkg/Dowd: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Jun 11 23:45:59 CEST 2015
Author: dacharya
Date: 2015-06-11 23:45:59 +0200 (Thu, 11 Jun 2015)
New Revision: 3672
Added:
pkg/Dowd/R/FrechetESPlot2DCl.R
pkg/Dowd/R/FrechetVaRPlot2DCl.R
pkg/Dowd/man/FrechetESPlot2DCl.Rd
pkg/Dowd/man/FrechetVaRPlot2DCl.Rd
Modified:
pkg/Dowd/NAMESPACE
pkg/Dowd/R/FrechetES.R
pkg/Dowd/R/FrechetVaR.R
pkg/Dowd/man/FrechetES.Rd
pkg/Dowd/man/FrechetVaR.Rd
Log:
FrechetESPlot2DCl and FrechetVaRPlot2DCl: source and documentation
Modified: pkg/Dowd/NAMESPACE
===================================================================
--- pkg/Dowd/NAMESPACE 2015-06-10 21:12:55 UTC (rev 3671)
+++ pkg/Dowd/NAMESPACE 2015-06-11 21:45:59 UTC (rev 3672)
@@ -17,7 +17,9 @@
export(CornishFisherES)
export(CornishFisherVaR)
export(FrechetES)
+export(FrechetESPlot2DCl)
export(FrechetVaR)
+export(FrechetVaRPlot2DCl)
export(GaussianCopulaVaR)
export(GumbelCopulaVaR)
export(HSES)
Modified: pkg/Dowd/R/FrechetES.R
===================================================================
--- pkg/Dowd/R/FrechetES.R 2015-06-10 21:12:55 UTC (rev 3671)
+++ pkg/Dowd/R/FrechetES.R 2015-06-11 21:45:59 UTC (rev 3672)
@@ -1,6 +1,6 @@
#' Frechet Expected Shortfall
#'
-#' Plots the ES of a portfolio against confidence level assuming extreme losses
+#' Estimates the ES of a portfolio assuming extreme losses
#' are Frechet distributed, for specified confidence level and a given
#' holding period.
#'
Added: pkg/Dowd/R/FrechetESPlot2DCl.R
===================================================================
--- pkg/Dowd/R/FrechetESPlot2DCl.R (rev 0)
+++ pkg/Dowd/R/FrechetESPlot2DCl.R 2015-06-11 21:45:59 UTC (rev 3672)
@@ -0,0 +1,110 @@
+#' Plots Frechet Expected Shortfall against confidence level
+#'
+#' Plots the ES of a portfolio against confidence level assuming extreme losses
+#' are Frechet distributed, for specified confidence level and a given
+#' holding period.
+#'
+#' Note that the long-right-hand tail is fitted to losses, not profits.
+#'
+#'
+#' @param mu Location parameter for daily L/P
+#' @param sigma Scale parameter for daily L/P
+#' @param tail.index Tail index
+#' @param n Block size from which maxima are drawn
+#' @param cl Confidence level and should be a vector
+#' @param hp Holding period
+#'
+#' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
+#'
+#' Embrechts, P., Kluppelberg, C. and Mikosch, T., Modelling Extremal Events for
+#' Insurance and Finance. Springer, Berlin, 1997, p. 324.
+#'
+#' Reiss, R. D. and Thomas, M. Statistical Analysis of Extreme Values from
+#' Insurance, Finance, Hydrology and Other Fields, Birkhaueser, Basel, 1997,
+#' 15-18.
+#'
+#' @author Dinesh Acharya
+#' @examples
+#'
+#' # Plots ES against vector of cl assuming Frechet Distribution for given parameters
+#' cl <- seq(0.9,0.99,0.01)
+#' FrechetESPlot2DCl(3.5, 2.3, 1.6, 10, cl, 30)
+#'
+#' @export
+FrechetESPlot2DCl <- function(mu, sigma, tail.index, n, cl, hp){
+
+ # Check that inputs have correct dimensions
+ if (!length(mu) == 1) {
+ stop("mu must be a scalar")
+ }
+ if (!length(sigma) == 1) {
+ stop("sigma must be a scalar")
+ }
+ if (!length(tail.index) == 1) {
+ stop("tail.index must be a scalar")
+ }
+ if (!is.vector(cl)) {
+ stop("cl must be a vector")
+ }
+ if (!length(hp) == 1) {
+ stop("hp must be a scalar")
+ }
+
+ # Change cl to row vector
+ cl <- t(as.matrix(cl))
+
+ # Check that parameters obey sign and value restrictions
+ if (sigma < 0) {
+ stop("Standard deviation must be non-negative")
+ }
+ if (min(tail.index) <= 0) {
+ stop("Tail index must be greater than 0")
+ }
+ 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")
+ }
+ if ( min(cl) <= 0){
+ stop("Holding period(s) must be greater than 0")
+ }
+
+ # VaR estimation
+ VaR <- mu * matrix(1, 1, length(cl)) - (sigma / tail.index) *
+ (1 - ( - n * log(cl)) ^ ( - tail.index))
+
+ # ES Estimation
+ number.slices <- 1000 # Number of slices into which tail is divided
+ cl0 <- cl # Initial confidence level
+ term <- VaR
+
+ delta.cl <- (1 - cl) / number.slices # Increment to confidence level as each slice is taken
+ for (i in 1:(number.slices-1)) {
+ cl <- cl0 + i * delta.cl # Revised cl
+ term <- term + mu * matrix(1, 1, length(cl)) - (sigma / tail.index) *
+ (1 - ( - n * log(cl)) ^ ( - tail.index))
+ # NB Frechet term
+ }
+
+ es <- term / (number.slices - 1)
+ plot(cl0, es, type = "l", xlab = "Confidence level", ylab = "VaR",
+ main = "Frechet ES against confidence level")
+
+ text(mean(cl0),
+ max(es) - .1*(max(es) - min(es)),
+ 'Input parameters')
+ text(mean(cl0),
+ max(es)-.2*(max(es)-min(es)),
+ paste('Location parameter for daily L/P = ', mu))
+ text(mean(cl0),
+ max(es) - .3 * (max(es) - min(es)),
+ paste('Scale parameter for daily L/P = ', sigma))
+ text(mean(cl0),
+ max(es) - .4 * (max(es) - min(es)),
+ paste('Tail index = ', tail.index))
+ text(mean(cl0),
+ max(es) - .5 * (max(es) - min(es)),
+ paste('Holding period = ', hp, ' days'))
+
+}
\ No newline at end of file
Modified: pkg/Dowd/R/FrechetVaR.R
===================================================================
--- pkg/Dowd/R/FrechetVaR.R 2015-06-10 21:12:55 UTC (rev 3671)
+++ pkg/Dowd/R/FrechetVaR.R 2015-06-11 21:45:59 UTC (rev 3672)
@@ -1,6 +1,6 @@
#' Frechet Value at Risk
#'
-#' Plots the VaR of a portfolio against confidence level assuming extreme losses
+#' Estimates the VaR of a portfolio assuming extreme losses
#' are Frechet distributed, for specified range of confidence level and a given
#' holding period.
#'
Added: pkg/Dowd/R/FrechetVaRPlot2DCl.R
===================================================================
--- pkg/Dowd/R/FrechetVaRPlot2DCl.R (rev 0)
+++ pkg/Dowd/R/FrechetVaRPlot2DCl.R 2015-06-11 21:45:59 UTC (rev 3672)
@@ -0,0 +1,93 @@
+#' Plots Frechet Value at Risk against Cl
+#'
+#' Plots the VaR of a portfolio against confidence level assuming extreme losses
+#' are Frechet distributed, for specified range of confidence level and a given
+#' holding period.
+#'
+#' Note that the long-right-hand tail is fitted to losses, not profits.
+#'
+#'
+#' @param mu Location parameter for daily L/P
+#' @param sigma Scale parameter for daily L/P
+#' @param tail.index Tail index
+#' @param n Block size from which maxima are drawn
+#' @param cl Confidence level and should be a vector
+#' @param hp Holding period and should be a scalar
+#'
+#' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
+#'
+#' Embrechts, P., Kluppelberg, C. and Mikosch, T., Modelling Extremal Events for
+#' Insurance and Finance. Springer, Berlin, 1997, p. 324.
+#'
+#' Reiss, R. D. and Thomas, M. Statistical Analysis of Extreme Values from
+#' Insurance, Finance, Hydrology and Other Fields, Birkhaueser, Basel, 1997,
+#' 15-18.
+#'
+#' @author Dinesh Acharya
+#' @examples
+#'
+#' # Plots VaR against vector of cl assuming Frechet Distribution for given parameters
+#' cl <- seq(0.9, .99, .01)
+#' FrechetVaRPlot2DCl(3.5, 2.3, 1.6, 10, cl, 30)
+#'
+#' @export
+FrechetVaRPlot2DCl <- function(mu, sigma, tail.index, n, cl, hp){
+
+ # Check that inputs have correct dimensions
+ if (!length(mu) == 1) {
+ stop("mu must be a scalar")
+ }
+ if (!length(sigma) == 1) {
+ stop("sigma must be a scalar")
+ }
+ if (!length(tail.index) == 1) {
+ stop("tail.index must be a scalar")
+ }
+ if (!is.vector(cl)) {
+ stop("cl must be a vector or a scalar")
+ }
+ if (!is.vector(hp)) {
+ stop("hp must be a vector or a scalar")
+ }
+
+ # Change cl to row vector
+ cl <- t(as.matrix(cl))
+
+ # Check that parameters obey sign and value restrictions
+ if (sigma < 0) {
+ stop("Standard deviation must be non-negative")
+ }
+ if (min(tail.index) <= 0) {
+ stop("Tail index must be greater than 0")
+ }
+ 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")
+ }
+ if ( min(cl) <= 0){
+ stop("Holding period(s) must be greater than 0")
+ }
+ # VaR estimation
+ VaR <- mu * matrix(1, 1, length(cl)) - (sigma / tail.index) *
+ (1 - ( - n * log(cl)) ^ ( - tail.index))
+ # Plotting
+ plot(cl, VaR, type = "l", xlab = "Confidence level", ylab = "VaR", main = "Frechet VaR against confidence level")
+ text(mean(cl),
+ max(VaR) - .1*(max(VaR) - min(VaR)),
+ 'Input parameters')
+ text(mean(cl),
+ max(VaR)-.2*(max(VaR)-min(VaR)),
+ paste('Location parameter for daily L/P = ', mu))
+ text(mean(cl),
+ max(VaR) - .3 * (max(VaR) - min(VaR)),
+ paste('Scale parameter for daily L/P = ', sigma))
+ text(mean(cl),
+ max(VaR) - .4 * (max(VaR) - min(VaR)),
+ paste('Tail index = ', tail.index))
+ text(mean(cl),
+ max(VaR) - .5 * (max(VaR) - min(VaR)),
+ paste('Holding period = ', hp, ' days'))
+
+}
\ No newline at end of file
Modified: pkg/Dowd/man/FrechetES.Rd
===================================================================
--- pkg/Dowd/man/FrechetES.Rd 2015-06-10 21:12:55 UTC (rev 3671)
+++ pkg/Dowd/man/FrechetES.Rd 2015-06-11 21:45:59 UTC (rev 3672)
@@ -25,7 +25,7 @@
cl and hp are vectors, returns a matrix of VaRs.
}
\description{
-Plots the ES of a portfolio against confidence level assuming extreme losses
+Estimates the ES of a portfolio assuming extreme losses
are Frechet distributed, for specified confidence level and a given
holding period.
}
Added: pkg/Dowd/man/FrechetESPlot2DCl.Rd
===================================================================
--- pkg/Dowd/man/FrechetESPlot2DCl.Rd (rev 0)
+++ pkg/Dowd/man/FrechetESPlot2DCl.Rd 2015-06-11 21:45:59 UTC (rev 3672)
@@ -0,0 +1,48 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/FrechetESPlot2DCl.R
+\name{FrechetESPlot2DCl}
+\alias{FrechetESPlot2DCl}
+\title{Plots Frechet Expected Shortfall against confidence level}
+\usage{
+FrechetESPlot2DCl(mu, sigma, tail.index, n, cl, hp)
+}
+\arguments{
+\item{mu}{Location parameter for daily L/P}
+
+\item{sigma}{Scale parameter for daily L/P}
+
+\item{tail.index}{Tail index}
+
+\item{n}{Block size from which maxima are drawn}
+
+\item{cl}{Confidence level and should be a vector}
+
+\item{hp}{Holding period}
+}
+\description{
+Plots the ES of a portfolio against confidence level assuming extreme losses
+are Frechet distributed, for specified confidence level and a given
+holding period.
+}
+\details{
+Note that the long-right-hand tail is fitted to losses, not profits.
+}
+\examples{
+# Plots ES against vector of cl assuming Frechet Distribution for given parameters
+ cl <- seq(0.9,0.99,0.01)
+ FrechetESPlot2DCl(3.5, 2.3, 1.6, 10, cl, 30)
+}
+\author{
+Dinesh Acharya
+}
+\references{
+Dowd, K. Measuring Market Risk, Wiley, 2007.
+
+Embrechts, P., Kluppelberg, C. and Mikosch, T., Modelling Extremal Events for
+Insurance and Finance. Springer, Berlin, 1997, p. 324.
+
+Reiss, R. D. and Thomas, M. Statistical Analysis of Extreme Values from
+Insurance, Finance, Hydrology and Other Fields, Birkhaueser, Basel, 1997,
+15-18.
+}
+
Modified: pkg/Dowd/man/FrechetVaR.Rd
===================================================================
--- pkg/Dowd/man/FrechetVaR.Rd 2015-06-10 21:12:55 UTC (rev 3671)
+++ pkg/Dowd/man/FrechetVaR.Rd 2015-06-11 21:45:59 UTC (rev 3672)
@@ -25,7 +25,7 @@
cl and hp are vectors, returns a matrix of VaRs.
}
\description{
-Plots the VaR of a portfolio against confidence level assuming extreme losses
+Estimates the VaR of a portfolio assuming extreme losses
are Frechet distributed, for specified range of confidence level and a given
holding period.
}
Added: pkg/Dowd/man/FrechetVaRPlot2DCl.Rd
===================================================================
--- pkg/Dowd/man/FrechetVaRPlot2DCl.Rd (rev 0)
+++ pkg/Dowd/man/FrechetVaRPlot2DCl.Rd 2015-06-11 21:45:59 UTC (rev 3672)
@@ -0,0 +1,48 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/FrechetVaRPlot2DCl.R
+\name{FrechetVaRPlot2DCl}
+\alias{FrechetVaRPlot2DCl}
+\title{Plots Frechet Value at Risk against Cl}
+\usage{
+FrechetVaRPlot2DCl(mu, sigma, tail.index, n, cl, hp)
+}
+\arguments{
+\item{mu}{Location parameter for daily L/P}
+
+\item{sigma}{Scale parameter for daily L/P}
+
+\item{tail.index}{Tail index}
+
+\item{n}{Block size from which maxima are drawn}
+
+\item{cl}{Confidence level and should be a vector}
+
+\item{hp}{Holding period and should be a scalar}
+}
+\description{
+Plots the VaR of a portfolio against confidence level assuming extreme losses
+are Frechet distributed, for specified range of confidence level and a given
+holding period.
+}
+\details{
+Note that the long-right-hand tail is fitted to losses, not profits.
+}
+\examples{
+# Plots VaR against vector of cl assuming Frechet Distribution for given parameters
+ cl <- seq(0.9, .99, .01)
+ FrechetVaRPlot2DCl(3.5, 2.3, 1.6, 10, cl, 30)
+}
+\author{
+Dinesh Acharya
+}
+\references{
+Dowd, K. Measuring Market Risk, Wiley, 2007.
+
+Embrechts, P., Kluppelberg, C. and Mikosch, T., Modelling Extremal Events for
+Insurance and Finance. Springer, Berlin, 1997, p. 324.
+
+Reiss, R. D. and Thomas, M. Statistical Analysis of Extreme Values from
+Insurance, Finance, Hydrology and Other Fields, Birkhaueser, Basel, 1997,
+15-18.
+}
+
More information about the Returnanalytics-commits
mailing list