Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
blackvariancecurve3.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19#include <ql/math/interpolations/linearinterpolation.hpp>
21
22namespace QuantExt {
23
24BlackVarianceCurve3::BlackVarianceCurve3(Natural settlementDays, const Calendar& cal, BusinessDayConvention bdc,
25 const DayCounter& dc, const std::vector<Time>& times,
26 const std::vector<Handle<Quote> >& blackVolCurve, bool requireMonotoneVariance)
27 : BlackVarianceTermStructure(settlementDays, cal, bdc, dc), times_(times), quotes_(blackVolCurve),
28 requireMonotoneVariance_(requireMonotoneVariance) {
29
30 QL_REQUIRE(times.size() == blackVolCurve.size(), "mismatch between date vector and black vol vector");
31
32 // cannot have dates[0]==referenceDate, since the
33 // value of the vol at dates[0] would be lost
34 // (variance at referenceDate must be zero)
35 QL_REQUIRE(times[0] > 0, "cannot have times[0] <= 0");
36
37 // Now insert 0 at the start of times_
38 times_.insert(times_.begin(), 0);
39
40 variances_ = std::vector<Real>(times_.size());
41 variances_[0] = 0.0;
42 for (Size j = 1; j < times_.size(); j++) {
43 QL_REQUIRE(times_[j] > times_[j - 1], "times must be sorted unique!");
44 registerWith(quotes_[j - 1]);
45 }
46 varianceCurve_ = Linear().interpolate(times_.begin(), times_.end(), variances_.begin());
47}
48
50 TermStructure::update(); // calls notifyObservers
51 LazyObject::update(); // as does this
52}
53
55 for (Size j = 1; j <= quotes_.size(); j++) {
56 variances_[j] = times_[j] * quotes_[j - 1]->value() * quotes_[j - 1]->value();
58 QL_REQUIRE(variances_[j] >= variances_[j - 1],
59 "variance must be non-decreasing at j:" << j << " got var[j]:" << variances_[j]
60 << " and var[j-1]:" << variances_[j - 1]);
61 }
62 }
63 varianceCurve_.update();
64}
65
67 calculate();
68 if (t <= times_.back()) {
69 return varianceCurve_(t, true);
70 } else {
71 // extrapolate with flat vol
72 return varianceCurve_(times_.back(), true) * t / times_.back();
73 }
74}
75} // namespace QuantExt
Black volatility curve modeled as variance curve.
BlackVarianceCurve3(Natural settlementDays, const Calendar &cal, BusinessDayConvention bdc, const DayCounter &dc, const std::vector< Time > &times, const std::vector< Handle< Quote > > &blackVolCurve, bool requireMonotoneVariance=true)
void performCalculations() const override
std::vector< Handle< Quote > > quotes_
virtual Real blackVarianceImpl(Time t, Real) const override