QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
capflooredcoupon.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) 2006, 2007 Cristina Duminuco
5 Copyright (C) 2006, 2009 StatPro Italia srl
6 Copyright (C) 2007 Giorgio Facchinetti
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
25namespace QuantLib {
26
27 CappedFlooredCoupon::CappedFlooredCoupon(const ext::shared_ptr<FloatingRateCoupon>& underlying,
28 Rate cap,
29 Rate floor)
30 : FloatingRateCoupon(underlying->date(),
31 underlying->nominal(),
32 underlying->accrualStartDate(),
33 underlying->accrualEndDate(),
34 underlying->fixingDays(),
35 underlying->index(),
36 underlying->gearing(),
37 underlying->spread(),
38 underlying->referencePeriodStart(),
39 underlying->referencePeriodEnd(),
40 underlying->dayCounter(),
41 underlying->isInArrears(),
42 underlying->exCouponDate()),
43 underlying_(underlying) {
44
45 if (gearing_ > 0) {
46 if (cap != Null<Rate>()) {
47 isCapped_ = true;
48 cap_ = cap;
49 }
50 if (floor != Null<Rate>()) {
51 floor_ = floor;
52 isFloored_ = true;
53 }
54 } else {
55 if (cap != Null<Rate>()){
56 floor_ = cap;
57 isFloored_ = true;
58 }
59 if (floor != Null<Rate>()){
60 isCapped_ = true;
61 cap_ = floor;
62 }
63 }
64
65 if (isCapped_ && isFloored_) {
67 "cap level (" << cap <<
68 ") less than floor level (" << floor << ")");
69 }
70
72 }
73
75 const ext::shared_ptr<FloatingRateCouponPricer>& pricer) {
77 underlying_->setPricer(pricer);
78 }
79
81 update();
82 underlying_->deepUpdate();
83 }
84
86 QL_REQUIRE(underlying_->pricer(), "pricer not set");
87 Rate swapletRate = underlying_->rate();
88 Rate floorletRate = 0.;
89 if(isFloored_)
90 floorletRate = underlying_->pricer()->floorletRate(effectiveFloor());
91 Rate capletRate = 0.;
92 if(isCapped_)
93 capletRate = underlying_->pricer()->capletRate(effectiveCap());
94 rate_ = swapletRate + floorletRate - capletRate;
95 }
96
98 calculate();
99 return rate_;
100 }
101
103 return underlying_->convexityAdjustment();
104 }
105
107 if ( (gearing_ > 0) && isCapped_)
108 return cap_;
109 if ( (gearing_ < 0) && isFloored_)
110 return floor_;
111 return Null<Rate>();
112 }
113
115 if ( (gearing_ > 0) && isFloored_)
116 return floor_;
117 if ( (gearing_ < 0) && isCapped_)
118 return cap_;
119 return Null<Rate>();
120 }
121
123 if (isCapped_)
124 return (cap_ - spread())/gearing();
125 else
126 return Null<Rate>();
127 }
128
130 if (isFloored_)
131 return (floor_ - spread())/gearing();
132 else
133 return Null<Rate>();
134 }
135
137 typedef FloatingRateCoupon super;
138 auto* v1 = dynamic_cast<Visitor<CappedFlooredCoupon>*>(&v);
139 if (v1 != nullptr)
140 v1->visit(*this);
141 else
142 super::accept(v);
143 }
144
145}
Floating rate coupon with additional cap/floor.
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
void performCalculations() const override
ext::shared_ptr< FloatingRateCoupon > underlying_
Rate rate() const override
accrued rate
void accept(AcyclicVisitor &) override
CappedFlooredCoupon(const ext::shared_ptr< FloatingRateCoupon > &underlying, Rate cap=Null< Rate >(), Rate floor=Null< Rate >())
void setPricer(const ext::shared_ptr< FloatingRateCouponPricer > &pricer) override
Rate effectiveCap() const
effective cap of fixing
Rate effectiveFloor() const
effective floor of fixing
Rate convexityAdjustment() const override
convexity adjustment
base floating-rate coupon class
virtual void setPricer(const ext::shared_ptr< FloatingRateCouponPricer > &)
Real gearing() const
index gearing, i.e. multiplicative coefficient for the index
ext::shared_ptr< FloatingRateCouponPricer > pricer() const
Spread spread() const
spread paid over the fixing of the underlying index
virtual void calculate() const
Definition: lazyobject.hpp:253
void update() override
Definition: lazyobject.hpp:188
template class providing a null value for a given type.
Definition: null.hpp:76
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
Coupon pricers.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
ext::shared_ptr< BlackVolTermStructure > v