Re: Generalized Hull-White model problems

Posted by Alexander Lotter on
URL: http://quantlib.414.s1.nabble.com/Generalized-Hull-White-model-problems-tp12503p12505.html

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]