21#include <ql/termstructures/yieldtermstructure.hpp>
27void checkTimes(
const Array& t) {
30 QL_REQUIRE(t.front() > 0.0,
"first time (" << t.front() <<
") must be positive");
31 for (Size i = 0; i < t.size() - 1; ++i) {
32 QL_REQUIRE(t[i] < t[i + 1],
"times must be strictly increasing, entries at ("
33 << i <<
"," << i + 1 <<
") are (" << t[i] <<
"," << t[i + 1] <<
")");
37Array datesToTimes(
const std::vector<Date>& dates,
const Handle<YieldTermStructure>& yts) {
38 Array res(dates.size());
39 for (Size i = 0; i < dates.size(); ++i) {
40 res[i] = yts->timeFromReference(dates[i]);
48 const QuantLib::ext::shared_ptr<Constraint>& constraint)
49 : t_(t), y_(
QuantLib::ext::make_shared<PseudoParameter>(t.size() + 1, *constraint)) {
53PiecewiseConstantHelper1::PiecewiseConstantHelper1(
const std::vector<Date>& dates,
54 const Handle<YieldTermStructure>& yts,
55 const QuantLib::ext::shared_ptr<Constraint>& constraint)
56 : t_(datesToTimes(dates, yts)),
57 y_(
QuantLib::ext::make_shared<PseudoParameter>(dates.size() + 1, *constraint)) {
61PiecewiseConstantHelper11::PiecewiseConstantHelper11(
const Array& t1,
const Array& t2,
62 const QuantLib::ext::shared_ptr<Constraint>& constraint1,
63 const QuantLib::ext::shared_ptr<Constraint>& constraint2)
64 : h1_(t1, constraint1), h2_(t2, constraint2) {}
66PiecewiseConstantHelper11::PiecewiseConstantHelper11(
const std::vector<Date>& dates1,
67 const std::vector<Date>& dates2,
68 const Handle<YieldTermStructure>& yts,
69 const QuantLib::ext::shared_ptr<Constraint>& constraint1,
70 const QuantLib::ext::shared_ptr<Constraint>& constraint2)
71 : h1_(dates1, yts, constraint1), h2_(dates2, yts, constraint2) {}
73PiecewiseConstantHelper2::PiecewiseConstantHelper2(
const Array& t,
74 const QuantLib::ext::shared_ptr<Constraint>& constraint)
75 : zeroCutoff_(1.0E-6), t_(t),
76 y_(
QuantLib::ext::make_shared<PseudoParameter>(t.size() + 1, *constraint)) {
80PiecewiseConstantHelper2::PiecewiseConstantHelper2(
const std::vector<Date>& dates,
81 const Handle<YieldTermStructure>& yts,
82 const QuantLib::ext::shared_ptr<Constraint>& constraint)
83 : zeroCutoff_(1.0E-6), t_(datesToTimes(dates, yts)),
84 y_(
QuantLib::ext::make_shared<PseudoParameter>(dates.size() + 1, *constraint)) {
88PiecewiseConstantHelper2::PiecewiseConstantHelper2(
const Array& t,
const QuantLib::ext::shared_ptr<PseudoParameter>& p)
89 : zeroCutoff_(1.0E-6), t_(t), y_(p) {}
92 const QuantLib::ext::shared_ptr<Constraint>& constraint1,
93 const QuantLib::ext::shared_ptr<Constraint>& constraint2)
94 : zeroCutoff_(1.0E-6), t1_(t1), t2_(t2),
102 const std::vector<Date>& dates2,
103 const Handle<YieldTermStructure>& yts,
104 const QuantLib::ext::shared_ptr<Constraint>& constraint1,
105 const QuantLib::ext::shared_ptr<Constraint>& constraint2)
106 : zeroCutoff_(1.0E-6),
107 t1_(datesToTimes(dates1, yts)),
108 t2_(datesToTimes(dates2, yts)),
109 y1_(
QuantLib::ext::make_shared<PseudoParameter>(dates1.size() + 1, *constraint1)),
110 y2_(
QuantLib::ext::make_shared<PseudoParameter>(dates2.size() + 1, *constraint2)) {
PiecewiseConstantHelper1(const Array &t, const QuantLib::ext::shared_ptr< QuantLib::Constraint > &constraint=QuantLib::ext::make_shared< QuantLib::NoConstraint >())
PiecewiseConstantHelper3(const Array &t1, const Array &t2, const QuantLib::ext::shared_ptr< QuantLib::Constraint > &constraint1=QuantLib::ext::make_shared< QuantLib::NoConstraint >(), const QuantLib::ext::shared_ptr< QuantLib::Constraint > &constraint2=QuantLib::ext::make_shared< QuantLib::NoConstraint >())
Parameter that accesses CalibratedModel.
helper classes for piecewise constant parametrizations