[Returnanalytics-commits] r3848 - in pkg/Dowd: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jul 22 23:32:02 CEST 2015
Author: dacharya
Date: 2015-07-22 23:32:02 +0200 (Wed, 22 Jul 2015)
New Revision: 3848
Added:
pkg/Dowd/R/NormalVaRConfidenceInterval.R
pkg/Dowd/man/NormalVaRConfidenceInterval.Rd
Log:
Function NormalVaRConfidenceInterval added.
Added: pkg/Dowd/R/NormalVaRConfidenceInterval.R
===================================================================
--- pkg/Dowd/R/NormalVaRConfidenceInterval.R (rev 0)
+++ pkg/Dowd/R/NormalVaRConfidenceInterval.R 2015-07-22 21:32:02 UTC (rev 3848)
@@ -0,0 +1,35 @@
+#' Generates Monte Carlo 95\% Confidence Intervals for normal VaR
+#'
+#' Generates 95\% confidence intervals for normal VaR using Monte Carlo simulation
+#'
+#' @param mu Mean of the P/L process
+#' @param sigma Standard deviation of the P/L process
+#' @param number.trials Number of trials used in the simulations
+#' @param sample.size Sample drawn in each trial
+#' @param cl Confidence Level
+#' @param hp Holding Period
+#'
+#' @return 95\% confidence intervals for normal VaR
+#' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
+#'
+#' @author Dinesh Acharya
+#' @examples
+#'
+#' # Generates 95\% confidence intervals for normal VaR for given parameters
+#' NormalVaRConfidenceInterval(0, .5, 20, 15, .95, 90)
+#'
+#'
+#' @export
+NormalVaRConfidenceInterval <- function(mu, sigma, number.trials, sample.size, cl, hp){
+ VaR <- double(number.trials)
+ for (k in 1:number.trials) {
+ z <- rnorm(sample.size)
+ x <- sigma * z + mu
+ VaR[k] <- NormalVaR(returns = x, cl = cl, hp = hp)
+ }
+ VaR <- sort(VaR)
+ lower.order.stat <- floor(0.025 * number.trials)
+ upper.order.stat <- ceiling(0.975 * number.trials)
+ y <- c(VaR[lower.order.stat], VaR[upper.order.stat])
+ return(y)
+}
Added: pkg/Dowd/man/NormalVaRConfidenceInterval.Rd
===================================================================
--- pkg/Dowd/man/NormalVaRConfidenceInterval.Rd (rev 0)
+++ pkg/Dowd/man/NormalVaRConfidenceInterval.Rd 2015-07-22 21:32:02 UTC (rev 3848)
@@ -0,0 +1,38 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/NormalVaRConfidenceInterval.R
+\name{NormalVaRConfidenceInterval}
+\alias{NormalVaRConfidenceInterval}
+\title{Generates Monte Carlo 95\% Confidence Intervals for normal VaR}
+\usage{
+NormalVaRConfidenceInterval(mu, sigma, number.trials, sample.size, cl, hp)
+}
+\arguments{
+\item{mu}{Mean of the P/L process}
+
+\item{sigma}{Standard deviation of the P/L process}
+
+\item{number.trials}{Number of trials used in the simulations}
+
+\item{sample.size}{Sample drawn in each trial}
+
+\item{cl}{Confidence Level}
+
+\item{hp}{Holding Period}
+}
+\value{
+95\% confidence intervals for normal VaR
+}
+\description{
+Generates 95\% confidence intervals for normal VaR using Monte Carlo simulation
+}
+\examples{
+# Generates 95\\\% confidence intervals for normal VaR for given parameters
+ NormalVaRConfidenceInterval(0, .5, 20, 15, .95, 90)
+}
+\author{
+Dinesh Acharya
+}
+\references{
+Dowd, K. Measuring Market Risk, Wiley, 2007.
+}
+
More information about the Returnanalytics-commits
mailing list