|
From: Amine I. <ami...@gm...> - 2020-07-06 13:34:11
|
Thanks Luigi & all,
Been trying to get my calibration to run on a G2 model where I only calibrate the volatility params, so I specify that fixedparameter vector for those two parameters is set to false. However, they remain unchanged.
Any idea as to what I may be doing wrong? Below are the snippets of code I used.
Thanks,
Amine
void calibrateModel(ShortRateModel& model, const std::vector<boost::shared_ptr<CalibrationHelper>> &helpers,
const std::vector<Real>& weights, const std::vector<bool>& fixParameters)
{
LevenbergMarquardt om;
EndCriteria stop(400, 100, 1.0e-5, 1.0e-7, 1.0e-5);
model.calibrate(helpers, om, stop, Constraint(), weights, fixParameters);
return;
}
// Calibrate and log calibrated parameters
Real correls[] = {-0.9, -0.5, -0.2 };
Real a = 0.8, sigma1 = 0.01, b = 0.15, eta = 0.0085, rho = correls[0];
boost::shared_ptr<ShortRateModel> modelG2 =
boost::make_shared<G2>(Handle<YieldTermStructure>(yieldCurveInput), a, sigma1, b, eta, rho);
auto modelG2Params = modelG2->params();
std::vector<bool> nonFreeModelG2Params(modelG2Params.size());
nonFreeModelG2Params[0] = true; nonFreeModelG2Params[1]=false;
nonFreeModelG2Params[2] = true; nonFreeModelG2Params[3]=false; // <== modelG2 parameters that will be calibrated (i.e, non fixed)
nonFreeModelG2Params[4] = true;
calibrateModel(*modelG2, swaptionhelpers, std::vector<Real>(), nonFreeModelG2Params);
std::cout << "\nCalibrated G2 model parameters: " << "\n\n";
auto calibratedParams=modelG2->params();
for(auto i=0; i<calibratedParams.size(); ++i)
std::cout << calibratedParams[i] << "\n";
> On 3 Jul 2020, at 14:08, Luigi Ballabio <lui...@gm...> wrote:
>
> Hello,
> see Examples/BermudanSwaption/BermudanSwaption.cpp.
>
> Luigi
>
>
> On Fri, Jul 3, 2020 at 2:50 PM Amine Ifri <ami...@gm... <mailto:ami...@gm...>> wrote:
> Hi all,
>
> Looking to calibrate model parameters of a G2 model for rates on a set of swaption volatilities, is there a class in QuantLib that does just that, or does one need to write it from scratch?
>
> Thanks,
> Amine
>
|