I try to explain how ccruncher works and how navigate in the C++ code:
the code is under $CCRUNCHER/src/ directory
each class have a cpp file and a hpp file
most of classes have a companion test class (*Test.?pp)
each section in xml input has a directory with related classes
most of classes haven't interest. Are pure containers.
functional key classes are:
src/math/CholeskyDecomposition [Cholesky decomposition of a mtrix following 'Numerical Recipes in C']
share/Mersenne-1.0/MersenneTwisterTest [random number generator]
src/math/Normal [implements cdf computation for normal distribution]
src/math/CopulaNormal [correlated random number generator. see algorithm described in
'Properties of the Norta method in higher dimensions' from Soumyadip Ghosh and Shane G. Henderson.
You can found the pdf searching it on Google]
src/math/PowMatrix [computes the pow of a matrix]
src/kernel/IData [input xml file manager, main data container]
src/kernel/MonteCarlo [MonteCarlo algorithm]
src/aggregators/SegmentAggregator [computes the value of each simulation]
C1 | 1 C A C A
C2 | C 1 C B C
C3 | A C 1 C A
C4 | C B C 1 C
C5 | A C A C 1
creating a copula for each time tranch. These copulas will be used to
generate correlated random numbers:
simulation_1 => (X1_1, X2_1, X3_1, X4_1, X5_1)
simulation_2 => (X1_2, X2_2, X3_2, X4_2, X5_2)
...
simulation_k => (X1_k, X2_k, X3_k, X4_k, X5_k)
...
satisfying the correlation client matrix
correlation(X1, X1)=1
correlation(X1, X2)=C
correlation(X1, X3)=A
etc.
Xi_k is a uniform random number between 0 and 1 correlated with Xj_k from correlation client matrix
initializing aggregators
Run MonteCarlo (explained 1 simulation)
for each time tranch we realize the time-tranch copula. Supose that we have
4 time tranches:
each Xi_j is a number between 0 and 1. The copula1 (copula from time tranch 1) generate
X1_, copula2 (copula from time tranch 2) generate X2_, copula3 (copula from time
tranch 3) generate X3_*, etc.
We translate Xi_j to rating using scaled transition matrix. Supose that defined ratings are
AAA, AA and default, and scaled transition matrix (probability to jump from rating X to
rating Y in K time) is:
AAA AA default
---------------------
AAA | 0.8 0.1 0.1
AA | 0.1 0.8 0.1
default | 0.0 0.0 1.0
Supose that C1 rating at T0 is a AA (departure ratings are fixed, see tag client) and X1_1 is 0.29.
We take the transition matrix line
AAA AA default
---------------------
AA | 0.1 0.8 0.1
and we make the asignation: [0.0 - 0.1] -> AAA [0.1 - 0.9] -> AA [0.9 - 1.0] -> default
in our case, 0.29 belongs [0.1 - 0.9], then the T1 rating is AA.
For simulate the rating in T2 we make the same from T1 simulated rating (AA).
For simulate the rating in T3 we make the same from T2 simulated rating, and so on.
Please, reports any sugestion, doubt or mistake.
Sorry for my limited english.
> Hello!
> I sent you a short message on
> gerard@fobos.generacio.com . May be you could tell me at
> list what docs (in English) I can use to help myself to analyse
> the program's code?
> BR,
> Yuri
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Yuri,
At his moment, the documentation is under development (in spanish).
You can take a look from repository:
http://www.generacio.com/svn/repos/ccruncher/trunk/doc/ccruncher.pdf
I try to explain how ccruncher works and how navigate in the C++ code:
'Properties of the Norta method in higher dimensions' from Soumyadip Ghosh and Shane G. Henderson.
You can found the pdf searching it on Google]
The steps that ccruncher performs are:
from class PowMatrix. See point 2.3.4 in pdf doc.
create a correlation matrix for clients. Supose that we have 5 clients (C1, C2, C3, C4, C5) and
2 sectors (S1 and S2).
The sectorial correlation matrix is
S1 | A C C=correlation between a S1 client and a S2 client
S2 | C B
We supose that,
C1 belongs S1,
C2 belongs S2,
C3 belongs S1,
C4 belongs S2
C5 belongs S1
Then, the client correlation is:
C1 | 1 C A C A
C2 | C 1 C B C
C3 | A C 1 C A
C4 | C B C 1 C
C5 | A C A C 1
creating a copula for each time tranch. These copulas will be used to
generate correlated random numbers:
simulation_1 => (X1_1, X2_1, X3_1, X4_1, X5_1)
simulation_2 => (X1_2, X2_2, X3_2, X4_2, X5_2)
...
simulation_k => (X1_k, X2_k, X3_k, X4_k, X5_k)
...
satisfying the correlation client matrix
correlation(X1, X1)=1
correlation(X1, X2)=C
correlation(X1, X3)=A
etc.
Xi_k is a uniform random number between 0 and 1 correlated with Xj_k from correlation client matrix
initializing aggregators
Run MonteCarlo (explained 1 simulation)
for each time tranch we realize the time-tranch copula. Supose that we have
4 time tranches:
C1 | X1_1 X1_2 X1_3 X1_4
C2 | X2_1 X2_2 X2_3 X2_4
C3 | X3_1 X3_2 X3_3 X3_4
C4 | X4_1 X4_2 X4_3 X4_4
C5 | X5_1 X5_2 X5_3 X5_4
each Xi_j is a number between 0 and 1. The copula1 (copula from time tranch 1) generate
X1_, copula2 (copula from time tranch 2) generate X2_, copula3 (copula from time
tranch 3) generate X3_*, etc.
We translate Xi_j to rating using scaled transition matrix. Supose that defined ratings are
AAA, AA and default, and scaled transition matrix (probability to jump from rating X to
rating Y in K time) is:
default | 0.0 0.0 1.0
Supose that C1 rating at T0 is a AA (departure ratings are fixed, see tag client) and X1_1 is 0.29.
We take the transition matrix line
and we make the asignation:
[0.0 - 0.1] -> AAA
[0.1 - 0.9] -> AA
[0.9 - 1.0] -> default
in our case, 0.29 belongs [0.1 - 0.9], then the T1 rating is AA.
For simulate the rating in T2 we make the same from T1 simulated rating (AA).
For simulate the rating in T3 we make the same from T2 simulated rating, and so on.
The same for C2, C3, C4 and C5.
Finally, we have
C1 | R1_1 R1_2 R1_3 R1_4
C2 | R2_1 R2_2 R2_3 R2_4
C3 | R3_1 R3_2 R3_3 R3_4
C4 | R4_1 R4_2 R4_3 R4_4
C5 | R5_1 R5_2 R5_3 R5_4
where Ri_k is the simulated rating for client i at time k. Now we can
evaluate the portfolio at time 1, 2, 3 and 4.
Input file is described in:
http://www.generacio.com/ccruncher/tagreference.html
Examples of input files can be found in $CCRUNCHER/samples/ directory
or in the repository:
http://www.generacio.com/svn/repos/ccruncher/trunk/samples/sample50.xml
Please, reports any sugestion, doubt or mistake.
Sorry for my limited english.
> Hello!
> I sent you a short message on
> gerard@fobos.generacio.com . May be you could tell me at
> list what docs (in English) I can use to help myself to analyse
> the program's code?
> BR,
> Yuri