QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
btp.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2010, 2011 Ferdinando Ametrano
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20/*! \file btp.hpp
21 \brief Italian BTP (Buoni Poliennali del Tesoro) fixed rate bond
22*/
23
24#ifndef quantlib_btp_hpp
25#define quantlib_btp_hpp
26
31
32#include <numeric>
33
34namespace QuantLib {
35
36 /*! Italian CCTEU (Certificato di credito del tesoro)
37 Euribor6M indexed floating rate bond
38
39 \ingroup instruments
40
41 */
42 class CCTEU : public FloatingRateBond {
43 public:
44 CCTEU(const Date& maturityDate,
45 Spread spread,
46 const Handle<YieldTermStructure>& fwdCurve =
48 const Date& startDate = Date(),
49 const Date& issueDate = Date());
50 //! \name Bond interface
51 //@{
52 //! accrued amount at a given date
53 /*! The default bond settlement is used if no date is given. */
54 Real accruedAmount(Date d = Date()) const override;
55 //@}
56 };
57
58 //! Italian BTP (Buono Poliennali del Tesoro) fixed rate bond
59 /*! \ingroup instruments
60
61 */
62 class BTP : public FixedRateBond {
63 public:
64 BTP(const Date& maturityDate,
65 Rate fixedRate,
66 const Date& startDate = Date(),
67 const Date& issueDate = Date());
68 /*! constructor needed for legacy non-par redemption BTPs.
69 As of today the only remaining one is IT123456789012
70 that will redeem 99.999 on xx-may-2037 */
71 BTP(const Date& maturityDate,
72 Rate fixedRate,
74 const Date& startDate = Date(),
75 const Date& issueDate = Date());
76 //! \name Bond interface
77 //@{
78 //! accrued amount at a given date
79 /*! The default bond settlement is used if no date is given. */
80 Real accruedAmount(Date d = Date()) const override;
81 //@}
82 //! BTP yield given a (clean) price and settlement date
83 /*! The default BTP conventions are used: Actual/Actual (ISMA),
84 Compounded, Annual.
85 The default bond settlement is used if no date is given. */
88 Real accuracy = 1.0e-8,
89 Size maxEvaluations = 100) const;
90 };
91
92 class RendistatoBasket : public Observer,
93 public Observable {
94 public:
95 RendistatoBasket(const std::vector<ext::shared_ptr<BTP> >& btps,
96 const std::vector<Real>& outstandings,
97 std::vector<Handle<Quote> > cleanPriceQuotes);
98 //! \name Inspectors
99 //@{
100 Size size() const { return n_;}
101 const std::vector<ext::shared_ptr<BTP> >& btps() const;
102 const std::vector<Handle<Quote> >& cleanPriceQuotes() const;
103 const std::vector<Real>& outstandings() const { return outstandings_;}
104 const std::vector<Real>& weights() const { return weights_;}
105 Real outstanding() const { return outstanding_;}
106 //@}
107 //! \name Observer interface
108 //@{
109 void update() override { notifyObservers(); }
110 //@}
111 private:
112 std::vector<ext::shared_ptr<BTP> > btps_;
113 std::vector<Real> outstandings_;
114 std::vector<Handle<Quote> > quotes_;
117 std::vector<Real> weights_;
118 };
119
121 public:
122 RendistatoCalculator(ext::shared_ptr<RendistatoBasket> basket,
123 ext::shared_ptr<Euribor> euriborIndex,
124 Handle<YieldTermStructure> discountCurve);
125 //! \name Calculations
126 //@{
127 Rate yield() const;
128 Time duration() const;
129 // bonds
130 const std::vector<Rate>& yields() const;
131 const std::vector<Time>& durations() const;
132 // swaps
133 const std::vector<Time>& swapLengths() const;
134 const std::vector<Rate>& swapRates() const;
135 const std::vector<Rate>& swapYields() const;
136 const std::vector<Time>& swapDurations() const;
137 //@}
138 //! \name Equivalent Swap proxy
139 //@{
140 ext::shared_ptr<VanillaSwap> equivalentSwap() const;
141 Rate equivalentSwapRate() const;
146 //@}
147 protected:
148 //! \name LazyObject interface
149 //@{
150 void performCalculations() const override;
151 //@}
152 private:
153 ext::shared_ptr<RendistatoBasket> basket_;
154 ext::shared_ptr<Euribor> euriborIndex_;
156
157 mutable std::vector<Rate> yields_;
158 mutable std::vector<Time> durations_;
161
163 mutable std::vector<ext::shared_ptr<VanillaSwap> > swaps_;
164 std::vector<Time> swapLengths_;
165 mutable std::vector<Time> swapBondDurations_;
166 mutable std::vector<Rate> swapBondYields_, swapRates_;
167 };
168
169 //! RendistatoCalculator equivalent swap lenth Quote adapter
171 public:
172 RendistatoEquivalentSwapLengthQuote(ext::shared_ptr<RendistatoCalculator> r);
173 Real value() const override;
174 bool isValid() const override;
175
176 private:
177 ext::shared_ptr<RendistatoCalculator> r_;
178 };
179
180 //! RendistatoCalculator equivalent swap spread Quote adapter
182 public:
183 RendistatoEquivalentSwapSpreadQuote(ext::shared_ptr<RendistatoCalculator> r);
184 Real value() const override;
185 bool isValid() const override;
186
187 private:
188 ext::shared_ptr<RendistatoCalculator> r_;
189 };
190
191 // inline
192
195 return ClosestRounding(5)(result);
196 }
197
200 return ClosestRounding(5)(result);
201 }
202
203 inline const std::vector<ext::shared_ptr<BTP> >&
205 return btps_;
206 }
207
208 inline const std::vector<Handle<Quote> >&
210 return quotes_;
211 }
212
214 return std::inner_product(basket_->weights().begin(),
215 basket_->weights().end(),
216 yields().begin(), Real(0.0));
217 }
218
220 calculate();
221 return duration_;
222 }
223
224 inline const std::vector<Rate>& RendistatoCalculator::yields() const {
225 calculate();
226 return yields_;
227 }
228
229 inline const std::vector<Time>& RendistatoCalculator::durations() const {
230 calculate();
231 return durations_;
232 }
233
234 inline const std::vector<Time>& RendistatoCalculator::swapLengths() const {
235 return swapLengths_;
236 }
237
238 inline const std::vector<Rate>& RendistatoCalculator::swapRates() const {
239 calculate();
240 return swapRates_;
241 }
242
243 inline const std::vector<Rate>& RendistatoCalculator::swapYields() const {
244 calculate();
245 return swapBondYields_;
246 }
247
248 inline const std::vector<Time>& RendistatoCalculator::swapDurations() const {
249 calculate();
250 return swapBondDurations_;
251 }
252
253 inline ext::shared_ptr<VanillaSwap>
255 calculate();
257 }
258
260 calculate();
262 }
263
265 calculate();
267 }
268
270 calculate();
272 }
273
275 calculate();
277 }
278
280 return yield() - equivalentSwapRate();
281 }
282
284 return r_->equivalentSwapLength();
285 }
286
288 return r_->equivalentSwapSpread();
289 }
290
291}
292
293#endif
Italian BTP (Buono Poliennali del Tesoro) fixed rate bond.
Definition: btp.hpp:62
Rate yield(Real cleanPrice, Date settlementDate=Date(), Real accuracy=1.0e-8, Size maxEvaluations=100) const
BTP yield given a (clean) price and settlement date.
Definition: btp.cpp:82
Real accruedAmount(Date d=Date()) const override
accrued amount at a given date
Definition: btp.hpp:198
Real cleanPrice() const
theoretical clean price
Definition: bond.cpp:174
virtual Real accruedAmount(Date d=Date()) const
accrued amount at a given date
Definition: bond.cpp:267
Date startDate() const
Definition: bond.cpp:146
Date issueDate() const
Definition: bond.hpp:352
const ext::shared_ptr< CashFlow > & redemption() const
Definition: bond.cpp:140
Date maturityDate() const
Definition: bond.cpp:150
Date settlementDate(Date d=Date()) const
Definition: bond.cpp:161
Real accruedAmount(Date d=Date()) const override
accrued amount at a given date
Definition: btp.hpp:193
Closest rounding.
Definition: rounding.hpp:106
Concrete date class.
Definition: date.hpp:125
floating-rate bond (possibly capped and/or floored)
Shared handle to an observable.
Definition: handle.hpp:41
T result(const std::string &tag) const
returns any additional result returned by the pricing engine.
Definition: instrument.hpp:188
Framework for calculation on demand and result caching.
Definition: lazyobject.hpp:35
virtual void calculate() const
Definition: lazyobject.hpp:253
Object that notifies its changes to a set of observers.
Definition: observable.hpp:62
Object that gets notified when a given observable changes.
Definition: observable.hpp:116
purely virtual base class for market observables
Definition: quote.hpp:37
const std::vector< ext::shared_ptr< BTP > > & btps() const
Definition: btp.hpp:204
void update() override
Definition: btp.hpp:109
const std::vector< Real > & outstandings() const
Definition: btp.hpp:103
std::vector< ext::shared_ptr< BTP > > btps_
Definition: btp.hpp:112
const std::vector< Handle< Quote > > & cleanPriceQuotes() const
Definition: btp.hpp:209
const std::vector< Real > & weights() const
Definition: btp.hpp:104
Real outstanding() const
Definition: btp.hpp:105
std::vector< Real > weights_
Definition: btp.hpp:117
std::vector< Real > outstandings_
Definition: btp.hpp:113
std::vector< Handle< Quote > > quotes_
Definition: btp.hpp:114
Size size() const
Definition: btp.hpp:100
void performCalculations() const override
Definition: btp.cpp:156
Rate equivalentSwapYield() const
Definition: btp.hpp:264
Handle< YieldTermStructure > discountCurve_
Definition: btp.hpp:155
const std::vector< Time > & swapLengths() const
Definition: btp.hpp:234
const std::vector< Rate > & swapYields() const
Definition: btp.hpp:243
std::vector< Time > swapBondDurations_
Definition: btp.hpp:165
ext::shared_ptr< Euribor > euriborIndex_
Definition: btp.hpp:154
std::vector< Time > swapLengths_
Definition: btp.hpp:164
const std::vector< Rate > & yields() const
Definition: btp.hpp:224
std::vector< Rate > swapBondYields_
Definition: btp.hpp:166
Time equivalentSwapLength() const
Definition: btp.hpp:274
ext::shared_ptr< VanillaSwap > equivalentSwap() const
Definition: btp.hpp:254
const std::vector< Time > & durations() const
Definition: btp.hpp:229
std::vector< ext::shared_ptr< VanillaSwap > > swaps_
Definition: btp.hpp:163
std::vector< Time > durations_
Definition: btp.hpp:158
std::vector< Rate > yields_
Definition: btp.hpp:157
std::vector< Rate > swapRates_
Definition: btp.hpp:166
const std::vector< Time > & swapDurations() const
Definition: btp.hpp:248
Spread equivalentSwapSpread() const
Definition: btp.hpp:279
const std::vector< Rate > & swapRates() const
Definition: btp.hpp:238
Rate equivalentSwapRate() const
Definition: btp.hpp:259
ext::shared_ptr< RendistatoBasket > basket_
Definition: btp.hpp:153
Time equivalentSwapDuration() const
Definition: btp.hpp:269
RendistatoCalculator equivalent swap lenth Quote adapter.
Definition: btp.hpp:170
ext::shared_ptr< RendistatoCalculator > r_
Definition: btp.hpp:177
Real value() const override
returns the current value
Definition: btp.hpp:283
bool isValid() const override
returns true if the Quote holds a valid value
Definition: btp.cpp:227
RendistatoCalculator equivalent swap spread Quote adapter.
Definition: btp.hpp:181
ext::shared_ptr< RendistatoCalculator > r_
Definition: btp.hpp:188
Real value() const override
returns the current value
Definition: btp.hpp:287
bool isValid() const override
returns true if the Quote holds a valid value
Definition: btp.cpp:240
Euribor index
Date d
fixed-rate bond
floating-rate bond
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real Spread
spreads on interest rates
Definition: types.hpp:74
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
ext::shared_ptr< YieldTermStructure > r
Simple fixed-rate vs Libor swap.