From 74fa05ce92c4d23d14cc6672ffefe3379a804bcd Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Tue, 10 Mar 2015 18:25:03 -0400 Subject: add an function for computing truncated expected loss --- R/distrib.R | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'R') diff --git a/R/distrib.R b/R/distrib.R index 277b324..b2c028a 100644 --- a/R/distrib.R +++ b/R/distrib.R @@ -302,6 +302,24 @@ lossdistC.truncated <- function(p, w, S, N, T=N, defaultflag=FALSE){ q = double(N))$q } +exp.trunc <- function(p, w, S, N, K){ + ## computes E[(K-L)^+] + r <- 0 + .C("exp_trunc", as.double(p), as.integer(length(p)), + as.double(w), as.double(S), as.integer(N), as.double(K), res = r)$res +} + +rec.trunc <- function(p, w, S, N, K){ + ## computes E[(K-(1-R))^+] = E[(\tilde K- \bar R)] + ## where \tilde K = K-sum_i w_i S_i and \bar R=\sum_i w_i R_i (1-X_i) + Ktilde <- K-crossprod(w, S) + if(Ktilde < 0){ + return( 0 ) + }else{ + return( exp.trunc(1-p, w, 1-S, N, Ktilde) ) + } +} + recovdistC <- function(dp, pp, w, S, N){ ## C version of recovdist .C("recovdist", as.double(dp), as.double(pp), as.integer(length(dp)), -- cgit v1.2.3-70-g09d2