Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
strippedcapflooredcpicoupon.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 <iostream>
20#include <ql/cashflows/cpicouponpricer.hpp>
21#include <ql/cashflows/inflationcoupon.hpp>
22#include <ql/cashflows/inflationcouponpricer.hpp>
24
25namespace QuantExt {
26using namespace QuantLib;
27
29 const ext::shared_ptr<CappedFlooredCPICashFlow>& underlying)
30 : CPICashFlow(underlying->notional(), underlying->cpiIndex(), underlying->baseDate(), underlying->baseFixing(),
31 underlying->observationDate(), underlying->observationLag(),
32 underlying->interpolation(), underlying->date(), underlying->growthOnly()),
33 underlying_(underlying) {
34 registerWith(underlying_);
35}
36
38 return underlying_->amount() - underlying_->underlying()->amount();
39}
40
42 const ext::shared_ptr<CappedFlooredCPICoupon>& underlying)
43 : CPICoupon(underlying->baseCPI(), underlying->date(), underlying->nominal(), underlying->accrualStartDate(),
44 underlying->accrualEndDate(), underlying->cpiIndex(),
45 underlying->observationLag(), underlying->observationInterpolation(), underlying->dayCounter(),
46 underlying->fixedRate(), underlying->referencePeriodStart(),
47 underlying->referencePeriodEnd(), underlying->exCouponDate()),
48 underlying_(underlying) {
49 registerWith(underlying_);
50}
51
52Rate StrippedCappedFlooredCPICoupon::rate() const { return underlying_->rate() - underlying_->underlying()->rate(); }
53
55 QL_FAIL("not implemented");
56 return 0.0;
57}
58
60 QL_FAIL("not implemented");
61 return 0.0;
62}
63
65 QL_FAIL("not implemented");
66 return 0.0;
67}
68
70 QL_FAIL("not implemented");
71 return 0.0;
72}
73
74void StrippedCappedFlooredCPICoupon::update() { notifyObservers(); }
75
77 underlying_->accept(v);
78 Visitor<StrippedCappedFlooredCPICoupon>* v1 = dynamic_cast<Visitor<StrippedCappedFlooredCPICoupon>*>(&v);
79 if (v1 != NULL)
80 v1->visit(*this);
81 else
82 CPICoupon::accept(v);
83}
84
85bool StrippedCappedFlooredCPICoupon::isCap() const { return underlying_->isCapped(); }
86
87bool StrippedCappedFlooredCPICoupon::isFloor() const { return underlying_->isFloored(); }
88
90
92 : underlyingLeg_(underlyingLeg) {}
93
94StrippedCappedFlooredCPICouponLeg::operator Leg() const {
95 Leg resultLeg;
96 resultLeg.reserve(underlyingLeg_.size());
97 ext::shared_ptr<CappedFlooredCPICoupon> c;
98 ext::shared_ptr<CappedFlooredCPICashFlow> f;
99 for (Leg::const_iterator i = underlyingLeg_.begin(); i != underlyingLeg_.end(); ++i) {
100 if ((c = ext::dynamic_pointer_cast<CappedFlooredCPICoupon>(*i)) != NULL) {
101 resultLeg.push_back(ext::make_shared<StrippedCappedFlooredCPICoupon>(c));
102 } else if ((f = ext::dynamic_pointer_cast<CappedFlooredCPICashFlow>(*i)) != NULL) {
103 resultLeg.push_back(ext::make_shared<StrippedCappedFlooredCPICashFlow>(f));
104 }
105 // we don't want the following, just strip caps/floors and ignore the rest
106 // else {
107 // resultLeg.push_back(*i);
108 // }
109 }
110 return resultLeg;
111}
112} // namespace QuantExt
Real amount() const override
Cashflow interface.
StrippedCappedFlooredCPICashFlow(const ext::shared_ptr< CappedFlooredCPICashFlow > &underlying)
ext::shared_ptr< CappedFlooredCPICashFlow > underlying_
StrippedCappedFlooredCPICoupon(const ext::shared_ptr< CappedFlooredCPICoupon > &underlying)
Rate rate() const override
Coupon interface.
virtual void accept(AcyclicVisitor &) override
Visitability.
ext::shared_ptr< CappedFlooredCPICoupon > underlying_
strips the embedded option from cap floored cpi coupons