QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
blackvariancecurve.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) 2002, 2003, 2004 Ferdinando Ametrano
5 Copyright (C) 2003 StatPro Italia srl
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
23#include <utility>
24
25namespace QuantLib {
26
28 const std::vector<Date>& dates,
29 const std::vector<Volatility>& blackVolCurve,
30 DayCounter dayCounter,
31 bool forceMonotoneVariance)
32 : BlackVarianceTermStructure(referenceDate), dayCounter_(std::move(dayCounter)),
33 maxDate_(dates.back()) {
34
35 QL_REQUIRE(dates.size()==blackVolCurve.size(),
36 "mismatch between date vector and black vol vector");
37
38 // cannot have dates[0]==referenceDate, since the
39 // value of the vol at dates[0] would be lost
40 // (variance at referenceDate must be zero)
42 "cannot have dates[0] <= referenceDate");
43
44 variances_ = std::vector<Real>(dates.size()+1);
45 times_ = std::vector<Time>(dates.size()+1);
46 variances_[0] = 0.0;
47 times_[0] = 0.0;
48 Size j;
49 for (j=1; j<=blackVolCurve.size(); j++) {
50 times_[j] = timeFromReference(dates[j-1]);
51 QL_REQUIRE(times_[j]>times_[j-1],
52 "dates must be sorted unique!");
53 variances_[j] = times_[j] *
54 blackVolCurve[j-1]*blackVolCurve[j-1];
56 || !forceMonotoneVariance,
57 "variance must be non-decreasing");
58 }
59
60 // default: linear interpolation
61 setInterpolation<Linear>();
62 }
63
65 if (t<=times_.back()) {
66 return varianceCurve_(t, true);
67 } else {
68 // extrapolate with flat vol
69 return varianceCurve_(times_.back(), true)*t/times_.back();
70 }
71 }
72
73}
74
Black volatility curve modelled as variance curve.
BlackVarianceCurve(const Date &referenceDate, const std::vector< Date > &dates, const std::vector< Volatility > &blackVolCurve, DayCounter dayCounter, bool forceMonotoneVariance=true)
Real blackVarianceImpl(Time t, Real) const override
Black variance calculation.
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
virtual const Date & referenceDate() const
the date at which discount = 1.0 and/or variance = 0.0
Time timeFromReference(const Date &date) const
date/time conversion
const DefaultType & t
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
linear interpolation between discrete points
Definition: any.hpp:35
STL namespace.