QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
capfloortermvolcurve.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2007 Ferdinando Ametrano
5 Copyright (C) 2007 Katiuscia Manzoni
6 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
7 Copyright (C) 2003, 2004, 2005 StatPro Italia srl
8
9 This file is part of QuantLib, a free-software/open-source library
10 for financial quantitative analysts and developers - http://quantlib.org/
11
12 QuantLib is free software: you can redistribute it and/or modify it
13 under the terms of the QuantLib license. You should have received a
14 copy of the license along with this program; if not, please email
15 <quantlib-dev@lists.sf.net>. The license is also available online at
16 <http://quantlib.org/license.shtml>.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the license for more details.
21*/
22
23#include <ql/termstructures/volatility/capfloor/capfloortermvolcurve.hpp>
24#include <ql/math/interpolations/cubicinterpolation.hpp>
25#include <ql/quotes/simplequote.hpp>
26#include <ql/utilities/dataformatters.hpp>
27
28namespace QuantLib {
29
30 // floating reference date, floating market data
32 Natural settlementDays,
33 const Calendar& calendar,
35 const std::vector<Period>& optionTenors,
36 const std::vector<Handle<Quote> >& vols,
37 const DayCounter& dc)
38 : CapFloorTermVolatilityStructure(settlementDays, calendar, bdc, dc),
39 nOptionTenors_(optionTenors.size()),
40 optionTenors_(optionTenors),
41 optionDates_(nOptionTenors_),
42 optionTimes_(nOptionTenors_),
43 volHandles_(vols),
44 vols_(vols.size()) // do not initialize with nOptionTenors_
45 {
50 }
51
52 // fixed reference date, floating market data
54 const Date& settlementDate,
55 const Calendar& calendar,
57 const std::vector<Period>& optionTenors,
58 const std::vector<Handle<Quote> >& vols,
59 const DayCounter& dayCounter)
60 : CapFloorTermVolatilityStructure(settlementDate, calendar, bdc, dayCounter),
61 nOptionTenors_(optionTenors.size()),
62 optionTenors_(optionTenors),
63 optionDates_(nOptionTenors_),
64 optionTimes_(nOptionTenors_),
65 volHandles_(vols),
66 vols_(vols.size()) // do not initialize with nOptionTenors_
67 {
72 }
73
74 // fixed reference date, fixed market data
76 const Date& settlementDate,
77 const Calendar& calendar,
79 const std::vector<Period>& optionTenors,
80 const std::vector<Volatility>& vols,
81 const DayCounter& dayCounter)
82 : CapFloorTermVolatilityStructure(settlementDate, calendar, bdc, dayCounter),
83 nOptionTenors_(optionTenors.size()),
84 optionTenors_(optionTenors),
85 optionDates_(nOptionTenors_),
86 optionTimes_(nOptionTenors_),
87 volHandles_(vols.size()), // do not initialize with nOptionTenors_
88 vols_(vols)
89 {
92 // fill dummy handles to allow generic handle-based computations later
93 for (Size i=0; i<nOptionTenors_; ++i)
94 volHandles_[i] = Handle<Quote>(ext::shared_ptr<Quote>(new
95 SimpleQuote(vols_[i])));
97 }
98
99 // floating reference date, fixed market data
101 Natural settlementDays,
102 const Calendar& calendar,
104 const std::vector<Period>& optionTenors,
105 const std::vector<Volatility>& vols,
106 const DayCounter& dayCounter)
107 : CapFloorTermVolatilityStructure(settlementDays, calendar, bdc, dayCounter),
108 nOptionTenors_(optionTenors.size()),
109 optionTenors_(optionTenors),
110 optionDates_(nOptionTenors_),
111 optionTimes_(nOptionTenors_),
112 volHandles_(vols.size()), // do not initialize with nOptionTenors_
113 vols_(vols)
114 {
115 checkInputs();
117 // fill dummy handles to allow generic handle-based computations later
118 for (Size i=0; i<nOptionTenors_; ++i)
119 volHandles_[i] = Handle<Quote>(ext::shared_ptr<Quote>(new
120 SimpleQuote(vols_[i])));
121 interpolate();
122 }
123
125 {
126 QL_REQUIRE(!optionTenors_.empty(), "empty option tenor vector");
127 QL_REQUIRE(nOptionTenors_==vols_.size(),
128 "mismatch between number of option tenors (" <<
129 nOptionTenors_ << ") and number of volatilities (" <<
130 vols_.size() << ")");
131 QL_REQUIRE(optionTenors_[0]>0*Days,
132 "negative first option tenor: " << optionTenors_[0]);
133 for (Size i=1; i<nOptionTenors_; ++i)
134 QL_REQUIRE(optionTenors_[i]>optionTenors_[i-1],
135 "non increasing option tenor: " << io::ordinal(i) <<
136 " is " << optionTenors_[i-1] << ", " <<
137 io::ordinal(i+1) << " is " << optionTenors_[i]);
138 }
139
141 {
142 for (auto& volHandle : volHandles_)
143 registerWith(volHandle);
144 }
145
147 {
149 optionTimes_.begin(), optionTimes_.end(),
150 vols_.begin(),
154 }
155
157 {
158 // recalculate dates if necessary...
159 if (moving_) {
161 if (evaluationDate_ != d) {
162 evaluationDate_ = d;
164 }
165 }
168 }
169
171 {
172 for (Size i=0; i<nOptionTenors_; ++i) {
175 }
176 }
177
179 {
180 // check if date recalculation must be called here
181
182 for (Size i=0; i<vols_.size(); ++i)
183 vols_[i] = volHandles_[i]->value();
184
186 }
187
188}
calendar class
Definition: calendar.hpp:61
void performCalculations() const override
CapFloorTermVolCurve(Natural settlementDays, const Calendar &calendar, BusinessDayConvention bdc, const std::vector< Period > &optionTenors, const std::vector< Handle< Quote > > &vols, const DayCounter &dc=Actual365Fixed())
floating reference date, floating market data
std::vector< Handle< Quote > > volHandles_
Cubic interpolation between discrete points.
@ SecondDerivative
Match value of second derivative at end.
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Shared handle to an observable.
Definition: handle.hpp:41
void update() override
Definition: lazyobject.hpp:188
virtual void update()=0
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
DateProxy & evaluationDate()
the date at which pricing is to be performed.
Definition: settings.hpp:147
market element returning a stored value
Definition: simplequote.hpp:33
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
Time timeFromReference(const Date &date) const
date/time conversion
Date optionDateFromTenor(const Period &) const
period/date conversion
BusinessDayConvention
Business Day conventions.
detail::ordinal_holder ordinal(Size)
outputs naturals as 1st, 2nd, 3rd...
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35