QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
inflationcoupon.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) 2009 Chris Kenyon
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
24#include <utility>
25
26namespace QuantLib {
27
29 Real nominal,
30 const Date& startDate,
31 const Date& endDate,
32 Natural fixingDays,
33 ext::shared_ptr<InflationIndex> index,
34 const Period& observationLag,
35 DayCounter dayCounter,
36 const Date& refPeriodStart,
37 const Date& refPeriodEnd,
38 const Date& exCouponDate)
39 : Coupon(paymentDate,
40 nominal,
41 startDate,
42 endDate,
43 refPeriodStart,
44 refPeriodEnd,
45 exCouponDate), // ref period is before lag
46 index_(std::move(index)), observationLag_(observationLag), dayCounter_(std::move(dayCounter)),
47 fixingDays_(fixingDays) {
49 registerWith(Settings::instance().evaluationDate());
50 }
51
52
53 void InflationCoupon::setPricer(const ext::shared_ptr<InflationCouponPricer>& pricer) {
54 QL_REQUIRE(checkPricerImpl(pricer),"pricer given is wrong type");
55 if (pricer_ != nullptr)
58 if (pricer_ != nullptr)
60 update();
61 }
62
63
65 calculate();
66 return rate_;
67 }
68
70 QL_REQUIRE(pricer_, "pricer not set");
71 // we know it is the correct type because checkPricerImpl checks on setting
72 // in general pricer_ will be a derived class, as will *this on calling
73 pricer_->initialize(*this);
74 rate_ = pricer_->swapletRate();
75 }
76
77
79 if (d <= accrualStartDate_ || d > paymentDate_) {
80 return 0.0;
81 } else {
82 return nominal() * rate() * accruedPeriod(d);
83 }
84 }
85
86
88
89 // fixing calendar is usually the null calendar for inflation indices
90 return index_->fixingCalendar().advance(refPeriodEnd_-observationLag_,
91 -static_cast<Integer>(fixingDays_), Days, ModifiedPreceding);
92 }
93
94
96 return amount() * discountingCurve->discount(date());
97 }
98
99
101 return index_->fixing(fixingDate());
102 }
103
104}
coupon accruing over a fixed period
Definition: coupon.hpp:39
Date paymentDate_
Definition: coupon.hpp:90
Date refPeriodEnd_
Definition: coupon.hpp:92
virtual Real nominal() const
Definition: coupon.hpp:100
Date date() const override
Definition: coupon.hpp:53
Time accruedPeriod(const Date &) const
accrued period as fraction of year at the given date
Definition: coupon.cpp:57
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Shared handle to an observable.
Definition: handle.hpp:41
virtual Date fixingDate() const
fixing date
void performCalculations() const override
ext::shared_ptr< InflationCouponPricer > pricer_
ext::shared_ptr< InflationIndex > index_
Rate rate() const override
accrued rate
Real amount() const override
returns the amount of the cash flow
ext::shared_ptr< InflationCouponPricer > pricer() const
InflationCoupon(const Date &paymentDate, Real nominal, const Date &startDate, const Date &endDate, Natural fixingDays, ext::shared_ptr< InflationIndex > index, const Period &observationLag, DayCounter dayCounter, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date(), const Date &exCouponDate=Date())
virtual bool checkPricerImpl(const ext::shared_ptr< InflationCouponPricer > &) const =0
makes sure you were given the correct type of pricer
Real accruedAmount(const Date &) const override
accrued amount at the given date
virtual Rate indexFixing() const
fixing of the underlying index, as observed by the coupon
void setPricer(const ext::shared_ptr< InflationCouponPricer > &)
Real price(const Handle< YieldTermStructure > &discountingCurve) const
virtual void calculate() const
Definition: lazyobject.hpp:253
void update() override
Definition: lazyobject.hpp:188
Size unregisterWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:245
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Date d
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
QL_INTEGER Integer
integer number
Definition: types.hpp:35
Real Rate
interest rates
Definition: types.hpp:70
inflation-coupon pricers
base classes for inflation indexes
Definition: any.hpp:35
STL namespace.
Interest-rate term structure.
Coupon paying a yoy inflation index.