summaryrefslogtreecommitdiffstats
path: root/src/lossdistrib.c
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 /src/lossdistrib.c
parent544eb106db66e859a0933244bf46624eab1ab555 (diff)
downloadlossdistrib-74fa05ce92c4d23d14cc6672ffefe3379a804bcd.tar.gz
add an function for computing truncated expected loss
Diffstat (limited to 'src/lossdistrib.c')
-rw-r--r--src/lossdistrib.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/lossdistrib.c b/src/lossdistrib.c
index d28b1b2..51e273b 100644
--- a/src/lossdistrib.c
+++ b/src/lossdistrib.c
@@ -200,6 +200,23 @@ void lossdistrib_truncated(double *p, int *np, double *w, double *S, int *N,
free(qtemp);
}
+void exp_trunc(double *p, int *np, double *w, double *S, int *N, double *K,
+ double *r) {
+ double lu;
+ double *qtemp;
+ double lambda;
+ lu = 1./(*N+1);
+ int T = (int) floor((*K) * (*N))+1;
+ int zero = 0;
+ qtemp = calloc( T, sizeof(double));
+ int i;
+ lossdistrib_truncated(p, np, w, S, N, &T, &zero, qtemp);
+ for(i = 0; i < T; i++){
+ *r += (*K - lu*i) * qtemp[i];
+ }
+ free(qtemp);
+}
+
void lossdistrib_joint(double *p, int *np, double *w, double *S, int *N, int *defaultflag, double *q) {
/* recursive algorithm with first order correction
computes jointly the loss and recovery distribution
@@ -711,7 +728,7 @@ void lossdistrib_joint_Z(double *dp, int *ndp, double *w,
double beta = 0;
int one = 1;
-#pragma omp parallel for private(j)
+ #pragma omp parallel for private(j)
for(i = 0; i < *nZ; i++){
for(j = 0; j < *ndp; j++){
dpshocked[j + (*ndp) * i] = shockprob(dp[j], rho[j], Z[i], 0);