QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
cpicapfloor.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2010, 2011 Chris Kenyon
5 Copyright (C) 2021 Ralf Konrad Eckel
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
22#include <ql/cashflows/cashflows.hpp>
23#include <ql/cashflows/cashflowvectors.hpp>
24#include <ql/cashflows/couponpricer.hpp>
25#include <ql/cashflows/fixedratecoupon.hpp>
26#include <ql/cashflows/iborcoupon.hpp>
27#include <ql/cashflows/simplecashflow.hpp>
28#include <ql/indexes/inflationindex.hpp>
29#include <ql/instruments/cpicapfloor.hpp>
30#include <ql/termstructures/yieldtermstructure.hpp>
31#include <ql/time/schedule.hpp>
32#include <utility>
33
34
35namespace QuantLib {
36
38 Real nominal,
39 const Date& startDate, // start date of contract (only)
40 Real baseCPI,
41 const Date& maturity, // this is pre-adjustment!
42 Calendar fixCalendar,
43 BusinessDayConvention fixConvention,
44 Calendar payCalendar,
45 BusinessDayConvention payConvention,
46 Rate strike,
47 const ext::shared_ptr<ZeroInflationIndex>& index,
48 const Period& observationLag,
49 CPI::InterpolationType observationInterpolation)
50 : type_(type), nominal_(nominal), startDate_(startDate), baseCPI_(baseCPI), maturity_(maturity),
51 fixCalendar_(std::move(fixCalendar)), fixConvention_(fixConvention),
52 payCalendar_(std::move(payCalendar)), payConvention_(payConvention), strike_(strike),
53 index_(index), observationLag_(observationLag),
54 observationInterpolation_(observationInterpolation) {
55 QL_REQUIRE(index_, "no inflation index passed");
56 QL_REQUIRE(fixCalendar_ != Calendar(), "no fixing calendar passed");
57 QL_REQUIRE(payCalendar_ != Calendar(), "no payment calendar passed");
58
60 QL_REQUIRE(observationLag_ >= index_->availabilityLag(),
61 "CPIcapfloor's observationLag must be at least availabilityLag of inflation index: "
62 <<"when the observation is effectively flat"
63 << observationLag_ << " vs " << index_->availabilityLag());
64 } else {
65 QL_REQUIRE(observationLag_ > index_->availabilityLag(),
66 "CPIcapfloor's observationLag must be greater than availabilityLag of inflation index: "
67 <<"when the observation is effectively linear"
68 << observationLag_ << " vs " << index_->availabilityLag());
69 }
70 }
71
72
73 // when you fix - but remember that there is an observation interpolation factor as well
76 }
77
78
81 }
82
83
85 return (Settings::instance().evaluationDate() > maturity_);
86 }
87
88
90 // nothing yet
91 }
92
93
95
96 // correct PricingEngine?
97 auto* arguments = dynamic_cast<CPICapFloor::arguments*>(args);
98 QL_REQUIRE(arguments != nullptr, "wrong argument type, not CPICapFloor::arguments*");
99
100 // data move
116 }
117
118}
BusinessDayConvention payConvention
CPI::InterpolationType observationInterpolation
ext::shared_ptr< ZeroInflationIndex > index
BusinessDayConvention fixConvention
void validate() const override
Definition: cpicapfloor.cpp:89
Date fixingDate() const
Definition: cpicapfloor.cpp:74
void setupArguments(PricingEngine::arguments *) const override
Definition: cpicapfloor.cpp:94
bool isExpired() const override
returns whether the instrument might have value greater than zero.
Definition: cpicapfloor.cpp:84
ext::shared_ptr< ZeroInflationIndex > index_
CPICapFloor(Option::Type type, Real nominal, const Date &startDate, Real baseCPI, const Date &maturity, Calendar fixCalendar, BusinessDayConvention fixConvention, Calendar payCalendar, BusinessDayConvention payConvention, Rate strike, const ext::shared_ptr< ZeroInflationIndex > &inflationIndex, const Period &observationLag, CPI::InterpolationType observationInterpolation=CPI::AsIndex)
Definition: cpicapfloor.cpp:37
Date payDate() const
Definition: cpicapfloor.cpp:79
CPI::InterpolationType observationInterpolation_
BusinessDayConvention payConvention_
BusinessDayConvention fixConvention_
calendar class
Definition: calendar.hpp:61
Date adjust(const Date &, BusinessDayConvention convention=Following) const
Definition: calendar.cpp:84
Concrete date class.
Definition: date.hpp:125
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
bool isInterpolated(const ext::shared_ptr< ZeroInflationIndex > &index, const QuantLib::CPI::InterpolationType &type=QuantLib::CPI::AsIndex)
Definition: any.hpp:35
STL namespace.
InterpolationType
when you observe an index, how do you interpolate between fixings?