Heston model calibration - Diff Evolution

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

Heston model calibration - Diff Evolution

Anthony Dimiceli
Hi ,

I am still learning QLib and I have inherited some code for calibrating Heston model. The calibration is using Differential Evolution and is working out of the box. However, this code is based on QL 1.1 version and we have decided to upgrade to the current version. After the upgrade I realized that HestonBootStrapFunction and HestonConstraint classes have been retired (probably). My question is, how do I adapt the below code section to the 1.8 version ?
Thanks for the awesome library..I have a lot to learn..

boost::shared_ptr<QuantLib::PiecewiseTimeDependentHestonModel> model_ =

                                                boost::shared_ptr<QuantLib::PiecewiseTimeDependentHestonModel>(

                                                                new QuantLib::PiecewiseTimeDependentHestonModel(interestRateTermStructure, dividendTermStructure,

                                                                                s0, v0, theta, kappa, sigma, rho, timeGrid));

 

                                boost::shared_ptr<QuantLib::PricingEngine> engine_( new QuantLib::AnalyticPTDHestonEngine(model_) );

 

                                QuantLib::Array params(5);

                                // initial conditions

                                params[0] = theta0; params[1] = kappa0; params[2] = sigma0; params[3] = rho0; params[4] = v0;

 

                                std::vector<boost::shared_ptr<QuantLib::CalibrationHelper>>::iterator h;

                                for(QuantLib::Size i=0; i<CalibrationDates.size(); i++)

                                {

                                                QuantLib::Date currentDate = CalibrationDates[i];

                                                if( helpers_.find( currentDate ) != helpers_.end() )

                                                {

                                                                for( h=helpers_[currentDate].begin(); h!=helpers_[currentDate].end(); h++ )

                                                                                (*h)->setPricingEngine(engine_);

 

                                                                QuantLib::HestonBootstrapFunction HestonBootstrapFunction(model_, i, helpers_[currentDate]);

 

                                                                QuantLib::HestonConstraint Constraint(parameters);

                                                                QuantLib::Problem Problem(HestonBootstrapFunction, Constraint, params);

 

                                                                QuantLib::DifferentialEvolution::Configuration config;

                                                                config.withPopulationMembers(PopulationSizeCpp);

                                                               

                                                                QuantLib::DifferentialEvolution DEvolution(config);

 

                                                                QuantLib::EndCriteria EndCriteria(50, 2, StationarityCpp, StationarityCpp, 1e-3);

 

                                                                QuantLib::EndCriteria::Type Type = DEvolution.minimize(Problem, EndCriteria);

 

                                                                QuantLib::Real cost = Problem.value(Problem.currentValue());

 

                                                                params = Problem.currentValue();

 

                                                                calculation_times.push_back((clock() - begin) / CLOCKS_PER_SEC);

                                                                calculation_errors.push_back(cost);

 

                                                }

                                }

------------------------------------------------------------------------------

_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Heston model calibration - Diff Evolution

Luigi Ballabio
Hello,
    sorry for the delay. I'm kind of puzzled--the HestonConstraint and HestonBootstrapFunction classes don't exist in QuantLib 1.1 or in later versions, and DifferentialEvolution was only added in version 1.3.  I suspect you're using a version of QuantLib that was internally customized.  Can you check in which file HestonConstraint is defined?

Luigi


On Sun, Jul 31, 2016 at 6:55 PM Anthony Dimiceli <[hidden email]> wrote:
Hi ,

I am still learning QLib and I have inherited some code for calibrating Heston model. The calibration is using Differential Evolution and is working out of the box. However, this code is based on QL 1.1 version and we have decided to upgrade to the current version. After the upgrade I realized that HestonBootStrapFunction and HestonConstraint classes have been retired (probably). My question is, how do I adapt the below code section to the 1.8 version ?
Thanks for the awesome library..I have a lot to learn..

boost::shared_ptr<QuantLib::PiecewiseTimeDependentHestonModel> model_ =

                                                boost::shared_ptr<QuantLib::PiecewiseTimeDependentHestonModel>(

                                                                new QuantLib::PiecewiseTimeDependentHestonModel(interestRateTermStructure, dividendTermStructure,

                                                                                s0, v0, theta, kappa, sigma, rho, timeGrid));

 

                                boost::shared_ptr<QuantLib::PricingEngine> engine_( new QuantLib::AnalyticPTDHestonEngine(model_) );

 

                                QuantLib::Array params(5);

                                // initial conditions

                                params[0] = theta0; params[1] = kappa0; params[2] = sigma0; params[3] = rho0; params[4] = v0;

 

                                std::vector<boost::shared_ptr<QuantLib::CalibrationHelper>>::iterator h;

                                for(QuantLib::Size i=0; i<CalibrationDates.size(); i++)

                                {

                                                QuantLib::Date currentDate = CalibrationDates[i];

                                                if( helpers_.find( currentDate ) != helpers_.end() )

                                                {

                                                                for( h=helpers_[currentDate].begin(); h!=helpers_[currentDate].end(); h++ )

                                                                                (*h)->setPricingEngine(engine_);

 

                                                                QuantLib::HestonBootstrapFunction HestonBootstrapFunction(model_, i, helpers_[currentDate]);

 

                                                                QuantLib::HestonConstraint Constraint(parameters);

                                                                QuantLib::Problem Problem(HestonBootstrapFunction, Constraint, params);

 

                                                                QuantLib::DifferentialEvolution::Configuration config;

                                                                config.withPopulationMembers(PopulationSizeCpp);

                                                               

                                                                QuantLib::DifferentialEvolution DEvolution(config);

 

                                                                QuantLib::EndCriteria EndCriteria(50, 2, StationarityCpp, StationarityCpp, 1e-3);

 

                                                                QuantLib::EndCriteria::Type Type = DEvolution.minimize(Problem, EndCriteria);

 

                                                                QuantLib::Real cost = Problem.value(Problem.currentValue());

 

                                                                params = Problem.currentValue();

 

                                                                calculation_times.push_back((clock() - begin) / CLOCKS_PER_SEC);

                                                                calculation_errors.push_back(cost);

 

                                                }

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

------------------------------------------------------------------------------

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