#include #include #include /* Algorithms exposed in the paper 'Simulation of High-Dimensional t-Student Copula with a Given Block Correlation Matrix' by Gerard torrent-Gironella and Josep Fortiana */ /* gcc -Wall -O3 -DNDEBUG -o cholesky cholesky.c -lm */ /* number of blocks (or sectors) */ #define K 3 /* original matrix dimension (or number of obligors) */ #define N 6 /* Cholesky algorithm for block matrix k = number of groups n = elements per block, size k d= diagonal per block, size k M = block values, size kxk H = cholesky values (diagonal not included), size kx(n[0]+...+n[k-1]) v = cholesky values (only diagonal), size n[0]+...+n[k-1]) if matrix is not definite positive, returns 1, else returns 0 */ int chold(int k, int *n, double *d, double **M, double **H, double *v) { int i, j, r, s, q; double val1=0.0, val2=0.0; assert(k>0 && n!=NULL && d!=NULL && M!=NULL && H!=NULL && v!=NULL); for(r=0; r 0) { y[i] += sum*J[i][r]; } sum += x[i]; } for(j=i+1; j 0) { printf("matrix not definite positive\n"); return 1; } printf("H = \n"); printMatrix(H, 3, 6); printf("v = \n"); printVector(v, 6); inv(3, n, H, v, J, w); printf("J = \n"); printMatrix(J, 6, 3); printf("w = \n"); printVector(w, 6); for(i=0;i