QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
bond.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2004 Jeff Yu
5 Copyright (C) 2004 M-Dimension Consulting Inc.
6 Copyright (C) 2005, 2006, 2007, 2008 StatPro Italia srl
7 Copyright (C) 2007, 2008, 2009 Ferdinando Ametrano
8 Copyright (C) 2007 Chiara Fornarola
9 Copyright (C) 2008 Simon Ibbotson
10
11 This file is part of QuantLib, a free-software/open-source library
12 for financial quantitative analysts and developers - http://quantlib.org/
13
14 QuantLib is free software: you can redistribute it and/or modify it
15 under the terms of the QuantLib license. You should have received a
16 copy of the license along with this program; if not, please email
17 <quantlib-dev@lists.sf.net>. The license is also available online at
18 <http://quantlib.org/license.shtml>.
19
20 This program is distributed in the hope that it will be useful, but WITHOUT
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. See the license for more details.
23*/
24
29#ifndef quantlib_bond_hpp
30#define quantlib_bond_hpp
31
32#include <ql/instrument.hpp>
33
34#include <ql/time/calendar.hpp>
35#include <ql/cashflow.hpp>
36#include <ql/compounding.hpp>
37
38#include <vector>
39
40namespace QuantLib {
41
42 class DayCounter;
43
45
59 class Bond : public Instrument {
60 public:
62 class Price {
63 public:
64 enum Type { Dirty, Clean };
67 Real amount() const {
68 QL_REQUIRE(amount_ != Null<Real>(), "no amount given");
69 return amount_;
70 }
71 Type type() const { return type_; }
72 private:
75 };
76
78
84 const Date& issueDate = Date(),
85 const Leg& coupons = Leg());
86
88
94 Real faceAmount,
95 const Date& maturityDate,
96 const Date& issueDate = Date(),
97 const Leg& cashflows = Leg());
98
99 class arguments;
100 class results;
101 class engine;
102
104
105 bool isExpired() const override;
107
109 void deepUpdate() override;
111
113 Natural settlementDays() const;
114 const Calendar& calendar() const;
115
116 const std::vector<Real>& notionals() const;
117 virtual Real notional(Date d = Date()) const;
118
120 const Leg& cashflows() const;
122 const Leg& redemptions() const;
124 const ext::shared_ptr<CashFlow>& redemption() const;
125
126 Date startDate() const;
127 Date maturityDate() const;
128 Date issueDate() const;
129
130 bool isTradable(Date d = Date()) const;
131 Date settlementDate(Date d = Date()) const;
133
135
136
138
147 Real cleanPrice() const;
148
150
159 Real dirtyPrice() const;
160
162
163 Real settlementValue() const;
164
166
169 Rate yield(const DayCounter& dc,
170 Compounding comp,
171 Frequency freq,
172 Real accuracy = 1.0e-8,
173 Size maxEvaluations = 100,
174 Real guess = 0.05,
175 Bond::Price::Type priceType = Bond::Price::Clean) const;
176
178
180 const DayCounter& dc,
181 Compounding comp,
182 Frequency freq,
183 Date settlementDate = Date()) const;
184
186
188 const DayCounter& dc,
189 Compounding comp,
190 Frequency freq,
191 Date settlementDate = Date()) const;
192
194
196
198
199 Rate yield(Real price,
200 const DayCounter& dc,
201 Compounding comp,
202 Frequency freq,
204 Real accuracy = 1.0e-8,
205 Size maxEvaluations = 100,
206 Real guess = 0.05,
207 Bond::Price::Type priceType = Bond::Price::Clean) const;
208
210
211 virtual Real accruedAmount(Date d = Date()) const;
213
221 virtual Rate nextCouponRate(Date d = Date()) const;
222
224
231 Rate previousCouponRate(Date d = Date()) const;
232
233 Date nextCashFlowDate(Date d = Date()) const;
234 Date previousCashFlowDate(Date d = Date()) const;
235
236 protected:
237 void setupExpired() const override;
238 void setupArguments(PricingEngine::arguments*) const override;
239 void fetchResults(const PricingEngine::results*) const override;
240
255 void addRedemptionsToCashflows(const std::vector<Real>& redemptions
256 = std::vector<Real>());
257
265 const Date& date);
266
273 const ext::shared_ptr<CashFlow>& redemption);
274
283
286 std::vector<Date> notionalSchedule_;
287 std::vector<Real> notionals_;
288 Leg cashflows_; // all cashflows
289 Leg redemptions_; // the redemptions
290
293 };
294
296 public:
300 void validate() const override;
301 };
302
304 public:
306 void reset() override {
309 }
310 };
311
312 class Bond::engine : public GenericEngine<Bond::arguments,
313 Bond::results> {};
314
315
316 // inline definitions
317
319 return settlementDays_;
320 }
321
322 inline const Calendar& Bond::calendar() const {
323 return calendar_;
324 }
325
326 inline const std::vector<Real>& Bond::notionals() const {
327 return notionals_;
328 }
329
330 inline const Leg& Bond::cashflows() const {
331 return cashflows_;
332 }
333
334 inline const Leg& Bond::redemptions() const {
335 return redemptions_;
336 }
337
338 inline Date Bond::issueDate() const {
339 return issueDate_;
340 }
341
342}
343
344#endif
Bond price information.
Definition: bond.hpp:62
Price(Real amount, Type type)
Definition: bond.hpp:66
Type type() const
Definition: bond.hpp:71
Real amount() const
Definition: bond.hpp:67
void validate() const override
Definition: bond.cpp:399
void reset() override
Definition: bond.hpp:306
Base bond class.
Definition: bond.hpp:59
Calendar calendar_
Definition: bond.hpp:285
Real cleanPrice() const
theoretical clean price
Definition: bond.cpp:174
Leg redemptions_
Definition: bond.hpp:289
Real settlementValue_
Definition: bond.hpp:292
void setupArguments(PricingEngine::arguments *) const override
Definition: bond.cpp:285
const std::vector< Real > & notionals() const
Definition: bond.hpp:326
Rate previousCouponRate(Date d=Date()) const
Previous coupon already paid at a given date.
Definition: bond.cpp:268
Natural settlementDays() const
Definition: bond.hpp:318
bool isExpired() const override
returns whether the instrument might have value greater than zero.
Definition: bond.cpp:103
void addRedemptionsToCashflows(const std::vector< Real > &redemptions=std::vector< Real >())
Definition: bond.cpp:304
Rate yield(const DayCounter &dc, Compounding comp, Frequency freq, Real accuracy=1.0e-8, Size maxEvaluations=100, Real guess=0.05, Bond::Price::Type priceType=Bond::Price::Clean) const
theoretical bond yield
Definition: bond.cpp:198
virtual Real accruedAmount(Date d=Date()) const
accrued amount at a given date
Definition: bond.cpp:256
void deepUpdate() override
Definition: bond.cpp:356
const Calendar & calendar() const
Definition: bond.hpp:322
Date startDate() const
Definition: bond.cpp:146
const Leg & cashflows() const
Definition: bond.hpp:330
Date nextCashFlowDate(Date d=Date()) const
Definition: bond.cpp:272
Real settlementValue() const
theoretical settlement value
Definition: bond.cpp:186
std::vector< Real > notionals_
Definition: bond.hpp:287
Date issueDate() const
Definition: bond.hpp:338
Real dirtyPrice() const
theoretical dirty price
Definition: bond.cpp:178
Natural settlementDays_
Definition: bond.hpp:284
Leg cashflows_
Definition: bond.hpp:288
const ext::shared_ptr< CashFlow > & redemption() const
Definition: bond.cpp:140
void setSingleRedemption(Real notional, Real redemption, const Date &date)
Definition: bond.cpp:331
Date previousCashFlowDate(Date d=Date()) const
Definition: bond.cpp:276
Date issueDate_
Definition: bond.hpp:291
Date maturityDate() const
Definition: bond.cpp:150
bool isTradable(Date d=Date()) const
Definition: bond.cpp:157
const Leg & redemptions() const
Definition: bond.hpp:334
void setupExpired() const override
Definition: bond.cpp:280
void fetchResults(const PricingEngine::results *) const override
Definition: bond.cpp:294
std::vector< Date > notionalSchedule_
Definition: bond.hpp:286
Date maturityDate_
Definition: bond.hpp:291
void calculateNotionalsFromCashflows()
Definition: bond.cpp:363
virtual Real notional(Date d=Date()) const
Definition: bond.cpp:112
Date settlementDate(Date d=Date()) const
Definition: bond.cpp:161
virtual Rate nextCouponRate(Date d=Date()) const
Definition: bond.cpp:264
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
template base class for option pricing engines
Abstract instrument class.
Definition: instrument.hpp:44
template class providing a null value for a given type.
Definition: null.hpp:76
Frequency
Frequency of events.
Definition: frequency.hpp:37
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
Compounding
Interest rate coumpounding rule.
Definition: compounding.hpp:32
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78