[Returnanalytics-commits] r3661 - in pkg/Dowd: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Jun 4 02:09:54 CEST 2015
Author: dacharya
Date: 2015-06-04 02:09:54 +0200 (Thu, 04 Jun 2015)
New Revision: 3661
Added:
pkg/Dowd/R/CornishFisherES.R
pkg/Dowd/R/CornishFisherVaR.R
pkg/Dowd/man/CornishFisherES.Rd
pkg/Dowd/man/CornishFisherVaR.Rd
Modified:
pkg/Dowd/NAMESPACE
Log:
CornishFisherES and CornishFisherVaR: source and documentation.
Modified: pkg/Dowd/NAMESPACE
===================================================================
--- pkg/Dowd/NAMESPACE 2015-06-02 18:34:16 UTC (rev 3660)
+++ pkg/Dowd/NAMESPACE 2015-06-04 00:09:54 UTC (rev 3661)
@@ -14,6 +14,8 @@
export(CdfOfSumUsingProductCopula)
export(ChristoffersenBacktestForIndependence)
export(ChristoffersenBacktestForUnconditionalCoverage)
+export(CornishFisherES)
+export(CornishFisherVaR)
export(GaussianCopulaVaR)
export(GumbelCopulaVaR)
export(HSES)
Added: pkg/Dowd/R/CornishFisherES.R
===================================================================
--- pkg/Dowd/R/CornishFisherES.R (rev 0)
+++ pkg/Dowd/R/CornishFisherES.R 2015-06-04 00:09:54 UTC (rev 3661)
@@ -0,0 +1,45 @@
+#' Corn-Fisher ES
+#'
+#' Function estimates the ES for near-normal P/L using the Cornish-Fisher
+#' adjustment for non-normality, for specified confidence level.
+#'
+#' @param mu Mean of P/L distribution
+#' @param sigma Variance of of P/L distribution
+#' @param skew Skew of P/L distribution
+#' @param kurtosis Kurtosis of P/L distribution
+#' @param cl ES confidence level
+#' @return Expected Shortfall
+#'
+#' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
+#'
+#' Zangri, P. A VaR methodology for portfolios that include options.
+#' RiskMetrics Monitor, First quarter, 1996, p. 4-12.
+#'
+#' @author Dinesh Acharya
+#' @examples
+#'
+#' # Estimates Cornish-Fisher ES for given parameters
+#' CornishFisherES(3.2, 5.6, 2, 3, .9)
+#'
+#' @export
+CornishFisherES <- function(mu, sigma, skew, kurtosis, cl) {
+ # ES estimation
+ confidence.level <- cl
+ delta.cl <- (1 - confidence.level)/100
+ cl <- double(99)
+ z <- double(99)
+ VaR <- double(99)
+ adjustment <- double(99)
+ cl[1] <- confidence.level
+ for (i in 1:98){
+ cl [i] <- cl[1] + i * delta.cl
+ z[i] <- qnorm(1 - cl[i], 0, 1)
+ adjustment[i] <- (1/6) * (z[i]^2 - 1) * skew +
+ (1/24) * (z[i]^3 - 3 * z[i]) * (kurtosis - 3) -
+ (1/36) * (2 * z[i]^3 - 5 * z[i]) * skew^2
+ VaR[i] <- - sigma * (z[i] + adjustment[i]) - mu
+ }
+ y <- mean(VaR)
+ return(y)
+
+}
\ No newline at end of file
Added: pkg/Dowd/R/CornishFisherVaR.R
===================================================================
--- pkg/Dowd/R/CornishFisherVaR.R (rev 0)
+++ pkg/Dowd/R/CornishFisherVaR.R 2015-06-04 00:09:54 UTC (rev 3661)
@@ -0,0 +1,36 @@
+#' Corn-Fisher VaR
+#'
+#' Function estimates the VaR for near-normal P/L using the Cornish-Fisher
+#' adjustment for non-normality, for specified confidence level.
+#'
+#' @param mu Mean of P/L distribution
+#' @param sigma Variance of of P/L distribution
+#' @param skew Skew of P/L distribution
+#' @param kurtosis Kurtosis of P/L distribution
+#' @param cl VaR confidence level
+#' @return Value at Risk
+#'
+#' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
+#'
+#' Zangri, P. A VaR methodology for portfolios that include options.
+#' RiskMetrics Monitor, First quarter, 1996, p. 4-12.
+#'
+#' @author Dinesh Acharya
+#' @examples
+#'
+#' # Estimates Cornish-Fisher VaR for given parameters
+#' CornishFisherVaR(3.2, 5.6, 2, 3, .9)
+#'
+#' @export
+CornishFisherVaR <- function(mu, sigma, skew, kurtosis, cl) {
+ # Normal variate
+ z <- qnorm(1 - cl, 0, 1)
+ # Deriving adjustment factor
+ adjustment <- (1/6) * (z^2 - 1) * skew +
+ (1/24) * (z^3 - 3 * z) * (kurtosis - 3) -
+ (1/36) * (2 * z^3 - 5 * z) * skew^2
+ # VaR estimation
+ y <- - sigma * (z + adjustment) - mu
+ return(y)
+
+}
\ No newline at end of file
Added: pkg/Dowd/man/CornishFisherES.Rd
===================================================================
--- pkg/Dowd/man/CornishFisherES.Rd (rev 0)
+++ pkg/Dowd/man/CornishFisherES.Rd 2015-06-04 00:09:54 UTC (rev 3661)
@@ -0,0 +1,40 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/CornishFisherES.R
+\name{CornishFisherES}
+\alias{CornishFisherES}
+\title{Corn-Fisher ES}
+\usage{
+CornishFisherES(mu, sigma, skew, kurtosis, cl)
+}
+\arguments{
+\item{mu}{Mean of P/L distribution}
+
+\item{sigma}{Variance of of P/L distribution}
+
+\item{skew}{Skew of P/L distribution}
+
+\item{kurtosis}{Kurtosis of P/L distribution}
+
+\item{cl}{ES confidence level}
+}
+\value{
+Expected Shortfall
+}
+\description{
+Function estimates the ES for near-normal P/L using the Cornish-Fisher
+adjustment for non-normality, for specified confidence level.
+}
+\examples{
+# Estimates Cornish-Fisher ES for given parameters
+ CornishFisherES(3.2, 5.6, 2, 3, .9)
+}
+\author{
+Dinesh Acharya
+}
+\references{
+Dowd, K. Measuring Market Risk, Wiley, 2007.
+
+Zangri, P. A VaR methodology for portfolios that include options.
+RiskMetrics Monitor, First quarter, 1996, p. 4-12.
+}
+
Added: pkg/Dowd/man/CornishFisherVaR.Rd
===================================================================
--- pkg/Dowd/man/CornishFisherVaR.Rd (rev 0)
+++ pkg/Dowd/man/CornishFisherVaR.Rd 2015-06-04 00:09:54 UTC (rev 3661)
@@ -0,0 +1,40 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/CornishFisherVaR.R
+\name{CornishFisherVaR}
+\alias{CornishFisherVaR}
+\title{Corn-Fisher VaR}
+\usage{
+CornishFisherVaR(mu, sigma, skew, kurtosis, cl)
+}
+\arguments{
+\item{mu}{Mean of P/L distribution}
+
+\item{sigma}{Variance of of P/L distribution}
+
+\item{skew}{Skew of P/L distribution}
+
+\item{kurtosis}{Kurtosis of P/L distribution}
+
+\item{cl}{VaR confidence level}
+}
+\value{
+Value at Risk
+}
+\description{
+Function estimates the VaR for near-normal P/L using the Cornish-Fisher
+adjustment for non-normality, for specified confidence level.
+}
+\examples{
+# Estimates Cornish-Fisher VaR for given parameters
+ CornishFisherVaR(3.2, 5.6, 2, 3, .9)
+}
+\author{
+Dinesh Acharya
+}
+\references{
+Dowd, K. Measuring Market Risk, Wiley, 2007.
+
+Zangri, P. A VaR methodology for portfolios that include options.
+RiskMetrics Monitor, First quarter, 1996, p. 4-12.
+}
+
More information about the Returnanalytics-commits
mailing list