Posted by
Alexander Lotter on
URL: http://quantlib.414.s1.nabble.com/Generalized-Hull-White-model-problems-tp12503p12513.html
Hello Javit,
I used this setting:
TimeGrid grid(times.begin(), times.end(), 1);
// defining the models
boost::shared_ptr<G2> modelG2(new G2(rhTermStructure));
boost::shared_ptr<HullWhite> modelHW(new HullWhite(rhTermStructure));
boost::shared_ptr<HullWhite> modelHW2(new HullWhite(rhTermStructure));
boost::shared_ptr<BlackKarasinski> modelBK(
new BlackKarasinski(rhTermStructure));
//------------------ GHW model ---------
std::vector<Date> GHWdates;
GHWdates.push_back(calendar.advance(settlementDate,0,Years));
GHWdates.push_back(calendar.advance(settlementDate,12,Months,floatingLegConvention));
GHWdates.push_back(calendar.advance(settlementDate,73,Months,floatingLegConvention));
std::vector<Real> a(3, 0.04);
std::vector<Real> sigma(3, 0.1);
boost::shared_ptr<GeneralizedHullWhite> generalizedHWmodel(
new GeneralizedHullWhite(rhTermStructure, GHWdates, GHWdates, a, sigma));
Please correct me, if I've forgotten something.
Cheers
Alexander
<quote author="Javit Hafizoglu">
Alexander,
I believe Luigi forgot to change the generalized HW code when he made the change in the parameter class to include the positive constraint. Your point for the "size()" vs "size()+1" is valid.
I didn't notice anything because I still use the older version of GHW with quantlib 9.7.
Per the tests, I tested the GHW code and it worked when I submitted. I ran my tests by adding couple of lines into BermudanSwaption.cpp I used only two timepoints for the volatility and the reversion parameters. It takes significantly long if you include more time points. I would suggest both decreasing the timegrid and the timepoints (let me know if you don't understand what I meant here by timepoints) to decrease the optimization time. And once optimized, initiate your next search with the most recent model parameters.
Luigi, please let me know if you would like me to get involved also.
Thank you,
Javit
Alexander Lotter wrote
Hello Luigi,
thanks for the quick reply.
>The PiecewiseConstantParameter class was modified in revision 17224 to
>take an optional constraint, so that's taken care of; the code in the
>trunk instantiates it with a PositiveConstraint.
I am not sure this is enough. This peace of code in QL causes problems:
----
PiecewiseConstantParameter(const std::vector<Time>& times,
const Constraint& constraint =
NoConstraint())
: Parameter(times.size()+1,
boost::shared_ptr<Parameter::Impl>(
new PiecewiseConstantParameter::Impl(times)),
constraint)
{}
----
should be
----
public:
PiecewiseConstantParameter(const std::vector<Time>& times,
const Constraint& constraint =
NoConstraint())
: Parameter(times.size(),
----
times.size() not times.size() + 1, in this case I get run time exception in the following functions
---
boost::function<Real (Time)> GeneralizedHullWhite::speed() const {
std::vector<Real> speedvals;
speedvals.push_back(a_(0.0001));
for (Size i=0;i<a_.size()-1;i++)
speedvals.push_back(
a_(
(speedstructure_[i+1]-speedstructure_[0])/365.0
- 0.00001));
return PiecewiseLinearCurve(speedperiods_, speedvals);
}
boost::function<Real (Time)> GeneralizedHullWhite::vol() const {
std::vector<Real> volvals;
volvals.push_back(sigma_(0.0001));
for (Size i=0;i<sigma_.size()-1;i++)
volvals.push_back(
sigma_(
(speedstructure_[i+1]-speedstructure_[0])/365.0
- 0.00001));
return PiecewiseLinearCurve(volperiods_, volvals);
}
---
vector subscript out of range
a_.size() - 1 and sigma_.size() - 1 are bigger than speedstructure_[i+1]
</quote>