Login  Register

G2++ process

Posted by André de Boer on Nov 20, 2015; 9:09am
URL: http://quantlib.414.s1.nabble.com/G2-process-tp17103.html

Hello All,

I'm trying to perform a monte carlo simulation with the G2++ model.
Below the code I have so far.
But this results in a much to big difference between the theoretical
and the average of the simulations.

The problem I think lies in the loop:

for (Size path = 0; path < numPaths; ++path){
for (Size step = 0; step < numSteps; ++step) {
ir  = g2Process->evolve(grid[step], ir, grid.dt(step), dz);
zcbBond = g2Model->discountBond(0, grid[step], ir);
ZCB[path][step] = zcbBond;
sample = generator.nextSequence().value ;
dz[0]=sample[0]; dz[1]=sample[1];
}
}

Is there a better way to do this? Is there a way to improve the
performance here?

Kind regards,
André



void g2pp(){

const Date &referenceDate = Date::todaysDate();
Handle<Quote> forward(boost::shared_ptr<Quote>(new SimpleQuote(0.05)));
ActualActual dayCounter;
boost::shared_ptr<YieldTermStructure> yield(new
FlatForward(referenceDate, forward, dayCounter));

Real a, sigma, b, eta, rho;
a = .1;  sigma = .01; b = .1; eta   = .01; rho = -.7;

boost::shared_ptr<G2> g2Model(new
G2(Handle<YieldTermStructure>(yield), a, sigma, b, eta, rho));
boost::shared_ptr<StochasticProcess> g2Process(new G2Process(a, sigma,
b, eta, rho));
Size numPaths = 15, numSteps=180;
TimeGrid grid((Time)15, numSteps);

Matrix ZCB(numPaths, numSteps);
SobolRsg sobol(2, 42);
InverseCumulativeRsg<SobolRsg, InverseCumulativeNormal> generator(sobol);

Array ir(2), dz(2);
ir[0] = ir[1] = 0.0;
dz[0] = dz[1] = 0.0;

Real zcbBond, fwRate;
std::vector<Real> sample(2);

for (Size path = 0; path < numPaths; ++path){
for (Size step = 0; step < numSteps; ++step) {
ir  = g2Process->evolve(grid[step], ir, grid.dt(step), dz);
zcbBond = g2Model->discountBond(0, grid[step], ir);
ZCB[path][step] = zcbBond;
sample = generator.nextSequence().value ;
dz[0]=sample[0]; dz[1]=sample[1];
}
}

ofstream G2_ZCB;
G2_ZCB.open ("C:\\Temp\\G2_ZCB.csv");

for (QuantLib::Size path = 0; path < numPaths; ++path) {
for (QuantLib::Size step = 0; step < numSteps; ++step) {
G2_ZCB << ZCB[path][step] << ",";
}
G2_ZCB << "\n";
}
G2_ZCB.close();
}

------------------------------------------------------------------------------
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users