[Returnanalytics-commits] r3837 - in pkg/Dowd: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Jul 21 23:04:57 CEST 2015
Author: dacharya
Date: 2015-07-21 23:04:57 +0200 (Tue, 21 Jul 2015)
New Revision: 3837
Added:
pkg/Dowd/R/NormalESConfidenceInterval.R
pkg/Dowd/man/NormalESConfidenceInterval.Rd
Log:
Function NormalESConfidenceInterval added.
Added: pkg/Dowd/R/NormalESConfidenceInterval.R
===================================================================
--- pkg/Dowd/R/NormalESConfidenceInterval.R (rev 0)
+++ pkg/Dowd/R/NormalESConfidenceInterval.R 2015-07-21 21:04:57 UTC (rev 3837)
@@ -0,0 +1,37 @@
+#' Generates Monte Carlo 95\% Confidence Intervals for normal ES
+#'
+#' Generates 95\% confidence intervals for normal ES 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 ES
+#'
+#' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
+#'
+#' @author Dinesh Acharya
+#'
+#' @examples
+#'
+#' # Generates 95\% confidence intervals for normal ES for given parameters
+#' NormalESConfidenceInterval(0, .5, 20, 20, .95, 90)
+#'
+#'
+#' @export
+NormalESConfidenceInterval <- function(mu, sigma, number.trials, sample.size, cl, hp){
+ ES <- double(number.trials)
+ for (k in 1:number.trials) {
+ z <- rnorm(sample.size)
+ x <- sigma * z + mu
+ ES[k] <- NormalES(returns = x, cl = cl, hp = hp)
+ }
+ ES <- sort(ES)
+ lower.order.stat <- floor(0.025 * number.trials)
+ upper.order.stat <- ceiling(0.975 * number.trials)
+ y <- c(ES[lower.order.stat], ES[upper.order.stat])
+ return(y)
+}
Added: pkg/Dowd/man/NormalESConfidenceInterval.Rd
===================================================================
--- pkg/Dowd/man/NormalESConfidenceInterval.Rd (rev 0)
+++ pkg/Dowd/man/NormalESConfidenceInterval.Rd 2015-07-21 21:04:57 UTC (rev 3837)
@@ -0,0 +1,38 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/NormalESConfidenceInterval.R
+\name{NormalESConfidenceInterval}
+\alias{NormalESConfidenceInterval}
+\title{Generates Monte Carlo 95\% Confidence Intervals for normal ES}
+\usage{
+NormalESConfidenceInterval(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 ES
+}
+\description{
+Generates 95\% confidence intervals for normal ES using Monte Carlo simulation
+}
+\examples{
+# Generates 95\\\% confidence intervals for normal ES for given parameters
+ NormalESConfidenceInterval(0, .5, 20, 20, .95, 90)
+}
+\author{
+Dinesh Acharya
+}
+\references{
+Dowd, K. Measuring Market Risk, Wiley, 2007.
+}
+
More information about the Returnanalytics-commits
mailing list