From 3cab7807e4d31a1cda940b9b3e160a1a7cf10a09 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Thu, 30 Jul 2015 15:16:39 -0400 Subject: improve docs --- R/distrib.R | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'R/distrib.R') diff --git a/R/distrib.R b/R/distrib.R index 536ed20..d941bd2 100644 --- a/R/distrib.R +++ b/R/distrib.R @@ -16,7 +16,7 @@ #' Gaussian distribution. #' #' if f is a function, then with(GHquad(100), crossprod(f(Z), w)) -#' +#' will compute \eqn{\frac{1}{\sqrt{2\pi}}\int_-\infty^\infty f(x)e^{-\frac{x^2}{2}}\,dx}. #' @param n Integer, the number of nodes #' @return A list with two components: #' \item{Z}{the list of nodes} @@ -106,20 +106,19 @@ lossdistrib2 <- function(p, w, S, N, defaultflag=FALSE){ return(q) } +#' recursive algorithm with first order correction truncated version +#' this is actually slower than lossdistrib2. But in C this is +#' twice as fast. +#' For high severities, M can become bigger than N, and there is +#' some probability mass escaping. +#' +#' @param p Numeric, vector of default probabilities +#' @param w Numeric, vector of weights +#' @param S Numeric, vector of severities +#' @param N Integer, number of ticks in the grid +#' @param cutoff Integer, where to stop computing the exact probabilities +#' @return a Numeric vector of size \code{N} computing the loss distribution lossdistrib2.truncated <- function(p, w, S, N, cutoff=N){ - ## recursive algorithm with first order correction - ## p vector of default probabilities - ## w vector of weigths - ## S vector of severities - ## N number of ticks in the grid (for best accuracy should - ## be a multiple of the number of issuers) - ## cutoff where to stop computing the exact probabilities - ## (useful for tranche computations) - - ## this is actually slower than lossdistrib2. But in C this is - ## twice as fast. - ## for high severities, M can become bigger than N, and there is - ## some probability mass escaping. n <- length(p) lu <- 1/(N-1) q <- rep(0, cutoff) @@ -174,19 +173,20 @@ recovdist <- function(dp, pp, w, S, N){ return(q) } +#' recursive algorithm with first order correction to compute the joint +#' probability distribution of the loss and recovery. +#' For high severities, M can become bigger than N, and there is +#' some probability mass escaping. +#' +#' @param p Numeric, vector of default probabilities +#' @param w Numeric, vector of weights +#' @param S Numeric, vector of severities +#' @param N Integer, number of ticks in the grid +#' @param cutoff Integer, where to stop computing the exact probabilities +#' @return q Matrix of joint loss, recovery probability distribution +#' colSums(q) is the recovery distribution marginal +#' rowSums(q) is the loss distribution marginal lossdist.joint <- function(p, w, S, N, defaultflag=FALSE){ - ## recursive algorithm with first order correction - ## to compute the joint probability distribution of the loss and recovery - ## inputs: - ## p: vector of default probabilities - ## w: vector of issuer weights - ## S: vector of severities - ## N: number of tick sizes on the grid - ## defaultflag: if true computes the default distribution - ## output: - ## q: matrix of joint loss, recovery probability - ## colSums(q) is the recovery distribution marginal - ## rowSums(q) is the loss distribution marginal n <- length(p) lu <- 1/(N-1) q <- matrix(0, N, N) -- cgit v1.2.3-70-g09d2