|
From: Anthony D. <ant...@gm...> - 2016-07-30 20:45:46
|
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);
}
}
|