summaryrefslogtreecommitdiffstats
path: root/R/distrib.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/distrib.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)),