summaryrefslogtreecommitdiffstats
path: root/R
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@serenitascapital.com>2015-03-10 18:25:03 -0400
committerGuillaume Horel <guillaume.horel@serenitascapital.com>2015-03-10 18:25:03 -0400
commit74fa05ce92c4d23d14cc6672ffefe3379a804bcd (patch)
tree5da699084471de26f84a1736ea6862c00b69fb6e /R
parent544eb106db66e859a0933244bf46624eab1ab555 (diff)
downloadlossdistrib-74fa05ce92c4d23d14cc6672ffefe3379a804bcd.tar.gz
add an function for computing truncated expected loss
Diffstat (limited to 'R')
-rw-r--r--R/distrib.R18
1 files changed, 18 insertions, 0 deletions
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)),