QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
strippedcapflooredcoupon.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) 2014 Peter Caspers
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
22#include <utility>
23
24namespace QuantLib {
25
27 const ext::shared_ptr<CappedFlooredCoupon> &underlying)
29 underlying->date(), underlying->nominal(),
30 underlying->accrualStartDate(), underlying->accrualEndDate(),
31 underlying->fixingDays(), underlying->index(),
32 underlying->gearing(), underlying->spread(),
33 underlying->referencePeriodStart(),
34 underlying->referencePeriodEnd(), underlying->dayCounter(),
35 underlying->isInArrears()),
36 underlying_(underlying) {
38 }
39
41 update();
42 underlying_->deepUpdate();
43 }
44
46 QL_REQUIRE(underlying_->underlying()->pricer() != nullptr, "pricer not set");
47 underlying_->underlying()->pricer()->initialize(*underlying_->underlying());
48 Rate floorletRate = 0.0;
49 if (underlying_->isFloored())
50 floorletRate = underlying_->underlying()->pricer()->floorletRate(
51 underlying_->effectiveFloor());
52 Rate capletRate = 0.0;
53 if (underlying_->isCapped())
54 capletRate =
55 underlying_->underlying()->pricer()->capletRate(underlying_->effectiveCap());
56
57 // if the underlying is collared we return the value of the embedded
58 // collar, otherwise the value of a long floor or a long cap respectively
59
60 rate_ = (underlying_->isFloored() && underlying_->isCapped()) ?
61 Real(floorletRate - capletRate) :
62 Real(floorletRate + capletRate);
63 }
64
66 calculate();
67 return rate_;
68 }
69
71 return underlying_->convexityAdjustment();
72 }
73
75
77 return underlying_->floor();
78 }
79
81 return underlying_->effectiveCap();
82 }
83
85 return underlying_->effectiveFloor();
86 }
87
89 underlying_->accept(v);
90 auto* v1 = dynamic_cast<Visitor<StrippedCappedFlooredCoupon>*>(&v);
91 if (v1 != nullptr)
92 v1->visit(*this);
93 else
95 }
96
98 return underlying_->isCapped();
99 }
100
102 return underlying_->isFloored();
103 }
104
106 return isCap() && isFloor();
107 }
108
110 const ext::shared_ptr<FloatingRateCouponPricer> &pricer) {
112 underlying_->setPricer(pricer);
113 }
114
116 : underlyingLeg_(std::move(underlyingLeg)) {}
117
118 StrippedCappedFlooredCouponLeg::operator Leg() const {
119 Leg resultLeg;
120 resultLeg.reserve(underlyingLeg_.size());
121 ext::shared_ptr<CappedFlooredCoupon> c;
122 for (const auto& i : underlyingLeg_) {
123 if ((c = ext::dynamic_pointer_cast<CappedFlooredCoupon>(i)) != nullptr) {
124 resultLeg.push_back(
125 ext::make_shared<StrippedCappedFlooredCoupon>(c));
126 } else {
127 resultLeg.push_back(i);
128 }
129 }
130 return resultLeg;
131 }
132}
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
base floating-rate coupon class
virtual void setPricer(const ext::shared_ptr< FloatingRateCouponPricer > &)
void accept(AcyclicVisitor &) override
ext::shared_ptr< FloatingRateCouponPricer > pricer() const
virtual void calculate() const
Definition: lazyobject.hpp:253
void update() override
Definition: lazyobject.hpp:188
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
StrippedCappedFlooredCoupon(const ext::shared_ptr< CappedFlooredCoupon > &underlying)
Rate rate() const override
Coupon interface.
void accept(AcyclicVisitor &) override
Visitability.
void setPricer(const ext::shared_ptr< FloatingRateCouponPricer > &pricer) override
ext::shared_ptr< CappedFlooredCoupon > underlying_
Rate convexityAdjustment() const override
convexity adjustment
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
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78
STL namespace.
ext::shared_ptr< BlackVolTermStructure > v
strips the embedded option from cap floored coupons