24#ifndef quantext_piecewise_price_hpp
25#define quantext_piecewise_price_hpp
29#include <ql/termstructures/localbootstrap.hpp>
30#include <ql/termstructures/yield/bootstraptraits.hpp>
31#include <ql/patterns/lazyobject.hpp>
39 typedef QuantLib::BootstrapHelper<PriceTermStructure>
helper;
43 return ts->referenceDate();
53 static QuantLib::Real
guess(QuantLib::Size i,
const C* c,
bool validData, QuantLib::Size j) {
56 return c->instrument(i-1)->quote()->value();
61 static QuantLib::Real
minValueAfter(QuantLib::Size i,
const C* c,
bool validData, QuantLib::Size j) {
63 Real g =
guess(i, c, validData, j);
64 return g < 0.0 ? g * 5.0 / 4.0 : g * 3.0 / 4.0;
69 static QuantLib::Real
maxValueAfter(QuantLib::Size i,
const C* c,
bool validData, QuantLib::Size j) {
71 Real g =
guess(i, c, validData, j);
72 return g < 0.0 ? g * 3.0 / 4.0 : g * 5.0 / 4.0;
76 static void updateGuess(std::vector<QuantLib::Real>& data, QuantLib::Real price, QuantLib::Size i) {
98template <
class Interpolator,
template <
class>
class Bootstrap = IterativeBootstrap>
106 typedef QuantLib::BootstrapHelper<PriceTermStructure>
helper;
113 const std::vector<QuantLib::ext::shared_ptr<helper> >& instruments,
114 const QuantLib::DayCounter& dayCounter,
116 const Interpolator& i = Interpolator(),
122 QuantLib::Date
maxDate()
const override;
123 QuantLib::Time
maxTime()
const override;
128 QuantLib::Time
minTime()
const override;
129 std::vector<QuantLib::Date>
pillarDates()
const override;
134 const std::vector<QuantLib::Time>&
times()
const;
135 const std::vector<QuantLib::Real>&
prices()
const;
139 const QuantLib::ext::shared_ptr<helper>&
instrument(QuantLib::Size i)
const;
149 QuantLib::Real
priceImpl(QuantLib::Time t)
const override;
161template <
class Interpolator,
template <
class>
class Bootstrap>
163 const QuantLib::Date& referenceDate,
164 const std::vector<QuantLib::ext::shared_ptr<helper> >& instruments,
165 const QuantLib::DayCounter& dayCounter,
166 const QuantLib::Currency& currency,
167 const Interpolator& i,
168 const Bootstrap<this_curve>& bootstrap)
169 :
base_curve(referenceDate, dayCounter, currency, i), instruments_(instruments),
170 accuracy_(1e-12), bootstrap_(bootstrap) {
177 [&referenceDate](
const QuantLib::ext::shared_ptr<helper>& inst) { return inst->pillarDate() > referenceDate; });
178 QL_REQUIRE(it !=
instruments_.end(),
"PiecewisePriceCurve: all instruments are expired.");
186template <
class Interpolator,
template <
class>
class Bootstrap>
189 return base_curve::maxDate();
192template <
class Interpolator,
template <
class>
class Bootstrap>
195 return base_curve::maxTime();
198template <
class Interpolator,
template <
class>
class Bootstrap>
201 return base_curve::minTime();
204template <
class Interpolator,
template <
class>
class Bootstrap>
207 return base_curve::pillarDates();
210template <
class Interpolator,
template <
class>
class Bootstrap>
213 return base_curve::times();
216template <
class Interpolator,
template <
class>
class Bootstrap>
219 return base_curve::prices();
222template <
class Interpolator,
template <
class>
class Bootstrap>
223const QuantLib::ext::shared_ptr<QuantLib::BootstrapHelper<PriceTermStructure> >&
225 QL_REQUIRE(i < instruments_.size(),
"Index (" << i <<
") greater than the number of instruments (" <<
226 instruments_.size() <<
").");
227 return instruments_[i];
230template <
class Interpolator,
template <
class>
class Bootstrap>
232 bootstrap_.calculate();
233 base_curve::performCalculations();
236template <
class Interpolator,
template <
class>
class Bootstrap>
239 return base_curve::priceImpl(t);
Interpolated price curve.
const QuantLib::Currency & currency() const override
The currency in which prices are expressed.
Piecewise price term structure.
QuantLib::Time minTime() const override
The minimum time for which the curve can return values.
void performCalculations() const override
PiecewisePriceCurve< Interpolator, Bootstrap > this_curve
PiecewisePriceCurve(const QuantLib::Date &referenceDate, const std::vector< QuantLib::ext::shared_ptr< helper > > &instruments, const QuantLib::DayCounter &dayCounter, const QuantLib::Currency ¤cy, const Interpolator &i=Interpolator(), const Bootstrap< this_curve > &bootstrap=Bootstrap< this_curve >())
Bootstrap< this_curve > bootstrap_
const QuantLib::ext::shared_ptr< helper > & instrument(QuantLib::Size i) const
Return the i-th instrument.
QuantLib::BootstrapHelper< PriceTermStructure > helper
const std::vector< QuantLib::Time > & times() const
InterpolatedPriceCurve< Interpolator > base_curve
Interpolator interpolator_type
QuantLib::Date maxDate() const override
const std::vector< QuantLib::Real > & prices() const
std::vector< QuantLib::Date > pillarDates() const override
The pillar dates for the PriceTermStructure.
std::vector< QuantLib::ext::shared_ptr< helper > > instruments_
friend class Bootstrap< this_curve >
QuantLib::Real priceImpl(QuantLib::Time t) const override
Price calculation.
QuantLib::Time maxTime() const override
Straight copy of ql/termstructures/iterativebootstrap.hpp with minor changes.
Interpolated price curve.
Traits class that is needed for Bootstrap classes to work.
static void updateGuess(std::vector< QuantLib::Real > &data, QuantLib::Real price, QuantLib::Size i)
Root finding update.
static QuantLib::Real guess(QuantLib::Size i, const C *c, bool validData, QuantLib::Size j)
Guesses.
QuantLib::BootstrapHelper< PriceTermStructure > helper
Helper type.
static QuantLib::Date initialDate(const PriceTermStructure *ts)
Start date of the term structure.
static QuantLib::Size maxIterations()
Maximum number of iterations to perform in search for root.
static QuantLib::Real maxValueAfter(QuantLib::Size i, const C *c, bool validData, QuantLib::Size j)
Maximum value after a given iteration.
static QuantLib::Real minValueAfter(QuantLib::Size i, const C *c, bool validData, QuantLib::Size j)
Minimum value after a given iteration.
static QuantLib::Real initialValue(const PriceTermStructure *ts)
Dummy value at reference date. Updated below along with first guess.