Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
piecewiseconstanthelper.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
20
21#include <ql/termstructures/yieldtermstructure.hpp>
22
23namespace QuantExt {
24
25namespace {
26
27void checkTimes(const Array& t) {
28 if (t.size() == 0)
29 return;
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] << ")");
34 }
35}
36
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]);
41 }
42 return res;
43}
44
45} // anonymous namespace
46
48 const QuantLib::ext::shared_ptr<Constraint>& constraint)
49 : t_(t), y_(QuantLib::ext::make_shared<PseudoParameter>(t.size() + 1, *constraint)) {
50 checkTimes(t_);
51}
52
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)) {
58 checkTimes(t_);
59}
60
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) {}
65
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) {}
72
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)) {
77 checkTimes(t_);
78}
79
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)) {
85 checkTimes(t_);
86}
87
88PiecewiseConstantHelper2::PiecewiseConstantHelper2(const Array& t, const QuantLib::ext::shared_ptr<PseudoParameter>& p)
89 : zeroCutoff_(1.0E-6), t_(t), y_(p) {}
90
91PiecewiseConstantHelper3::PiecewiseConstantHelper3(const Array& t1, const Array& t2,
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),
95 y1_(QuantLib::ext::make_shared<PseudoParameter>(t1.size() + 1, *constraint1)),
96 y2_(QuantLib::ext::make_shared<PseudoParameter>(t2.size() + 1, *constraint2)) {
97 checkTimes(t1_);
98 checkTimes(t2_);
99}
100
101PiecewiseConstantHelper3::PiecewiseConstantHelper3(const std::vector<Date>& dates1,
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)) {
111 checkTimes(t1_);
112 checkTimes(t2_);
113}
114
115} // namespace QuantExt
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