[Returnanalytics-commits] r3679 - in pkg/Dowd: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Jun 18 02:11:57 CEST 2015
Author: dacharya
Date: 2015-06-18 02:11:57 +0200 (Thu, 18 Jun 2015)
New Revision: 3679
Added:
pkg/Dowd/R/HSVaRFigure.R
pkg/Dowd/man/HSVaRFigure.Rd
Modified:
pkg/Dowd/NAMESPACE
Log:
HSVaRFigure: source and documentation
Modified: pkg/Dowd/NAMESPACE
===================================================================
--- pkg/Dowd/NAMESPACE 2015-06-17 23:16:50 UTC (rev 3678)
+++ pkg/Dowd/NAMESPACE 2015-06-18 00:11:57 UTC (rev 3679)
@@ -35,6 +35,7 @@
export(HSES)
export(HSVaR)
export(HSVaRDFPerc)
+export(HSVaRFigure)
export(HillEstimator)
export(HillPlot)
export(HillQuantileEstimator)
Added: pkg/Dowd/R/HSVaRFigure.R
===================================================================
--- pkg/Dowd/R/HSVaRFigure.R (rev 0)
+++ pkg/Dowd/R/HSVaRFigure.R 2015-06-18 00:11:57 UTC (rev 3679)
@@ -0,0 +1,54 @@
+#' @title Figure of Historical SImulation VaR and histogram of L/P
+#'
+#' @description Plots figure showing the historical simulation VaR and histogram
+#' of L/P for specified confidence level and holding period implied by data
+#' frequency.
+#'
+#' @param Ra Vector of profit loss data
+#' @param cl ES confidence level
+#'
+#' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
+#'
+#' @author Dinesh Acharya
+#' @examples
+#'
+#' # Plots figure showing VaR and histogram of P/L data
+#' Ra <- rnorm(100)
+#' HSVaRFigure(Ra, .95)
+#'
+#' @export
+HSVaRFigure<- function(Ra, cl){
+ # Determine if there are two arguments and ensure that arguments are read as intended
+ if (nargs() < 2) {
+ stop("Too few arguments")
+ }
+ if (nargs() > 2){
+ stop("Too many arguments")
+ }
+ if (nargs() == 2){
+ profit.loss <- as.vector(Ra)
+ n <- length(profit.loss)
+ }
+
+ # Check that inputs have correct dimensions
+ if (length(cl) != 1) {
+ stop("Confidence level must be a scalar")
+ }
+
+ if ( cl >= 1){
+ stop("Confidence level must be less than 1")
+ }
+
+ # VaR estimation
+ VaR <- HSVaR(profit.loss, cl) # HS VaR
+ # Histogram
+ n <- hist(profit.loss, main = "Historical Simulation VaR", col = 4,
+ xlab = "Loss(+) / Profit(-)", ylab = "Frequency")
+ v <- c(0, .625 * max(n$counts)) # Coordinates for VaR line
+ u <- VaR * matrix(1, length(v),1) # Coordinates for VaR line
+ lines(u, v, type = "l", col="blue")
+ cl.for.label <- 100 * cl
+ legend("topleft",c(paste('VaR at', cl.for.label, '% CL'),
+ paste('=', VaR)), bty="n", cex = 0.7)
+
+}
\ No newline at end of file
Added: pkg/Dowd/man/HSVaRFigure.Rd
===================================================================
--- pkg/Dowd/man/HSVaRFigure.Rd (rev 0)
+++ pkg/Dowd/man/HSVaRFigure.Rd 2015-06-18 00:11:57 UTC (rev 3679)
@@ -0,0 +1,30 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/HSVaRFigure.R
+\name{HSVaRFigure}
+\alias{HSVaRFigure}
+\title{Figure of Historical SImulation VaR and histogram of L/P}
+\usage{
+HSVaRFigure(Ra, cl)
+}
+\arguments{
+\item{Ra}{Vector of profit loss data}
+
+\item{cl}{ES confidence level}
+}
+\description{
+Plots figure showing the historical simulation VaR and histogram
+ of L/P for specified confidence level and holding period implied by data
+ frequency.
+}
+\examples{
+# Plots figure showing VaR and histogram of P/L data
+ Ra <- rnorm(100)
+ HSVaRFigure(Ra, .95)
+}
+\author{
+Dinesh Acharya
+}
+\references{
+Dowd, K. Measuring Market Risk, Wiley, 2007.
+}
+
More information about the Returnanalytics-commits
mailing list