QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
cmsspreadcoupon.cpp
1/*
2 Copyright (C) 2014 Peter Caspers
3
4 This file is part of QuantLib, a free-software/open-source library
5 for financial quantitative analysts and developers - http://quantlib.org/
6
7 QuantLib is free software: you can redistribute it and/or modify it
8 under the terms of the QuantLib license. You should have received a
9 copy of the license along with this program; if not, please email
10 <quantlib-dev@lists.sf.net>. The license is also available online at
11 <http://quantlib.org/license.shtml>.
12
13
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19#include <ql/cashflows/capflooredcoupon.hpp>
20#include <ql/cashflows/cashflowvectors.hpp>
21#include <ql/experimental/coupons/cmsspreadcoupon.hpp>
22#include <utility>
23
24namespace QuantLib {
25
27 const Date &paymentDate, Real nominal, const Date &startDate,
28 const Date &endDate, Natural fixingDays,
29 const ext::shared_ptr<SwapSpreadIndex> &index, Real gearing,
30 Spread spread, const Date &refPeriodStart,
31 const Date &refPeriodEnd,
32 const DayCounter &dayCounter, bool isInArrears, const Date &exCouponDate)
33 : FloatingRateCoupon(paymentDate, nominal, startDate, endDate,
34 fixingDays, index, gearing, spread,
35 refPeriodStart, refPeriodEnd, dayCounter,
36 isInArrears, exCouponDate),
37 index_(index) {}
38
40 auto* v1 = dynamic_cast<Visitor<CmsSpreadCoupon>*>(&v);
41 if (v1 != nullptr)
42 v1->visit(*this);
43 else
45 }
46
47 CmsSpreadLeg::CmsSpreadLeg(Schedule schedule, ext::shared_ptr<SwapSpreadIndex> index)
48 : schedule_(std::move(schedule)), swapSpreadIndex_(std::move(index)) {
49 QL_REQUIRE(swapSpreadIndex_, "no index provided");
50 }
51
53 notionals_ = std::vector<Real>(1, notional);
54 return *this;
55 }
56
58 CmsSpreadLeg::withNotionals(const std::vector<Real> &notionals) {
59 notionals_ = notionals;
60 return *this;
61 }
62
65 paymentDayCounter_ = dayCounter;
66 return *this;
67 }
68
71 paymentAdjustment_ = convention;
72 return *this;
73 }
74
76 fixingDays_ = std::vector<Natural>(1, fixingDays);
77 return *this;
78 }
79
81 CmsSpreadLeg::withFixingDays(const std::vector<Natural> &fixingDays) {
82 fixingDays_ = fixingDays;
83 return *this;
84 }
85
87 gearings_ = std::vector<Real>(1, gearing);
88 return *this;
89 }
90
92 CmsSpreadLeg::withGearings(const std::vector<Real> &gearings) {
93 gearings_ = gearings;
94 return *this;
95 }
96
98 spreads_ = std::vector<Spread>(1, spread);
99 return *this;
100 }
101
103 CmsSpreadLeg::withSpreads(const std::vector<Spread> &spreads) {
104 spreads_ = spreads;
105 return *this;
106 }
107
109 caps_ = std::vector<Rate>(1, cap);
110 return *this;
111 }
112
113 CmsSpreadLeg &CmsSpreadLeg::withCaps(const std::vector<Rate> &caps) {
114 caps_ = caps;
115 return *this;
116 }
117
119 floors_ = std::vector<Rate>(1, floor);
120 return *this;
121 }
122
123 CmsSpreadLeg &CmsSpreadLeg::withFloors(const std::vector<Rate> &floors) {
124 floors_ = floors;
125 return *this;
126 }
127
129 inArrears_ = flag;
130 return *this;
131 }
132
134 zeroPayments_ = flag;
135 return *this;
136 }
137
138 CmsSpreadLeg::operator Leg() const {
141 schedule_, notionals_, swapSpreadIndex_, paymentDayCounter_,
142 paymentAdjustment_, fixingDays_, gearings_, spreads_, caps_,
143 floors_, inArrears_, zeroPayments_);
144 }
145}
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
CMS spread coupon class.
CmsSpreadCoupon(const Date &paymentDate, Real nominal, const Date &startDate, const Date &endDate, Natural fixingDays, const ext::shared_ptr< SwapSpreadIndex > &index, Real gearing=1.0, Spread spread=0.0, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date(), const DayCounter &dayCounter=DayCounter(), bool isInArrears=false, const Date &exCouponDate=Date())
void accept(AcyclicVisitor &) override
helper class building a sequence of capped/floored cms-spread-rate coupons
CmsSpreadLeg & withPaymentAdjustment(BusinessDayConvention)
BusinessDayConvention paymentAdjustment_
std::vector< Rate > caps_
CmsSpreadLeg & withSpreads(Spread spread)
ext::shared_ptr< SwapSpreadIndex > swapSpreadIndex_
CmsSpreadLeg & withFloors(Rate floor)
CmsSpreadLeg(Schedule schedule, ext::shared_ptr< SwapSpreadIndex > swapSpreadIndex)
CmsSpreadLeg & withGearings(Real gearing)
CmsSpreadLeg & withCaps(Rate cap)
std::vector< Real > notionals_
CmsSpreadLeg & inArrears(bool flag=true)
std::vector< Spread > spreads_
CmsSpreadLeg & withFixingDays(Natural fixingDays)
CmsSpreadLeg & withPaymentDayCounter(const DayCounter &)
std::vector< Natural > fixingDays_
CmsSpreadLeg & withZeroPayments(bool flag=true)
std::vector< Rate > floors_
std::vector< Real > gearings_
CmsSpreadLeg & withNotionals(Real notional)
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
base floating-rate coupon class
void accept(AcyclicVisitor &) override
Payment schedule.
Definition: schedule.hpp:40
class for swap-rate spread indexes
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
BusinessDayConvention
Business Day conventions.
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
Leg FloatingLeg(const Schedule &schedule, const std::vector< Real > &nominals, const ext::shared_ptr< InterestRateIndexType > &index, const DayCounter &paymentDayCounter, BusinessDayConvention paymentAdj, const std::vector< Natural > &fixingDays, const std::vector< Real > &gearings, const std::vector< Spread > &spreads, const std::vector< Rate > &caps, const std::vector< Rate > &floors, bool isInArrears, bool isZero, Natural paymentLag=0, Calendar paymentCalendar=Calendar(), Period exCouponPeriod=Period(), Calendar exCouponCalendar=Calendar(), BusinessDayConvention exCouponAdjustment=Unadjusted, bool exCouponEndOfMonth=false)
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78
STL namespace.