aboutsummaryrefslogtreecommitdiffstats
path: root/lossdistrib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lossdistrib.c')
-rw-r--r--lossdistrib.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/lossdistrib.c b/lossdistrib.c
index e6eef029..d9af0f89 100644
--- a/lossdistrib.c
+++ b/lossdistrib.c
@@ -53,7 +53,7 @@ void lossdistrib(double *p, int *np, double *w, double *S, int *N, double *q) {
free(q2);
}
-void lossdistrib_fast(double *p, int *np, double *w, double *S, int *N, int *T, double *q) {
+void lossdistrib_truncated(double *p, int *np, double *w, double *S, int *N, int *T, double *q) {
/* recursive algorithm with first order correction for computing
the loss distribution.
p vector of default probabilities
@@ -278,7 +278,8 @@ void addandmultiply(double *X, double alpha, double *Y, int n) {
}
}
-void BClossdist(double *SurvProb, int *dim1, int *dim2, double *issuerweights, double *recov, double *Z, double *w, int *n, double *rho, int *N, double *L, double *R) {
+void BClossdist(double *SurvProb, int *dim1, int *dim2, double *issuerweights,
+ double *recov, double *Z, double *w, int *n, double *rho, int *N, int *T, double *L, double *R) {
/*
computes the loss and recovery distribution over time with a flat gaussiancorrelation
inputs:
@@ -289,9 +290,10 @@ void BClossdist(double *SurvProb, int *dim1, int *dim2, double *issuerweights, d
w: vector of factor weights (length n)
rho: correlation beta
N: number of ticks in the grid
+ T: number of probabilities to compute
outputs:
- L: matrix of size (1/lu+1, dim2)
- R: matrix of size (1/lu+1, dim2)
+ L: matrix of size (T, dim2)
+ R: matrix of size (T, dim2)
*/
int t, i, j;
double g;
@@ -300,8 +302,8 @@ void BClossdist(double *SurvProb, int *dim1, int *dim2, double *issuerweights, d
gshocked = calloc((*dim1), sizeof(double));
Rshocked = calloc((*dim1), sizeof(double));
Sshocked = calloc((*dim1), sizeof(double));
- Lw = malloc((*N) * sizeof(double));
- Rw = malloc((*N) * sizeof(double));
+ Lw = malloc((*T) * sizeof(double));
+ Rw = malloc((*T) * sizeof(double));
for(t=0; t < (*dim2); t++) {
for(i=0; i < *n; i++){
@@ -312,14 +314,14 @@ void BClossdist(double *SurvProb, int *dim1, int *dim2, double *issuerweights, d
Rshocked[j] = 1 - Sshocked[j];
}
/* reset Lw and Rw to 0 */
- for(j=0; j<*N; j++){
+ for(j=0; j<*T; j++){
Lw[j]=0;
Rw[j]=0;
}
- lossdistrib(gshocked, dim1, issuerweights, Sshocked, N, Lw);
- lossdistrib(gshocked, dim1, issuerweights, Rshocked, N, Rw);
- addandmultiply(Lw, w[i], L + t * (*N), *N);
- addandmultiply(Rw, w[i], R + t * (*N), *N);
+ lossdistrib_truncated(gshocked, dim1, issuerweights, Sshocked, N, T, Lw);
+ lossdistrib_truncated(gshocked, dim1, issuerweights, Rshocked, N, T, Rw);
+ addandmultiply(Lw, w[i], L + t * (*T), *T);
+ addandmultiply(Rw, w[i], R + t * (*T), *T);
}
}
free(gshocked);