QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
bondhelpers.cpp
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) 2008, 2009 Ferdinando Ametrano
5 Copyright (C) 2005 Toyin Akin
6 Copyright (C) 2007 StatPro Italia srl
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
24#include <ql/time/schedule.hpp>
25#include <ql/settings.hpp>
27
28namespace QuantLib {
29
31 const ext::shared_ptr<Bond>& bond,
32 const Bond::Price::Type priceType)
33 : RateHelper(price), bond_(ext::make_shared<Bond>(*bond)), priceType_(priceType) {
34
35 // the bond's last cashflow date, which can be later than
36 // bond's maturity date because of adjustment
37 latestDate_ = bond_->cashflows().back()->date();
38 earliestDate_ = bond_->nextCashFlowDate();
39
40 bond_->setPricingEngine(
41 ext::make_shared<DiscountingBondEngine>(termStructureHandle_));
42 }
43
45 // do not set the relinkable handle as an observer -
46 // force recalculation when needed
48 ext::shared_ptr<YieldTermStructure>(t, null_deleter()), false);
49
51 }
52
54 QL_REQUIRE(termStructure_ != nullptr, "term structure not set");
55 // we didn't register as observers - force calculation
56 bond_->recalculate();
57
58 switch (priceType_) {
60 return bond_->cleanPrice();
61 break;
62
64 return bond_->dirtyPrice();
65 break;
66
67 default:
68 QL_FAIL("This price type isn't implemented.");
69 }
70 }
71
73 auto* v1 = dynamic_cast<Visitor<BondHelper>*>(&v);
74 if (v1 != nullptr)
75 v1->visit(*this);
76 else
78 }
79
80
82
84 const Handle<Quote>& price,
85 Natural settlementDays,
86 Real faceAmount,
87 Schedule schedule,
88 const std::vector<Rate>& coupons,
89 const DayCounter& dayCounter,
90 BusinessDayConvention paymentConvention,
91 Real redemption,
92 const Date& issueDate,
93 const Calendar& paymentCalendar,
94 const Period& exCouponPeriod,
95 const Calendar& exCouponCalendar,
96 const BusinessDayConvention exCouponConvention,
97 bool exCouponEndOfMonth,
98 const Bond::Price::Type priceType)
99 : BondHelper(price,
100 ext::make_shared<FixedRateBond>(settlementDays, faceAmount, std::move(schedule),
101 coupons, dayCounter, paymentConvention,
102 redemption, issueDate, paymentCalendar,
103 exCouponPeriod, exCouponCalendar,
104 exCouponConvention, exCouponEndOfMonth),
105 priceType) {}
106
108
110 auto* v1 = dynamic_cast<Visitor<FixedRateBondHelper>*>(&v);
111 if (v1 != nullptr)
112 v1->visit(*this);
113 else
115 }
116
117
119
121 const Handle<Quote>& price,
122 Natural settlementDays,
123 Real faceAmount,
124 const bool growthOnly,
125 Real baseCPI,
126 const Period& observationLag,
127 const ext::shared_ptr<ZeroInflationIndex>& cpiIndex,
128 CPI::InterpolationType observationInterpolation,
129 Schedule schedule,
130 const std::vector<Rate>& fixedRate,
131 const DayCounter& accrualDayCounter,
132 BusinessDayConvention paymentConvention,
133 const Date& issueDate,
134 const Calendar& paymentCalendar,
135 const Period& exCouponPeriod,
136 const Calendar& exCouponCalendar,
137 const BusinessDayConvention exCouponConvention,
138 bool exCouponEndOfMonth,
139 const Bond::Price::Type priceType)
140 : BondHelper(price,
141 ext::make_shared<CPIBond>(settlementDays, faceAmount, growthOnly, baseCPI,
142 observationLag, cpiIndex, observationInterpolation,
143 std::move(schedule), fixedRate, accrualDayCounter, paymentConvention,
144 issueDate, paymentCalendar, exCouponPeriod, exCouponCalendar,
145 exCouponConvention, exCouponEndOfMonth),
146 priceType) {}
147
149
151 auto* v1 = dynamic_cast<Visitor<CPIBondHelper>*>(&v);
152 if (v1 != nullptr)
153 v1->visit(*this);
154 else
156 }
157
158}
bond rate helpers
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
Bond helper for curve bootstrap.
Definition: bondhelpers.hpp:40
Bond::Price::Type priceType_
Definition: bondhelpers.hpp:70
void setTermStructure(YieldTermStructure *) override
Definition: bondhelpers.cpp:44
RelinkableHandle< YieldTermStructure > termStructureHandle_
Definition: bondhelpers.hpp:69
void accept(AcyclicVisitor &) override
Definition: bondhelpers.cpp:72
Real impliedQuote() const override
Definition: bondhelpers.cpp:53
BondHelper(const Handle< Quote > &price, const ext::shared_ptr< Bond > &bond, Bond::Price::Type priceType=Bond::Price::Clean)
Definition: bondhelpers.cpp:30
ext::shared_ptr< Bond > bond_
Definition: bondhelpers.hpp:68
Base bond class.
Definition: bond.hpp:59
Base helper class for bootstrapping.
virtual void accept(AcyclicVisitor &)
virtual void setTermStructure(TS *)
sets the term structure to be used for pricing
void accept(AcyclicVisitor &) override
QL_DEPRECATED_ENABLE_WARNING CPIBondHelper(const Handle< Quote > &price, Natural settlementDays, Real faceAmount, bool growthOnly, Real baseCPI, const Period &observationLag, const ext::shared_ptr< ZeroInflationIndex > &cpiIndex, CPI::InterpolationType observationInterpolation, Schedule schedule, const std::vector< Rate > &fixedRate, const DayCounter &accrualDayCounter, BusinessDayConvention paymentConvention=Following, const Date &issueDate=Date(), const Calendar &paymentCalendar=Calendar(), const Period &exCouponPeriod=Period(), const Calendar &exCouponCalendar=Calendar(), BusinessDayConvention exCouponConvention=Unadjusted, bool exCouponEndOfMonth=false, Bond::Price::Type priceType=Bond::Price::Clean)
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
void accept(AcyclicVisitor &) override
QL_DEPRECATED_ENABLE_WARNING FixedRateBondHelper(const Handle< Quote > &price, Natural settlementDays, Real faceAmount, Schedule schedule, const std::vector< Rate > &coupons, const DayCounter &dayCounter, BusinessDayConvention paymentConv=Following, Real redemption=100.0, const Date &issueDate=Date(), const Calendar &paymentCalendar=Calendar(), const Period &exCouponPeriod=Period(), const Calendar &exCouponCalendar=Calendar(), BusinessDayConvention exCouponConvention=Unadjusted, bool exCouponEndOfMonth=false, Bond::Price::Type priceType=Bond::Price::Clean)
Definition: bondhelpers.cpp:83
Shared handle to an observable.
Definition: handle.hpp:41
Payment schedule.
Definition: schedule.hpp:40
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
Interest-rate term structure.
const DefaultType & t
discounting bond engine
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Definition: any.hpp:35
STL namespace.
empty deleter for shared_ptr
ext::shared_ptr< BlackVolTermStructure > v
#define QL_DEPRECATED_DISABLE_WARNING
Definition: qldefines.hpp:216
#define QL_DEPRECATED_ENABLE_WARNING
Definition: qldefines.hpp:217
date schedule
global repository for run-time library settings
InterpolationType
when you observe an index, how do you interpolate between fixings?