QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
yoycapfloortermpricesurface.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) 2009 Chris Kenyon
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
21#include <utility>
22
23namespace QuantLib {
24
26 Natural fixingDays,
27 const Period& lag,
28 const ext::shared_ptr<YoYInflationIndex>& yii,
29 Rate baseRate,
31 const DayCounter& dc,
32 const Calendar& cal,
33 const BusinessDayConvention& bdc,
34 const std::vector<Rate>& cStrikes,
35 const std::vector<Rate>& fStrikes,
36 const std::vector<Period>& cfMaturities,
37 const Matrix& cPrice,
38 const Matrix& fPrice)
39 : TermStructure(0, cal, dc),
40 fixingDays_(fixingDays), bdc_(bdc), yoyIndex_(yii), observationLag_(lag), nominalTS_(std::move(nominal)),
41 cStrikes_(cStrikes), fStrikes_(fStrikes), cfMaturities_(cfMaturities), cPrice_(cPrice),
42 fPrice_(fPrice), indexIsInterpolated_(yii->interpolated()) {
43
44 // data consistency checking, enough data?
45 QL_REQUIRE(fStrikes_.size() > 1, "not enough floor strikes");
46 QL_REQUIRE(cStrikes_.size() > 1, "not enough cap strikes");
47 QL_REQUIRE(cfMaturities_.size() > 1, "not enough maturities");
48 QL_REQUIRE(fStrikes_.size() == fPrice.rows(),
49 "floor strikes vs floor price rows not equal");
50 QL_REQUIRE(cStrikes_.size() == cPrice.rows(),
51 "cap strikes vs cap price rows not equal");
52 QL_REQUIRE(cfMaturities_.size() == fPrice.columns(),
53 "maturities vs floor price columns not equal");
54 QL_REQUIRE(cfMaturities_.size() == cPrice.columns(),
55 "maturities vs cap price columns not equal");
56
57 // data has correct properties (positive, monotonic)?
58 for(Size j = 0; j <cfMaturities_.size(); j++) {
59 QL_REQUIRE( cfMaturities[j] > Period(0,Days), "non-positive maturities");
60 if(j>0) {
61 QL_REQUIRE( cfMaturities[j] > cfMaturities[j-1],
62 "non-increasing maturities");
63 }
64 for(Size i = 0; i <fPrice_.rows(); i++) {
65 QL_REQUIRE( fPrice_[i][j] > 0.0,
66 "non-positive floor price: " << fPrice_[i][j] );
67 if(i>0) {
68 QL_REQUIRE( fPrice_[i][j] >= fPrice_[i-1][j],
69 "non-increasing floor prices");
70 }
71 }
72 for(Size i = 0; i <cPrice_.rows(); i++) {
73 QL_REQUIRE( cPrice_[i][j] > 0.0,
74 "non-positive cap price: " << cPrice_[i][j] );
75 if(i>0) {
76 QL_REQUIRE( cPrice_[i][j] <= cPrice_[i-1][j],
77 "non-decreasing cap prices");
78 }
79 }
80 }
81
82
83 // Get the set of strikes, noting that repeats, overlaps are
84 // expected between caps and floors but that no overlap in the
85 // output is allowed so no repeats or overlaps are used
86 cfStrikes_ = std::vector<Rate>();
87 for(Size i = 0; i <fStrikes_.size(); i++)
88 cfStrikes_.push_back( fStrikes[i] );
89 Real eps = 0.0000001;
90 Rate maxFstrike = fStrikes_.back();
91 for(Size i = 0; i < cStrikes_.size(); i++) {
92 Rate k = cStrikes[i];
93 if (k > maxFstrike + eps) cfStrikes_.push_back(k);
94 }
95
96 // final consistency checking
97 QL_REQUIRE(cfStrikes_.size() > 2, "overall not enough strikes");
98 for (Size i = 1; i < cfStrikes_.size(); i++)
100 "cfStrikes not increasing");
101 }
102
104 {
105 return referenceDate() + p;
106 }
107
109 return price(yoyOptionDateFromTenor(d), k);
110 }
111
114 }
115
118 }
119
121 bool extrapolate) const {
122 return atmYoYSwapRate(yoyOptionDateFromTenor(d), extrapolate);
123 }
124
126 const Period& obsLag,
127 bool extrapolate) const {
128 return atmYoYRate(yoyOptionDateFromTenor(d), obsLag, extrapolate);
129 }
130
131}
132
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Shared handle to an observable.
Definition: handle.hpp:41
Matrix used in linear algebra.
Definition: matrix.hpp:41
Size rows() const
Definition: matrix.hpp:504
Size columns() const
Definition: matrix.hpp:508
Basic term-structure functionality.
virtual const Date & referenceDate() const
the date at which discount = 1.0 and/or variance = 0.0
virtual Real price(const Date &d, Rate k) const =0
virtual Rate atmYoYRate(const Date &d, const Period &obsLag=Period(-1, Days), bool extrapolate=true) const =0
YoYCapFloorTermPriceSurface(Natural fixingDays, const Period &yyLag, const ext::shared_ptr< YoYInflationIndex > &yii, Rate baseRate, Handle< YieldTermStructure > nominal, const DayCounter &dc, const Calendar &cal, const BusinessDayConvention &bdc, const std::vector< Rate > &cStrikes, const std::vector< Rate > &fStrikes, const std::vector< Period > &cfMaturities, const Matrix &cPrice, const Matrix &fPrice)
virtual Real capPrice(const Date &d, Rate k) const =0
virtual Rate atmYoYSwapRate(const Date &d, bool extrapolate=true) const =0
virtual Real floorPrice(const Date &d, Rate k) const =0
virtual Date yoyOptionDateFromTenor(const Period &p) const
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Date d
BusinessDayConvention
Business Day conventions.
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
STL namespace.
yoy inflation cap and floor term-price structure