c++ boost overhead for cdf and pdf

442 views Asked by At

My question is how does one reduce the overhead when using boost::math::pdf and boost::math::cdf? It seems that every time I need to calculate a pdf or cdf, boost goes through several statements before the cdf/pdf is calculated. One can see this by stepping through a call to either pdf or cdf. (i.e. boost::math::cdf(s,x);) This seems to be very inefficient when one needs to access theses functions in a simulation (500,000+=5000 draws*100 loans). Thanks in advance

The relevant portions of the code are: main execution part:

for (int i = 0;i < NumSim;i++) {
    for (int j = 0;j < NumLoans;j++) {
        double Sum = 0;
        for (int T = 0;T < NumLoans;T++) {
                Sum = Sum + RndNumbers[i][T] * CholeskyMatrix[j][T];
        }
        CorrelatedRndNumbers[i][j] = Stats.NormCDF(Sum);
    }
}

.h file

class clStats
{
public:
    clStats(void);
    ~clStats(void);

    double  NormCDF(double x);
    double  NormPDF(double x);

private:
    boost::math::normal s;

}; 

.cpp file

clStats::clStats(void)
{
}


clStats::~clStats(void)
{
}
double  clStats::NormCDF(double x) {
      return boost::math::cdf(s,x);
}
double clStats::NormPDF(double x) {
    return boost::math::pdf(s,x);
}
0

There are 0 answers