Problem calibrating short rate model

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem calibrating short rate model

Der Spezialist
I try to calibrate some short rate models using Cap market quotes. The relevant code is the following:

    shared_ptr<BlackKarasinski> modelBK(new BlackKarasinski(hYTS));
    shared_ptr<CoxIngersollRoss> modelCIR(new CoxIngersollRoss());
  
    // - Calibrate models
   
    // Black Karasinski
    for(vecCapHelper::iterator it = capHelpers.begin(); it != capHelpers.end(); it++)
    {
        (*it)->setPricingEngine(shared_ptr<PricingEngine>(
            new TreeCapFloorEngine(modelBK, timesteps)
        ));
    }
    cout << "Calibrating Black--Karasinski...";
    calibrateModel(modelBK, capHelpers);
    cout << "done." << endl;

    // CoxIngersollRoss
    for(vecCapHelper::iterator it = capHelpers.begin(); it != capHelpers.end(); it++)
    {
        (*it)->setPricingEngine(shared_ptr<PricingEngine>(
            new TreeCapFloorEngine(modelCIR, timesteps, hYTS)
        ));
    }
    cout << "Calibrating Cox--Ingersoll--Ross...";
    calibrateModel(modelCIR, capHelpers);
    cout << "done." << endl;


Here the function calibrateModel() is the same as in the QuantLib example BermudanSwaption.cpp. capHelpers is a std::vector with CapHelpers, and hYTS is a handle to a yield term structure. The calibration of BlackKarasinski is fine, but the calibration of CIR gives:

Calibrating Black--Karasinski...done.
terminate called after throwing an instance of 'std::runtime_error'
  what(): 
/usr/include/boost/shared_ptr.hpp:419: In function `T* boost::shared_ptr< <template-parameter-1-1> >::operator->() const [with T = QuantLib::StochasticProcess1D::discretization]':
Boost assertion failed: px != 0
Calibrating Cox--Ingersoll--Ross...Aborted

I have spent two days now treating the code with a debugger, and chasing through the QuantLib sources, but I still got no idea what the problem is here.

Any clues?


------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Problem calibrating short rate model

Harald Grossauer
Can it be that QuantLib's CoxIngersollRoss (and its Extended version)
are not supposed to be used together with a TreeCapFloorEngine?

The problem is that in CoxIngersollRoss::Dynamics a
CoxIngersollRoss::HelperProcess is constructed which inherits from
StochasticProcess1D, but calls only the default constructor of
StochasticProcess1D, where no discretization is constructed. Neither is
the function StochasticProcess1D::variance redefined, so when in the
course of the calibration the line
Real v2 = process->variance(t, 0.0, dt);
(trinomialtree.cpp, line 42, QuantLib 0.9.9) is called, "process" is a
zero pointer.

Is it a bug or a feature (not yet implemented)?


------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Problem calibrating short rate model

Luigi Ballabio
On Sat, 2009-12-05 at 19:23 +0100, Harald Grossauer wrote:
> The problem is that in CoxIngersollRoss::Dynamics a
> CoxIngersollRoss::HelperProcess is constructed which inherits from
> StochasticProcess1D, but calls only the default constructor of
> StochasticProcess1D, where no discretization is constructed. Neither is
> the function StochasticProcess1D::variance redefined

You're right.  We should either pass a discretization (Euler should work
as well as any, since the diffusion term is constant) or override the
variance method (and possibly others.)

Harald, you did some digging already---do you think you can find some
time to write a patch?

Luigi


--

Use every man after his desert, and who shall scape whipping?
-- Hamlet, Act II, scene II



------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users