QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
floatingratecoupon.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
5 Copyright (C) 2003, 2004 StatPro Italia srl
6 Copyright (C) 2003 Nicolas Di Césaré
7 Copyright (C) 2006, 2007 Cristina Duminuco
8 Copyright (C) 2006 Ferdinando Ametrano
9 Copyright (C) 2007 Giorgio Facchinetti
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_floating_rate_coupon_hpp
30#define quantlib_floating_rate_coupon_hpp
31
32#include <ql/cashflows/coupon.hpp>
33#include <ql/patterns/visitor.hpp>
34#include <ql/patterns/lazyobject.hpp>
35#include <ql/time/daycounter.hpp>
36#include <ql/handle.hpp>
37
38namespace QuantLib {
39
40 class InterestRateIndex;
41 class YieldTermStructure;
42 class FloatingRateCouponPricer;
43
45 class FloatingRateCoupon : public Coupon {
46 public:
47 FloatingRateCoupon(const Date& paymentDate,
49 const Date& startDate,
50 const Date& endDate,
52 const ext::shared_ptr<InterestRateIndex>& index,
53 Real gearing = 1.0,
54 Spread spread = 0.0,
55 const Date& refPeriodStart = Date(),
56 const Date& refPeriodEnd = Date(),
58 bool isInArrears = false,
59 const Date& exCouponDate = Date());
60
62
63 void performCalculations() const override;
65
67 Real amount() const override { return rate() * accrualPeriod() * nominal(); }
69
71
72 Rate rate() const override;
73 Real price(const Handle<YieldTermStructure>& discountingCurve) const;
74 DayCounter dayCounter() const override { return dayCounter_; }
75 Real accruedAmount(const Date&) const override;
77
79
80
81 const ext::shared_ptr<InterestRateIndex>& index() const;
83 Natural fixingDays() const { return fixingDays_; }
85 virtual Date fixingDate() const;
87 Real gearing() const { return gearing_; }
89 Spread spread() const { return spread_; }
91 virtual Rate indexFixing() const;
93 virtual Rate convexityAdjustment() const;
95 virtual Rate adjustedFixing() const;
97 bool isInArrears() const { return isInArrears_; }
99
101
102 void accept(AcyclicVisitor&) override;
104
105 virtual void setPricer(const ext::shared_ptr<FloatingRateCouponPricer>&);
106 ext::shared_ptr<FloatingRateCouponPricer> pricer() const;
107 protected:
109 Rate convexityAdjustmentImpl(Rate fixing) const;
110 ext::shared_ptr<InterestRateIndex> index_;
116 ext::shared_ptr<FloatingRateCouponPricer> pricer_;
117 mutable Real rate_;
118 };
119
120 // inline definitions
121
122 inline const ext::shared_ptr<InterestRateIndex>&
124 return index_;
125 }
126
129 }
130
132 return (rate()-spread())/gearing();
133 }
134
135 inline ext::shared_ptr<FloatingRateCouponPricer>
137 return pricer_;
138 }
139
140 inline Rate
142 return (gearing() == 0.0 ? Rate(0.0) : Rate(adjustedFixing()-fixing));
143 }
144
146 auto* v1 = dynamic_cast<Visitor<FloatingRateCoupon>*>(&v);
147 if (v1 != nullptr)
148 v1->visit(*this);
149 else
151 }
152
153}
154
155#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
base floating-rate coupon class
virtual Date fixingDate() const
fixing date
void performCalculations() const override
Natural fixingDays() const
fixing days
ext::shared_ptr< InterestRateIndex > index_
virtual void setPricer(const ext::shared_ptr< FloatingRateCouponPricer > &)
Rate rate() const override
accrued rate
Real amount() const override
returns the amount of the cash flow
ext::shared_ptr< FloatingRateCouponPricer > pricer_
void accept(AcyclicVisitor &) override
Real gearing() const
index gearing, i.e. multiplicative coefficient for the index
Rate convexityAdjustmentImpl(Rate fixing) const
convexity adjustment for the given index fixing
virtual Rate adjustedFixing() const
convexity-adjusted fixing
DayCounter dayCounter() const override
day counter for accrual calculation
virtual Rate convexityAdjustment() const
convexity adjustment
Real accruedAmount(const Date &) const override
accrued amount at the given date
virtual Rate indexFixing() const
fixing of the underlying index
const ext::shared_ptr< InterestRateIndex > & index() const
floating index
ext::shared_ptr< FloatingRateCouponPricer > pricer() const
Real price(const Handle< YieldTermStructure > &discountingCurve) const
Spread spread() const
spread paid over the fixing of the underlying index
bool isInArrears() const
whether or not the coupon fixes in arrears
Shared handle to an observable.
Definition: handle.hpp:41
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 Spread
spreads on interest rates
Definition: types.hpp:74
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35