Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
piecewisezeroinflationcurve.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 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.a
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
19/*! \file qle/termstructures/inflation/piecewisezeroinflationcurve.hpp
20 \brief Piecewise interpolated zero inflation term structure
21 \ingroup termstructures
22*/
23
24#pragma once
25
26#include <ql/indexes/inflationindex.hpp>
27#include <ql/patterns/lazyobject.hpp>
28#include <ql/termstructures/iterativebootstrap.hpp>
31#include <utility>
32
33namespace QuantExt {
34
35//! Piecewise zero-inflation term structure
36template <class Interpolator, template <class> class Bootstrap = QuantLib::IterativeBootstrap,
37 class Traits = QuantExt::ZeroInflationTraits>
38class PiecewiseZeroInflationCurve : public QuantLib::InterpolatedZeroInflationCurve<Interpolator>,
39 public QuantLib::LazyObject,
40 public Traits::BootstrapFirstDateInitializer {
41private:
42 typedef QuantLib::InterpolatedZeroInflationCurve<Interpolator> base_curve;
44
45public:
46 typedef Traits traits_type;
47 typedef Interpolator interpolator_type;
48
49 //! \name Constructors
50 //@{
51 PiecewiseZeroInflationCurve(const QuantLib::Date& referenceDate, const QuantLib::Calendar& calendar,
52 const QuantLib::DayCounter& dayCounter, const QuantLib::Period& lag,
53 QuantLib::Frequency frequency, QuantLib::Rate baseZeroRate,
54 std::vector<QuantLib::ext::shared_ptr<typename Traits::helper>> instruments,
55 QuantLib::Real accuracy = 1.0e-12,
56 QuantLib::ext::shared_ptr<QuantLib::ZeroInflationIndex> index = nullptr,
57 bool useLastAvailableFixingAsBaseDate = false, const Interpolator& i = Interpolator())
58 : base_curve(referenceDate, calendar, dayCounter, lag, frequency, baseZeroRate, i),
59 instruments_(std::move(instruments)), accuracy_(accuracy), index_(index),
60 useLastAvailableFixingAsBaseDate_(useLastAvailableFixingAsBaseDate) {
61 bootstrap_.setup(this);
62 }
63 //@}
64
65 //! \name Inflation interface
66 //@{
67 QuantLib::Date baseDate() const override;
68 QuantLib::Date maxDate() const override;
69 void setSeasonality(const QuantLib::ext::shared_ptr<QuantLib::Seasonality>& seasonality =
70 QuantLib::ext::shared_ptr<QuantLib::Seasonality>()) override;
71 //@
72 //! \name Inspectors
73 //@{
74 const std::vector<QuantLib::Time>& times() const;
75 const std::vector<QuantLib::Date>& dates() const;
76 const std::vector<QuantLib::Real>& data() const;
77 std::vector<std::pair<QuantLib::Date, QuantLib::Real>> nodes() const;
78 //@}
79 //! \name Observer interface
80 //@{
81 void update() override;
82 //@}
83 //! \name Trait::BootstrapFirstDateInitializer interface
84 //@{
85 QuantLib::Date initialDate() const override;
86 //@}
87private:
88 // methods
89 void performCalculations() const override;
90 // data members
91 std::vector<QuantLib::ext::shared_ptr<typename Traits::helper>> instruments_;
92 QuantLib::Real accuracy_;
93
94 friend class Bootstrap<this_curve>;
95 friend class QuantLib::BootstrapError<this_curve>;
97 QuantLib::ext::shared_ptr<QuantLib::ZeroInflationIndex> index_;
99};
100
101// inline and template definitions
102
103template <class I, template <class> class B, class T>
105 this->calculate();
106 return base_curve::baseDate();
107}
108
109template <class I, template <class> class B, class T>
111 this->calculate();
112 return base_curve::maxDate();
113}
114
115template <class I, template <class> class B, class T>
116const std::vector<QuantLib::Time>& PiecewiseZeroInflationCurve<I, B, T>::times() const {
117 calculate();
118 return base_curve::times();
119}
120
121template <class I, template <class> class B, class T>
122const std::vector<QuantLib::Date>& PiecewiseZeroInflationCurve<I, B, T>::dates() const {
123 calculate();
124 return base_curve::dates();
125}
126
127template <class I, template <class> class B, class T>
128const std::vector<QuantLib::Real>& PiecewiseZeroInflationCurve<I, B, T>::data() const {
129 calculate();
130 return base_curve::rates();
131}
132
133template <class I, template <class> class B, class T>
134std::vector<std::pair<QuantLib::Date, QuantLib::Real>> PiecewiseZeroInflationCurve<I, B, T>::nodes() const {
135 calculate();
136 return base_curve::nodes();
137}
138
139template <class I, template <class> class B, class T>
141 bootstrap_.calculate();
142}
143
144template <class I, template <class> class B, class T> void PiecewiseZeroInflationCurve<I, B, T>::update() {
145 base_curve::update();
146 LazyObject::update();
147}
148
149template <class I, template <class> class B, class T>
151 return ZeroInflation::curveBaseDate(useLastAvailableFixingAsBaseDate_, base_curve::referenceDate(),
152 base_curve::observationLag(), base_curve::frequency(), index_);
153}
154
155template <class I, template <class> class B, class T>
156void PiecewiseZeroInflationCurve<I, B, T>::setSeasonality(const QuantLib::ext::shared_ptr<QuantLib::Seasonality>& seasonality) {
157 // always reset, whether with null or new pointer
158 base_curve::seasonality_ = seasonality;
159 if (base_curve::seasonality_ != nullptr) {
160 QL_REQUIRE(base_curve::seasonality_->isConsistent(*this), "Seasonality inconsistent with "
161 "inflation term structure");
162 }
163 update();
164}
165
166} // namespace QuantExt
Piecewise zero-inflation term structure.
void setSeasonality(const QuantLib::ext::shared_ptr< QuantLib::Seasonality > &seasonality=QuantLib::ext::shared_ptr< QuantLib::Seasonality >()) override
QuantExt::PiecewiseZeroInflationCurve< Interpolator, Bootstrap, Traits > this_curve
QuantLib::InterpolatedZeroInflationCurve< Interpolator > base_curve
const std::vector< QuantLib::Time > & times() const
const std::vector< QuantLib::Real > & data() const
PiecewiseZeroInflationCurve(const QuantLib::Date &referenceDate, const QuantLib::Calendar &calendar, const QuantLib::DayCounter &dayCounter, const QuantLib::Period &lag, QuantLib::Frequency frequency, QuantLib::Rate baseZeroRate, std::vector< QuantLib::ext::shared_ptr< typename Traits::helper > > instruments, QuantLib::Real accuracy=1.0e-12, QuantLib::ext::shared_ptr< QuantLib::ZeroInflationIndex > index=nullptr, bool useLastAvailableFixingAsBaseDate=false, const Interpolator &i=Interpolator())
std::vector< QuantLib::ext::shared_ptr< typename Traits::helper > > instruments_
QuantLib::ext::shared_ptr< QuantLib::ZeroInflationIndex > index_
const std::vector< QuantLib::Date > & dates() const
std::vector< std::pair< QuantLib::Date, QuantLib::Real > > nodes() const
Bootstrap traits to use for PiecewiseZeroInflationCurve.
some inflation related utilities.
interpolated correlation term structure
QuantLib::Date curveBaseDate(const bool baseDateLastKnownFixing, const QuantLib::Date &refDate, const QuantLib::Period obsLagCurve, const QuantLib::Frequency curveFreq, const QuantLib::ext::shared_ptr< QuantLib::ZeroInflationIndex > &index)
derives the zero inflation curve base date based on the useLastKnownFixing rule
Definition: inflation.cpp:172