#include #include #define MIN(x, y) (((x) < (y)) ? (x) : (y)) void lossdistrib(double *p, int *np, double *w, double *S, int *N, double *q) { /* recursive algorithm with first order correction for computing the loss distribution. p vector of default probabilities np length of p S vector of severities (should be same length as p) N number of ticks in the grid q the loss distribution */ int i, j, d1, d2; double lu, d, p1, p2, sum; double *q1, *q2; lu = 1./(*N-1); q1 = malloc( *N * sizeof(double)); q2 = malloc( *N * sizeof(double)); q[0] = 1; for(i=0; i<(*np); i++){ d = S[i] * w[i]/ lu; d1 = floor(d); d2 = ceil(d); p1 = p[i] * (d2-d); p2 = p[i] - p1; for(j=0; j