QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
cpicapfloorengines.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) 2011 Chris Kenyon
5
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21
25#include <utility>
26
27
28namespace QuantLib {
29
30
33 : priceSurf_(std::move(priceSurf)) {
35 }
36
37
39 {
40 Real npv = 0.0;
41
42 // what is the difference between the observationLag of the surface
43 // and the observationLag of the cap/floor?
44 // \TODO next line will fail if units are different
45 Period lagDiff = arguments_.observationLag - priceSurf_->observationLag();
46 // next line will fail if units are different if Period() is not well written
47 QL_REQUIRE(lagDiff >= Period(0, Months), "InterpolatingCPICapFloorEngine: "
48 "lag difference must be non-negative: " << lagDiff);
49
50 // we now need an effective maturity to use in the price surface because this uses
51 // maturity of calibration instruments as its time axis, N.B. this must also
52 // use the roll because the surface does
53 Date effectiveMaturity = arguments_.payDate - lagDiff;
54
55
56 // what interpolation do we use? Index / flat / linear
58 // same as index means we can just use the price surface
59 // since this uses the index
61 npv = priceSurf_->capPrice(effectiveMaturity, arguments_.strike);
62 } else {
63 npv = priceSurf_->floorPrice(effectiveMaturity, arguments_.strike);
64 }
65
66
67 } else {
68 std::pair<Date,Date> dd = inflationPeriod(effectiveMaturity, arguments_.index->frequency());
69 Real priceStart = 0.0;
70
72 priceStart = priceSurf_->capPrice(dd.first, arguments_.strike);
73 } else {
74 priceStart = priceSurf_->floorPrice(dd.first, arguments_.strike);
75 }
76
77 // if we use a flat index vs the interpolated one ...
79 // then use the price for the first day in the period because the value cannot change after then
80 npv = priceStart;
81
82 } else {
83 // linear interpolation will be very close
84 Real priceEnd = 0.0;
86 priceEnd = priceSurf_->capPrice((dd.second+Period(1,Days)), arguments_.strike);
87 } else {
88 priceEnd = priceSurf_->floorPrice((dd.second+Period(1,Days)), arguments_.strike);
89 }
90
91 npv = priceStart + (priceEnd - priceStart) * (effectiveMaturity - dd.first)
92 / ( (dd.second+Period(1,Days)) - dd.first); // can't get to next period'
93 }
94
95 }
96 results_.value = npv;
97 }
98
99}
act/act day counters
CPI::InterpolationType observationInterpolation
ext::shared_ptr< ZeroInflationIndex > index
Concrete date class.
Definition: date.hpp:125
Shared handle to an observable.
Definition: handle.hpp:41
Handle< CPICapFloorTermPriceSurface > priceSurf_
InterpolatingCPICapFloorEngine(Handle< CPICapFloorTermPriceSurface >)
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
Engines for CPI options.
cpi inflation cap and floor term price structure.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
std::pair< Date, Date > inflationPeriod(const Date &d, Frequency frequency)
utility function giving the inflation period for a given date
STL namespace.
@ AsIndex
same interpolation as index
@ Flat
flat from previous fixing