QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
extendedblackvariancecurve.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008 Frank Hövermann
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
20#include <ql/experimental/volatility/extendedblackvariancecurve.hpp>
21#include <ql/math/interpolations/linearinterpolation.hpp>
22#include <utility>
23
24namespace QuantLib {
25
27 const std::vector<Date>& dates,
28 std::vector<Handle<Quote> > volatilities,
29 DayCounter dayCounter,
30 bool forceMonotoneVariance)
31 : BlackVarianceTermStructure(referenceDate), dayCounter_(std::move(dayCounter)),
32 maxDate_(dates.back()), volatilities_(std::move(volatilities)),
33 forceMonotoneVariance_(forceMonotoneVariance) {
34 QL_REQUIRE(dates.size() == volatilities_.size(),
35 "size mismatch between dates and volatilities");
36
37 QL_REQUIRE(dates[0] > referenceDate,
38 "cannot have dates_[0] <= referenceDate");
39
40 variances_ = std::vector<Real>(dates.size()+1);
41 times_ = std::vector<Time>(dates.size()+1);
42
43 times_[0] = 0.0;
44 for (Size j=1; j<=dates.size(); ++j) {
45 times_[j] = timeFromReference(dates[j-1]);
46 QL_REQUIRE(times_[j]>times_[j-1],
47 "dates must be sorted unique!");
48 }
49
51 setInterpolation<Linear>();
52
53 for (auto& volatilitie : volatilities_)
54 registerWith(volatilitie);
55 }
56
58 variances_[0] = 0.0;
59 for (Size j=1; j<=volatilities_.size(); j++) {
60 Volatility sigma = volatilities_[j-1]->value();
61 variances_[j] = times_[j] * sigma * sigma;
62 QL_REQUIRE(variances_[j]>=variances_[j-1]
64 "variance must be non-decreasing");
65 }
66 }
67
72 }
73
75 if (t<=times_.back()) {
76 return varianceCurve_(t, true);
77 } else {
78 return varianceCurve_(times_.back(), true)*t/times_.back();
79 }
80 }
81
82}
83
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
std::vector< Handle< Quote > > volatilities_
ExtendedBlackVarianceCurve(const Date &referenceDate, const std::vector< Date > &dates, std::vector< Handle< Quote > > volatilities, DayCounter dayCounter, bool forceMonotoneVariance=true)
Real blackVarianceImpl(Time t, Real) const override
Black variance calculation.
Shared handle to an observable.
Definition: handle.hpp:41
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
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
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real Volatility
volatility
Definition: types.hpp:78
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
STL namespace.