/src/quantlib/ql/termstructures/volatility/equityfx/blackvariancecurve.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
21 | | #include <ql/math/interpolations/linearinterpolation.hpp> |
22 | | #include <ql/termstructures/volatility/equityfx/blackvariancecurve.hpp> |
23 | | #include <utility> |
24 | | |
25 | | namespace QuantLib { |
26 | | |
27 | | BlackVarianceCurve::BlackVarianceCurve(const Date& referenceDate, |
28 | | const std::vector<Date>& dates, |
29 | | const std::vector<Volatility>& blackVolCurve, |
30 | | DayCounter dayCounter, |
31 | | bool forceMonotoneVariance) |
32 | 0 | : BlackVarianceTermStructure(referenceDate), dayCounter_(std::move(dayCounter)), |
33 | 0 | maxDate_(dates.back()) { |
34 | |
|
35 | 0 | QL_REQUIRE(dates.size()==blackVolCurve.size(), |
36 | 0 | "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) |
41 | 0 | QL_REQUIRE(dates[0]>referenceDate, |
42 | 0 | "cannot have dates[0] <= referenceDate"); |
43 | | |
44 | 0 | variances_ = std::vector<Real>(dates.size()+1); |
45 | 0 | times_ = std::vector<Time>(dates.size()+1); |
46 | 0 | variances_[0] = 0.0; |
47 | 0 | times_[0] = 0.0; |
48 | 0 | Size j; |
49 | 0 | for (j=1; j<=blackVolCurve.size(); j++) { |
50 | 0 | times_[j] = timeFromReference(dates[j-1]); |
51 | 0 | QL_REQUIRE(times_[j]>times_[j-1], |
52 | 0 | "dates must be sorted unique!"); |
53 | 0 | variances_[j] = times_[j] * |
54 | 0 | blackVolCurve[j-1]*blackVolCurve[j-1]; |
55 | 0 | QL_REQUIRE(variances_[j]>=variances_[j-1] |
56 | 0 | || !forceMonotoneVariance, |
57 | 0 | "variance must be non-decreasing"); |
58 | 0 | } |
59 | | |
60 | | // default: linear interpolation |
61 | 0 | setInterpolation<Linear>(); |
62 | 0 | } Unexecuted instantiation: QuantLib::BlackVarianceCurve::BlackVarianceCurve(QuantLib::Date const&, std::__1::vector<QuantLib::Date, std::__1::allocator<QuantLib::Date> > const&, std::__1::vector<double, std::__1::allocator<double> > const&, QuantLib::DayCounter, bool) Unexecuted instantiation: QuantLib::BlackVarianceCurve::BlackVarianceCurve(QuantLib::Date const&, std::__1::vector<QuantLib::Date, std::__1::allocator<QuantLib::Date> > const&, std::__1::vector<double, std::__1::allocator<double> > const&, QuantLib::DayCounter, bool) |
63 | | |
64 | 0 | Real BlackVarianceCurve::blackVarianceImpl(Time t, Real) const { |
65 | 0 | if (t<=times_.back()) { |
66 | 0 | return varianceCurve_(t, true); |
67 | 0 | } else { |
68 | | // extrapolate with flat vol |
69 | 0 | return varianceCurve_(times_.back(), true)*t/times_.back(); |
70 | 0 | } |
71 | 0 | } |
72 | | |
73 | | } |
74 | | |