QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
makeyoyinflationcapfloor.cpp
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
22#include <ql/cashflows/cashflows.hpp>
23#include <ql/instruments/makeyoyinflationcapfloor.hpp>
24#include <ql/time/daycounters/thirty360.hpp>
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 : capFloorType_(capFloorType), length_(length), calendar_(std::move(cal)),
35 index_(std::move(index)), observationLag_(observationLag), strike_(Null<Rate>()),
36
37 dayCounter_(Thirty360(Thirty360::BondBasis)) {}
38
39 MakeYoYInflationCapFloor::operator YoYInflationCapFloor() const {
40 ext::shared_ptr<YoYInflationCapFloor> capfloor = *this;
41 return *capfloor;
42 }
43
44 MakeYoYInflationCapFloor::operator ext::shared_ptr<YoYInflationCapFloor>() const {
45
46 Date startDate;
47 if (effectiveDate_ != Date()) {
48 startDate = effectiveDate_;
49 } else {
50 Date referenceDate = Settings::instance().evaluationDate();
51 Date spotDate = calendar_.advance(referenceDate,
52 fixingDays_*Days);
53 startDate = spotDate+forwardStart_;
54 }
55
56 Date endDate = calendar_.advance(startDate,length_*Years,Unadjusted);
57 Schedule schedule(startDate, endDate, Period(Annual), calendar_,
58 Unadjusted, Unadjusted, // ref periods & acc periods
60 Leg leg = yoyInflationLeg(schedule, calendar_, index_,
61 observationLag_)
63 .withPaymentDayCounter(dayCounter_)
64 .withNotionals(nominal_)
65 ;
66
67 if (firstCapletExcluded_)
68 leg.erase(leg.begin());
69
70 // only leaves the last coupon
71 if (asOptionlet_ && leg.size() > 1) {
72 auto end = leg.end(); // Sun Studio needs an lvalue
73 leg.erase(leg.begin(), --end);
74 }
75
76 std::vector<Rate> strikeVector(1, strike_);
77 if (strike_ == Null<Rate>()) {
78 // ATM on the forecasting curve
79 strikeVector[0] = CashFlows::atmRate(leg, **nominalTermStructure_,
80 false, nominalTermStructure_->referenceDate());
81 }
82
83 ext::shared_ptr<YoYInflationCapFloor> capFloor(new
84 YoYInflationCapFloor(capFloorType_, leg, strikeVector));
85 capFloor->setPricingEngine(engine_);
86 return capFloor;
87 }
88
90 nominal_ = n;
91 return *this;
92 }
93
95 const Date& effectiveDate) {
96 effectiveDate_ = effectiveDate;
97 return *this;
98 }
99
102 roll_ = bdc;
103 return *this;
104 }
105
108 dayCounter_ = dc;
109 return *this;
110 }
111
114 fixingDays_ = n;
115 return *this;
116 }
117
119 asOptionlet_ = b;
120 return *this;
121 }
122
124 const ext::shared_ptr<PricingEngine>& engine) {
125 engine_ = engine;
126 return *this;
127 }
128
131 QL_REQUIRE(nominalTermStructure_.empty(), "ATM strike already given");
132 strike_ = strike;
133 return *this;
134 }
135
138 const Handle<YieldTermStructure>& nominalTermStructure) {
139 QL_REQUIRE(strike_ == Null<Rate>(), "explicit strike already given");
140 nominalTermStructure_ = nominalTermStructure;
141 return *this;
142 }
143
146 forwardStart_ = forwardStart;
147 return *this;
148 }
149
150}
151
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:521
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 & withFixingDays(Natural fixingDays)
Handle< YieldTermStructure > nominalTermStructure_
MakeYoYInflationCapFloor(YoYInflationCapFloor::Type capFloorType, ext::shared_ptr< YoYInflationIndex > index, const Size &length, Calendar cal, const Period &observationLag)
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:76
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.
yoyInflationLeg & withPaymentAdjustment(BusinessDayConvention)
yoyInflationLeg & withNotionals(Real notional)
yoyInflationLeg & withPaymentDayCounter(const DayCounter &)
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
Definition: any.hpp:35
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78
STL namespace.