QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
inflationcoupon.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) 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
20/*! \file inflationcoupon.hpp
21 \brief Coupon paying a variable index-based rate
22 */
23
24#ifndef quantlib_inflation_coupon_hpp
25#define quantlib_inflation_coupon_hpp
26
30#include <ql/handle.hpp>
31
32namespace QuantLib {
33
34 class InflationIndex;
35 class YieldTermStructure;
36 class InflationCouponPricer;
37
38 //! Base inflation-coupon class
39 /*! The day counter is usually obtained from the inflation term
40 structure that the inflation index uses for forecasting.
41 There is no gearing or spread because these are relevant for
42 YoY coupons but not zero inflation coupons.
43
44 \note inflation indices do not contain day counters or calendars.
45 */
46 class InflationCoupon : public Coupon {
47 public:
48 InflationCoupon(const Date& paymentDate,
50 const Date& startDate,
51 const Date& endDate,
53 ext::shared_ptr<InflationIndex> index,
56 const Date& refPeriodStart = Date(),
57 const Date& refPeriodEnd = Date(),
58 const Date& exCouponDate = Date());
59
60 //! \name CashFlow interface
61 //@{
62 Real amount() const override { return rate() * accrualPeriod() * nominal(); }
63 //@}
64
65 //! \name Coupon interface
66 //@{
67 Real price(const Handle<YieldTermStructure>& discountingCurve) const;
68 DayCounter dayCounter() const override { return dayCounter_; }
69 Real accruedAmount(const Date&) const override;
70 Rate rate() const override;
71 //@}
72
73 //! \name Inspectors
74 //@{
75 //! yoy inflation index
76 const ext::shared_ptr<InflationIndex>& index() const { return index_; }
77 //! how the coupon observes the index
79 //! fixing days
80 Natural fixingDays() const { return fixingDays_; }
81 //! fixing date
82 virtual Date fixingDate() const;
83 //! fixing of the underlying index, as observed by the coupon
84 virtual Rate indexFixing() const;
85 //@}
86
87 //! \name LazyObject interface
88 //@{
89 void performCalculations() const override;
90 //@}
91
92 //! \name Visitability
93 //@{
94 void accept(AcyclicVisitor&) override;
95 //@}
96 void setPricer(const ext::shared_ptr<InflationCouponPricer>&);
97 ext::shared_ptr<InflationCouponPricer> pricer() const;
98
99 protected:
100 ext::shared_ptr<InflationCouponPricer> pricer_;
101 ext::shared_ptr<InflationIndex> index_;
105 mutable Real rate_;
106
107 //! makes sure you were given the correct type of pricer
108 // this can also done in external pricer setter classes via
109 // accept/visit mechanism
110 virtual bool checkPricerImpl(const
111 ext::shared_ptr<InflationCouponPricer>&) const = 0;
112 };
113
114 // inline definitions
115
116
118 auto* v1 = dynamic_cast<Visitor<InflationCoupon>*>(&v);
119 if (v1 != nullptr)
120 v1->visit(*this);
121 else
123 }
124
125 inline ext::shared_ptr<InflationCouponPricer>
127 return pricer_;
128 }
129
130}
131
132#endif
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
coupon accruing over a fixed period
Definition: coupon.hpp:39
void accept(AcyclicVisitor &) override
Definition: coupon.cpp:80
Date exCouponDate() const override
returns the date that the cash flow trades exCoupon
Definition: coupon.hpp:57
virtual Real nominal() const
Definition: coupon.hpp:100
Time accrualPeriod() const
accrual period as fraction of year
Definition: coupon.cpp:44
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Shared handle to an observable.
Definition: handle.hpp:41
Base inflation-coupon class.
virtual Date fixingDate() const
fixing date
void performCalculations() const override
Natural fixingDays() const
fixing days
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
void accept(AcyclicVisitor &) override
Period observationLag() const
how the coupon observes the index
DayCounter dayCounter() const override
day counter for accrual calculation
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 > &)
const ext::shared_ptr< InflationIndex > & index() const
yoy inflation index
Real price(const Handle< YieldTermStructure > &discountingCurve) const
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
Coupon accruing over a fixed period.
day counter class
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
Globally accessible relinkable pointer.
Definition: any.hpp:35
ext::shared_ptr< BlackVolTermStructure > v
degenerate base class for the Acyclic Visitor pattern