[Returnanalytics-commits] r3681 - in pkg/Dowd: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jun 19 00:35:27 CEST 2015
Author: dacharya
Date: 2015-06-19 00:35:26 +0200 (Fri, 19 Jun 2015)
New Revision: 3681
Added:
pkg/Dowd/R/AdjustedVarianceCovarianceVaR.R
pkg/Dowd/man/AdjustedVarianceCovarianceVaR.Rd
Modified:
pkg/Dowd/NAMESPACE
pkg/Dowd/R/AdjustedNormalESHotspots.R
pkg/Dowd/R/AdjustedNormalVaRHotspots.R
pkg/Dowd/man/AdjustedNormalESHotspots.Rd
pkg/Dowd/man/AdjustedNormalVaRHotspots.Rd
Log:
AdjustedVarianceCovarianceVaR: source and documentation
Modified: pkg/Dowd/NAMESPACE
===================================================================
--- pkg/Dowd/NAMESPACE 2015-06-18 21:54:56 UTC (rev 3680)
+++ pkg/Dowd/NAMESPACE 2015-06-18 22:35:26 UTC (rev 3681)
@@ -4,6 +4,7 @@
export(AdjustedNormalESHotspots)
export(AdjustedNormalVaRHotspots)
export(AdjustedVarianceCovarianceES)
+export(AdjustedVarianceCovarianceVaR)
export(BinomialBacktest)
export(BlancoIhleBacktest)
export(BootstrapES)
Modified: pkg/Dowd/R/AdjustedNormalESHotspots.R
===================================================================
--- pkg/Dowd/R/AdjustedNormalESHotspots.R 2015-06-18 21:54:56 UTC (rev 3680)
+++ pkg/Dowd/R/AdjustedNormalESHotspots.R 2015-06-18 22:35:26 UTC (rev 3681)
@@ -20,7 +20,7 @@
#'
#' # Hotspots for ES for randomly generated portfolio
#' vc.matrix <- matrix(rnorm(16),4,4)
-#' return <- rnorm(4)
+#' mu <- rnorm(4)
#' skew <- .5
#' kurtosis <- 1.2
#' positions <- c(5,2,6,10)
Modified: pkg/Dowd/R/AdjustedNormalVaRHotspots.R
===================================================================
--- pkg/Dowd/R/AdjustedNormalVaRHotspots.R 2015-06-18 21:54:56 UTC (rev 3680)
+++ pkg/Dowd/R/AdjustedNormalVaRHotspots.R 2015-06-18 22:35:26 UTC (rev 3681)
@@ -20,13 +20,13 @@
#'
#' # Hotspots for ES for randomly generated portfolio
#' vc.matrix <- matrix(rnorm(16),4,4)
-#' return <- rnorm(4)
+#' mu <- rnorm(4)
#' skew <- .5
#' kurtosis <- 1.2
#' positions <- c(5,2,6,10)
#' cl <- .95
#' hp <- 280
-#' AdjustedNormalESHotsopts(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
+#' AdjustedNormalVaRHotspots(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
#'
#' @export
AdjustedNormalVaRHotspots <- function(vc.matrix, mu, skew, kurtosis, positions, cl, hp){
Added: pkg/Dowd/R/AdjustedVarianceCovarianceVaR.R
===================================================================
--- pkg/Dowd/R/AdjustedVarianceCovarianceVaR.R (rev 0)
+++ pkg/Dowd/R/AdjustedVarianceCovarianceVaR.R 2015-06-18 22:35:26 UTC (rev 3681)
@@ -0,0 +1,94 @@
+#' @title Cornish-Fisher adjusted variance-covariance VaR
+#'
+#' @description Estimates the variance-covariance VaR of a multi-asset portfolio using the Cornish-Fisher adjustment for portfolio-return non-normality, for specified confidence level and holding period.
+#'
+#' @param vc.matrix Assumed variance covariance matrix for returns
+#' @param mu Vector of expected position returns
+#' @param skew Portfolio return skewness
+#' @param kurtisos Portfolio return kurtosis
+#' @param positions Vector of positions
+#' @param cl Confidence level and is scalar or vector
+#' @param hp Holding period and is scalar or vector
+#'
+#' @references Dowd, K. Measurh ing Market Risk, Wiley, 2007.
+#'
+#' @author Dinesh Acharya
+#'
+#' @examples
+#'
+#' # Variance-covariance for randomly generated portfolio
+#' vc.matrix <- matrix(rnorm(16),4,4)
+#' return <- rnorm(4)
+#' skew <- .5
+#' kurtosis <- 1.2
+#' positions <- c(5,2,6,10)
+#' cl <- .95
+#' hp <- 280
+#' AdjustedNormalESHotsopts(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
+#'
+#' @export
+AdjustedVarianceCovarianceVaR <- function(vc.matrix, mu, skew, kurtosis, positions, cl, hp){
+
+ # Check that confidence level is read as a row vector
+ cl <- as.matrix(cl)
+ if (dim(cl)[1] > dim(cl)[2]){
+ cl <- t(cl)
+ }
+
+ # Check that hp is read as a column vector
+ hp <- as.matrix(hp)
+ if (dim(hp)[1] < dim(hp)[2]){
+ hp <- t(hp)
+ }
+
+ # Check that positions vector read as a scalar or row vector
+ positions <- as.matrix(positions)
+ if (dim(positions)[1] > dim(positions)[2]){
+ positions <- t(positions)
+ }
+
+ # Check that expected returns vector is read as a scalar or row vector
+ mu <- as.matrix(mu)
+ if (dim(mu)[1] > dim(mu)[2]){
+ mu <- t(mu)
+ }
+
+ # Check that dimensions are correct
+ if (max(dim(mu)) != max(dim(positions))){
+ stop("Positions vector and expected returns vector must have same size")
+ }
+ vc.matrix <- as.matrix(vc.matrix)
+ if (max(dim(vc.matrix)) != max(dim(positions))){
+ stop("Positions vector and expected returns vector must have same size")
+ }
+
+ # Check that inputs obey sign and value restrictions
+ if (cl >= 1){
+ stop("Confidence level must be less than 1")
+ }
+ if (cl <= 0){
+ stop("Confidence level must be greater than 0");
+ }
+ if (hp <= 0){
+ stop("Holding period must be greater than 0");
+ }
+
+ # Portfolio return standard deviation
+ sigma <- positions %*% vc.matrix %*% t(positions)/(sum(positions)^2) # standard deviation of portfolio returns
+ # VaR estimation
+ z <- double(length(cl))
+ adjustment <- z
+ VaR <- matrix(0, length(cl), length(hp))
+
+ for (i in 1:length(cl)) {
+ # Cornish-Fisher adjustment
+ 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
+ for (j in 1:length(hp)) {
+ VaR[i, j] <- - mu %*% t(positions) * hp[j] - (z[i] + adjustment[i]) * sigma * (sum(positions)^2) * sqrt(hp[j])
+ }
+ }
+ y <- t(VaR)
+ return(y)
+
+}
\ No newline at end of file
Modified: pkg/Dowd/man/AdjustedNormalESHotspots.Rd
===================================================================
--- pkg/Dowd/man/AdjustedNormalESHotspots.Rd 2015-06-18 21:54:56 UTC (rev 3680)
+++ pkg/Dowd/man/AdjustedNormalESHotspots.Rd 2015-06-18 22:35:26 UTC (rev 3681)
@@ -29,7 +29,7 @@
\examples{
# Hotspots for ES for randomly generated portfolio
vc.matrix <- matrix(rnorm(16),4,4)
- return <- rnorm(4)
+ mu <- rnorm(4)
skew <- .5
kurtosis <- 1.2
positions <- c(5,2,6,10)
Modified: pkg/Dowd/man/AdjustedNormalVaRHotspots.Rd
===================================================================
--- pkg/Dowd/man/AdjustedNormalVaRHotspots.Rd 2015-06-18 21:54:56 UTC (rev 3680)
+++ pkg/Dowd/man/AdjustedNormalVaRHotspots.Rd 2015-06-18 22:35:26 UTC (rev 3681)
@@ -29,13 +29,13 @@
\examples{
# Hotspots for ES for randomly generated portfolio
vc.matrix <- matrix(rnorm(16),4,4)
- return <- rnorm(4)
+ mu <- rnorm(4)
skew <- .5
kurtosis <- 1.2
positions <- c(5,2,6,10)
cl <- .95
hp <- 280
- AdjustedNormalESHotsopts(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
+ AdjustedNormalVaRHotspots(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
}
\author{
Dinesh Acharya
Added: pkg/Dowd/man/AdjustedVarianceCovarianceVaR.Rd
===================================================================
--- pkg/Dowd/man/AdjustedVarianceCovarianceVaR.Rd (rev 0)
+++ pkg/Dowd/man/AdjustedVarianceCovarianceVaR.Rd 2015-06-18 22:35:26 UTC (rev 3681)
@@ -0,0 +1,44 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/AdjustedVarianceCovarianceVaR.R
+\name{AdjustedVarianceCovarianceVaR}
+\alias{AdjustedVarianceCovarianceVaR}
+\title{Cornish-Fisher adjusted variance-covariance VaR}
+\usage{
+AdjustedVarianceCovarianceVaR(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
+}
+\arguments{
+\item{vc.matrix}{Assumed variance covariance matrix for returns}
+
+\item{mu}{Vector of expected position returns}
+
+\item{skew}{Portfolio return skewness}
+
+\item{positions}{Vector of positions}
+
+\item{cl}{Confidence level and is scalar or vector}
+
+\item{hp}{Holding period and is scalar or vector}
+
+\item{kurtisos}{Portfolio return kurtosis}
+}
+\description{
+Estimates the variance-covariance VaR of a multi-asset portfolio using the Cornish-Fisher adjustment for portfolio-return non-normality, for specified confidence level and holding period.
+}
+\examples{
+# Variance-covariance for randomly generated portfolio
+ vc.matrix <- matrix(rnorm(16),4,4)
+ return <- rnorm(4)
+ skew <- .5
+ kurtosis <- 1.2
+ positions <- c(5,2,6,10)
+ cl <- .95
+ hp <- 280
+ AdjustedNormalESHotsopts(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
+}
+\author{
+Dinesh Acharya
+}
+\references{
+Dowd, K. Measurh ing Market Risk, Wiley, 2007.
+}
+
More information about the Returnanalytics-commits
mailing list