[Returnanalytics-commits] r3733 - in pkg/Dowd: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jun 23 23:56:55 CEST 2015


Author: dacharya
Date: 2015-06-23 23:56:55 +0200 (Tue, 23 Jun 2015)
New Revision: 3733

Added:
   pkg/Dowd/R/InsuranceVaR.R
   pkg/Dowd/man/InsuranceVaR.Rd
Modified:
   pkg/Dowd/NAMESPACE
Log:
InsuranceVaR: source and documentation added.

Modified: pkg/Dowd/NAMESPACE
===================================================================
--- pkg/Dowd/NAMESPACE	2015-06-23 21:35:25 UTC (rev 3732)
+++ pkg/Dowd/NAMESPACE	2015-06-23 21:56:55 UTC (rev 3733)
@@ -41,6 +41,7 @@
 export(HillEstimator)
 export(HillPlot)
 export(HillQuantileEstimator)
+export(InsuranceVaR)
 export(JarqueBeraBacktest)
 export(KSTestStat)
 export(KuiperTestStat)

Added: pkg/Dowd/R/InsuranceVaR.R
===================================================================
--- pkg/Dowd/R/InsuranceVaR.R	                        (rev 0)
+++ pkg/Dowd/R/InsuranceVaR.R	2015-06-23 21:56:55 UTC (rev 3733)
@@ -0,0 +1,53 @@
+#' VaR of Insurance Portfolio
+#'
+#' Generates Monte Carlo VaR for insurance portfolio in Chapter 6.5
+#'
+#' @param mu Mean of returns
+#' @param sigma Volatility of returns
+#' @param n Number of contracts
+#' @param p Probability of any loss event
+#' @param theta Expected profit per contract
+#' @param deductible Deductible
+#' @param number.trials Number of simulation trials
+#' @param cl VaR confidence level
+#' @return VaR of the specified portfolio
+#' 
+#' @references Dowd, K. Measuring Market Risk, Wiley, 2007.
+#' 
+#' 
+#' @author Dinesh Acharya
+#' @examples
+#' 
+#'    # Estimates VaR of Insurance portfolio with given parameters
+#'    InsuranceVaR(.8, 1.3, 100, .6, 21,  12, 50, .95)
+#'
+#' @export
+InsuranceVaR<- function(mu, sigma, n, p, theta, deductible, number.trials, cl){
+  M <- number.trials
+  D <- deductible
+  L <- matrix(0, n, M)
+  company.loss <- L
+  total.company.loss <- double(M)
+  for (j in 1:M) {
+    L[1, j] <- rbinom( 1, 1, p) * rlnorm(1, mu, sigma) # Realisation of L
+    company.loss[1, j] <- max(L[1,j] - D, 0) # Adjust for deductible
+    
+    for (i in 2:n) {
+      L[i, j] <- rbinom(1, 1, p) * rlnorm(1, mu, sigma) # Realisation of L
+      company.loss[i, j] <- max(L[i,j] - D, 0) + company.loss[i - 1, j] # Adjust
+                                                                # for deductible
+    }
+    total.company.loss[j] <- company.loss[n,j] # Total company loss for 
+                                                # given j trial
+  }
+  # Sample of total company losses
+  adjusted.total.company.loss <- total.company.loss - mean(total.company.loss) -
+    theta * mean(total.company.loss) / n # Adjusts for premium
+  profit.or.loss <- - adjusted.total.company.loss # Convert to P/L
+  hist(adjusted.total.company.loss, col = "blue", 
+       xlab = "Total Company Loss", yab = "Frequency",
+       main = "Adjusted Total Company Loss")
+  y <- HSVaR(profit.or.loss, cl)
+  return(y)
+  
+}
\ No newline at end of file

Added: pkg/Dowd/man/InsuranceVaR.Rd
===================================================================
--- pkg/Dowd/man/InsuranceVaR.Rd	                        (rev 0)
+++ pkg/Dowd/man/InsuranceVaR.Rd	2015-06-23 21:56:55 UTC (rev 3733)
@@ -0,0 +1,42 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/InsuranceVaR.R
+\name{InsuranceVaR}
+\alias{InsuranceVaR}
+\title{VaR of Insurance Portfolio}
+\usage{
+InsuranceVaR(mu, sigma, n, p, theta, deductible, number.trials, cl)
+}
+\arguments{
+\item{mu}{Mean of returns}
+
+\item{sigma}{Volatility of returns}
+
+\item{n}{Number of contracts}
+
+\item{p}{Probability of any loss event}
+
+\item{theta}{Expected profit per contract}
+
+\item{deductible}{Deductible}
+
+\item{number.trials}{Number of simulation trials}
+
+\item{cl}{VaR confidence level}
+}
+\value{
+VaR of the specified portfolio
+}
+\description{
+Generates Monte Carlo VaR for insurance portfolio in Chapter 6.5
+}
+\examples{
+# Estimates VaR of Insurance portfolio with given parameters
+   InsuranceVaR(.8, 1.3, 100, .6, 21,  12, 50, .95)
+}
+\author{
+Dinesh Acharya
+}
+\references{
+Dowd, K. Measuring Market Risk, Wiley, 2007.
+}
+



More information about the Returnanalytics-commits mailing list