[Returnanalytics-commits] r3751 - in pkg/Dowd: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jun 26 20:49:05 CEST 2015
Author: dacharya
Date: 2015-06-26 20:49:04 +0200 (Fri, 26 Jun 2015)
New Revision: 3751
Added:
pkg/Dowd/R/HSVaRPlot2DCl.R
pkg/Dowd/man/HSVaRPlot2DCl.Rd
Log:
HSVaRPlot2DCl added.
Added: pkg/Dowd/R/HSVaRPlot2DCl.R
===================================================================
--- pkg/Dowd/R/HSVaRPlot2DCl.R (rev 0)
+++ pkg/Dowd/R/HSVaRPlot2DCl.R 2015-06-26 18:49:04 UTC (rev 3751)
@@ -0,0 +1,62 @@
+#' @title Plots historical simulation VaR against confidence level
+#'
+#' @description Function plots the historical simulation VaR of a
+#' portfolio against confidence level, for specified range of confidence level
+#' and holding period implied by data frequency.
+#'
+#' @param Ra Vector of daily P/L data
+#' @param cl Vector of VaR confidence levels
+#'
+#' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
+#'
+#' @author Dinesh Acharya
+#' @examples
+#'
+#' # Plots historical simulation VaR against confidence level
+#' Ra <- rnorm(100)
+#' cl <- seq(.90, .99, .01)
+#' HSVaRPlot2DCl(Ra, cl)
+#'
+#' @export
+HSVaRPlot2DCl <- function(Ra, cl){
+
+ # Determine if there are three 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
+ cl <- as.matrix(cl)
+ cl.rows <- dim(cl)[1]
+ cl.columns <- dim(cl)[2]
+ if (min(cl.rows, cl.columns) > 1) {
+ stop("Confidence level must be a vector.")
+ }
+ cl <- as.vector(cl)
+
+ # Check that inputs obey sign and value restrictions
+ if (max(cl) >= 1) {
+ stop("Confidence level must be less than 1.")
+ }
+ if (min(cl) <= 0) {
+ stop("Confidence level must positive.")
+ }
+
+ # VaR estimation
+ VaR <- double(length(cl))
+ for (k in 1:length(cl)) {
+ VaR[k] <- HSVaR(profit.loss, cl[k])
+ }
+
+ # Plot
+ plot(cl, VaR, type = "l", col = 3, xlab = "Confidence Level", ylab = "VaR", main = "Historical VaR against confidence level")
+ par(new = TRUE)
+}
\ No newline at end of file
Added: pkg/Dowd/man/HSVaRPlot2DCl.Rd
===================================================================
--- pkg/Dowd/man/HSVaRPlot2DCl.Rd (rev 0)
+++ pkg/Dowd/man/HSVaRPlot2DCl.Rd 2015-06-26 18:49:04 UTC (rev 3751)
@@ -0,0 +1,31 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/HSVaRPlot2DCl.R
+\name{HSVaRPlot2DCl}
+\alias{HSVaRPlot2DCl}
+\title{Plots historical simulation VaR against confidence level}
+\usage{
+HSVaRPlot2DCl(Ra, cl)
+}
+\arguments{
+\item{Ra}{Vector of daily P/L data}
+
+\item{cl}{Vector of VaR confidence levels}
+}
+\description{
+Function plots the historical simulation VaR of a
+portfolio against confidence level, for specified range of confidence level
+and holding period implied by data frequency.
+}
+\examples{
+# Plots historical simulation VaR against confidence level
+ Ra <- rnorm(100)
+ cl <- seq(.90, .99, .01)
+ HSVaRPlot2DCl(Ra, cl)
+}
+\author{
+Dinesh Acharya
+}
+\references{
+Dowd, K. Measuring Market Risk, Wiley, 2007.
+}
+
More information about the Returnanalytics-commits
mailing list