QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
makeyoyinflationcapfloor.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 Ferdinando Ametrano
5 Copyright (C) 2007 StatPro Italia srl
6 Copyright (C) 2009 Chris Kenyon
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
25#include <utility>
26
27namespace QuantLib {
28
30 ext::shared_ptr<YoYInflationIndex> index,
31 const Size& length,
32 Calendar cal,
33 const Period& observationLag,
34 CPI::InterpolationType interpolation)
35 : capFloorType_(capFloorType), length_(length), calendar_(std::move(cal)),
36 index_(std::move(index)), observationLag_(observationLag),
37 interpolation_(interpolation), strike_(Null<Rate>()),
38
39 dayCounter_(Thirty360(Thirty360::BondBasis)) {}
40
42 ext::shared_ptr<YoYInflationIndex> index,
43 const Size& length,
44 Calendar cal,
45 const Period& observationLag)
46 : MakeYoYInflationCapFloor(capFloorType, std::move(index), length, std::move(cal), observationLag, CPI::AsIndex) {}
47
48 MakeYoYInflationCapFloor::operator YoYInflationCapFloor() const {
49 ext::shared_ptr<YoYInflationCapFloor> capfloor = *this;
50 return *capfloor;
51 }
52
53 MakeYoYInflationCapFloor::operator ext::shared_ptr<YoYInflationCapFloor>() const {
54
55 Date startDate;
56 if (effectiveDate_ != Date()) {
57 startDate = effectiveDate_;
58 } else {
59 Date referenceDate = Settings::instance().evaluationDate();
60 Date spotDate = calendar_.advance(referenceDate,
61 fixingDays_*Days);
62 startDate = spotDate+forwardStart_;
63 }
64
65 Date endDate = calendar_.advance(startDate,length_*Years,Unadjusted);
66 Schedule schedule(startDate, endDate, Period(Annual), calendar_,
67 Unadjusted, Unadjusted, // ref periods & acc periods
69 Leg leg = yoyInflationLeg(schedule, calendar_, index_,
70 observationLag_, interpolation_)
72 .withPaymentDayCounter(dayCounter_)
73 .withNotionals(nominal_)
74 ;
75
76 if (firstCapletExcluded_)
77 leg.erase(leg.begin());
78
79 // only leaves the last coupon
80 if (asOptionlet_ && leg.size() > 1) {
81 auto end = leg.end(); // Sun Studio needs an lvalue
82 leg.erase(leg.begin(), --end);
83 }
84
85 std::vector<Rate> strikeVector(1, strike_);
86 if (strike_ == Null<Rate>()) {
87 // ATM on the forecasting curve
88 strikeVector[0] = CashFlows::atmRate(leg, **nominalTermStructure_,
89 false, nominalTermStructure_->referenceDate());
90 }
91
92 ext::shared_ptr<YoYInflationCapFloor> capFloor(new
93 YoYInflationCapFloor(capFloorType_, leg, strikeVector));
94 capFloor->setPricingEngine(engine_);
95 return capFloor;
96 }
97
99 nominal_ = n;
100 return *this;
101 }
102
104 const Date& effectiveDate) {
105 effectiveDate_ = effectiveDate;
106 return *this;
107 }
108
111 roll_ = bdc;
112 return *this;
113 }
114
117 dayCounter_ = dc;
118 return *this;
119 }
120
123 fixingDays_ = n;
124 return *this;
125 }
126
128 asOptionlet_ = b;
129 return *this;
130 }
131
133 const ext::shared_ptr<PricingEngine>& engine) {
134 engine_ = engine;
135 return *this;
136 }
137
140 QL_REQUIRE(nominalTermStructure_.empty(), "ATM strike already given");
141 strike_ = strike;
142 return *this;
143 }
144
147 const Handle<YieldTermStructure>& nominalTermStructure) {
148 QL_REQUIRE(strike_ == Null<Rate>(), "explicit strike already given");
149 nominalTermStructure_ = nominalTermStructure;
150 return *this;
151 }
152
155 forwardStart_ = forwardStart;
156 return *this;
157 }
158
159}
160
Cash-flow analysis functions.
ext::shared_ptr< PricingEngine > engine_
Definition: cdsoption.cpp:60
calendar class
Definition: calendar.hpp:61
static Rate atmRate(const Leg &leg, const YieldTermStructure &discountCurve, bool includeSettlementDateFlows, Date settlementDate=Date(), Date npvDate=Date(), Real npv=Null< Real >())
At-the-money rate of the cash flows.
Definition: cashflows.cpp:510
Concrete date class.
Definition: date.hpp:125
static Date advance(const Date &d, Integer units, TimeUnit)
Definition: date.cpp:139
day counter class
Definition: daycounter.hpp:44
Shared handle to an observable.
Definition: handle.hpp:41
MakeYoYInflationCapFloor & asOptionlet(bool b=true)
only get last coupon
MakeYoYInflationCapFloor & withStrike(Rate strike)
MakeYoYInflationCapFloor & withPricingEngine(const ext::shared_ptr< PricingEngine > &engine)
MakeYoYInflationCapFloor(YoYInflationCapFloor::Type capFloorType, ext::shared_ptr< YoYInflationIndex > index, const Size &length, Calendar cal, const Period &observationLag, CPI::InterpolationType interpolation)
MakeYoYInflationCapFloor & withFixingDays(Natural fixingDays)
Handle< YieldTermStructure > nominalTermStructure_
MakeYoYInflationCapFloor & withNominal(Real n)
MakeYoYInflationCapFloor & withForwardStart(Period forwardStart)
MakeYoYInflationCapFloor & withEffectiveDate(const Date &effectiveDate)
MakeYoYInflationCapFloor & withPaymentDayCounter(const DayCounter &)
ext::shared_ptr< PricingEngine > engine_
MakeYoYInflationCapFloor & withPaymentAdjustment(BusinessDayConvention)
MakeYoYInflationCapFloor & withAtmStrike(const Handle< YieldTermStructure > &nominalTermStructure)
template class providing a null value for a given type.
Definition: null.hpp:59
Payment schedule.
Definition: schedule.hpp:40
DateProxy & evaluationDate()
the date at which pricing is to be performed.
Definition: settings.hpp:147
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
30/360 day count convention
Definition: thirty360.hpp:76
Base class for yoy inflation cap-like instruments.
Helper class building a sequence of capped/floored yoy inflation coupons.
yoyInflationLeg & withPaymentAdjustment(BusinessDayConvention)
yoyInflationLeg & withNotionals(Real notional)
yoyInflationLeg & withPaymentDayCounter(const DayCounter &)
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
std::function< Real(Real)> b
BusinessDayConvention
Business Day conventions.
@ Annual
once a year
Definition: frequency.hpp:39
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
Helper class to instantiate standard yoy inflation cap/floor.
Definition: any.hpp:37
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78
STL namespace.
InterpolationType
when you observe an index, how do you interpolate between fixings?
30/360 day counters