QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
inflationcoupon.hpp
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#ifndef quantlib_inflation_coupon_hpp
25#define quantlib_inflation_coupon_hpp
26
27#include <ql/cashflows/coupon.hpp>
28#include <ql/patterns/visitor.hpp>
29#include <ql/time/daycounter.hpp>
30#include <ql/handle.hpp>
31
32namespace QuantLib {
33
34 class InflationIndex;
35 class YieldTermStructure;
36 class InflationCouponPricer;
37
39
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
61
62 Real amount() const override { return rate() * accrualPeriod() * nominal(); }
64
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;
72
74
75
76 const ext::shared_ptr<InflationIndex>& index() const { return index_; }
80 Natural fixingDays() const { return fixingDays_; }
82 virtual Date fixingDate() const;
84 virtual Rate indexFixing() const;
86
88
89 void performCalculations() const override;
91
93
94 void accept(AcyclicVisitor&) override;
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
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
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
Definition: any.hpp:35