Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
strippedcapflooredyoyinflationcoupon.cpp
Go to the documentation of this file.
1/*
2Copyright (C) 2019 Quaternion Risk Management Ltd
3All rights reserved.
4
5This file is part of ORE, a free-software/open-source library
6for transparent pricing and risk analysis - http://opensourcerisk.org
7
8ORE is free software: you can redistribute it and/or modify it
9under the terms of the Modified BSD License. You should have received a
10copy of the license along with this program.
11The license is also available online at <http://opensourcerisk.org>
12
13This program is distributed on the basis that it will form a useful
14contribution to risk analytics and model standardisation, but WITHOUT
15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19#include <ql/cashflows/inflationcoupon.hpp>
20#include <ql/cashflows/inflationcouponpricer.hpp>
22
23namespace QuantExt {
24using namespace QuantLib;
25
27 const ext::shared_ptr<CappedFlooredYoYInflationCoupon>& underlying)
28 : YoYInflationCoupon(underlying->date(), underlying->nominal(), underlying->accrualStartDate(),
29 underlying->accrualEndDate(), underlying->fixingDays(), underlying->yoyIndex(),
30 underlying->observationLag(), underlying->dayCounter(), underlying->gearing(),
31 underlying->spread(), underlying->referencePeriodStart(), underlying->referencePeriodEnd()),
32 underlying_(underlying) {
33 registerWith(underlying);
34}
35
37
38 QL_REQUIRE(underlying_->pricer() != NULL, "pricer not set");
39 underlying_->pricer()->initialize(*underlying_);
40 Rate floorletRate = 0.0;
41 if (underlying_->isFloored())
42 floorletRate = underlying_->pricer()->floorletRate(underlying_->effectiveFloor());
43 Rate capletRate = 0.0;
44 if (underlying_->isCapped())
45 capletRate = underlying_->pricer()->capletRate(underlying_->effectiveCap());
46
47 // if the underlying is collared we return the value of the embedded
48 // collar, otherwise the value of a long floor or a long cap respectively
49
50 return (underlying_->isFloored() && underlying_->isCapped()) ? floorletRate - capletRate
51 : floorletRate + capletRate;
52}
53
55
57
59
61
63
65 underlying_->accept(v);
66 Visitor<StrippedCappedFlooredYoYInflationCoupon>* v1 =
67 dynamic_cast<Visitor<StrippedCappedFlooredYoYInflationCoupon>*>(&v);
68 if (v1 != NULL)
69 v1->visit(*this);
70 else
72}
73
75
77
79
80void StrippedCappedFlooredYoYInflationCoupon::setPricer(const ext::shared_ptr<YoYInflationCouponPricer>& pricer) {
81 YoYInflationCoupon::setPricer(pricer);
82 underlying_->setPricer(pricer);
83}
84
86 : underlyingLeg_(underlyingLeg) {}
87
88StrippedCappedFlooredYoYInflationCouponLeg::operator Leg() const {
89 Leg resultLeg;
90 resultLeg.reserve(underlyingLeg_.size());
91 ext::shared_ptr<CappedFlooredYoYInflationCoupon> c;
92 for (Leg::const_iterator i = underlyingLeg_.begin(); i != underlyingLeg_.end(); ++i) {
93 if ((c = ext::dynamic_pointer_cast<CappedFlooredYoYInflationCoupon>(*i)) != NULL) {
94 resultLeg.push_back(ext::make_shared<StrippedCappedFlooredYoYInflationCoupon>(c));
95 } else {
96 resultLeg.push_back(*i);
97 }
98 }
99 return resultLeg;
100}
101} // namespace QuantExt
virtual void accept(AcyclicVisitor &) override
Visitability.
void setPricer(const ext::shared_ptr< YoYInflationCouponPricer > &pricer)
StrippedCappedFlooredYoYInflationCoupon(const ext::shared_ptr< CappedFlooredYoYInflationCoupon > &underlying)
ext::shared_ptr< CappedFlooredYoYInflationCoupon > underlying_
const ext::shared_ptr< CappedFlooredYoYInflationCoupon > underlying()
virtual void accept(AcyclicVisitor &) override
strips the embedded option from cap floored yoy inflation coupons