/src/quantlib/ql/termstructures/volatility/equityfx/gridmodellocalvolsurface.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) 2015 Klaus Spanderen |
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 | | /*! \file parameterizedlocalvolsurface.cpp |
21 | | */ |
22 | | |
23 | | #include <ql/time/calendars/nullcalendar.hpp> |
24 | | #include <ql/termstructures/volatility/equityfx/fixedlocalvolsurface.hpp> |
25 | | #include <ql/termstructures/volatility/equityfx/gridmodellocalvolsurface.hpp> |
26 | | #include <ql/functional.hpp> |
27 | | #include <algorithm> |
28 | | |
29 | | namespace QuantLib { |
30 | | GridModelLocalVolSurface::GridModelLocalVolSurface( |
31 | | const Date& referenceDate, |
32 | | const std::vector<Date>& dates, |
33 | | const std::vector<ext::shared_ptr<std::vector<Real> > >& strikes, |
34 | | const DayCounter& dayCounter, |
35 | | Extrapolation lowerExtrapolation, |
36 | | Extrapolation upperExtrapolation) |
37 | 0 | : LocalVolTermStructure( |
38 | 0 | referenceDate, NullCalendar(), Following, dayCounter), |
39 | 0 | CalibratedModel(dates.size()*strikes.front()->size()), |
40 | 0 | referenceDate_(referenceDate), |
41 | 0 | times_(dates.size()), |
42 | 0 | strikes_(strikes), |
43 | 0 | dayCounter_(dayCounter), |
44 | 0 | lowerExtrapolation_(lowerExtrapolation), |
45 | 0 | upperExtrapolation_(upperExtrapolation) { |
46 | |
|
47 | 0 | for (Size i=1; i < strikes_.size(); ++i) { |
48 | 0 | QL_REQUIRE(strikes_[i]->size() == strikes_.front()->size(), |
49 | 0 | "strike vectors must have the same dimension"); |
50 | 0 | } |
51 | | |
52 | 0 | std::fill(arguments_.begin(), arguments_.end(), |
53 | 0 | ConstantParameter(1.0, PositiveConstraint())); |
54 | |
|
55 | 0 | for (Size i=0; i < dates.size(); ++i) { |
56 | 0 | times_[i] = dayCounter.yearFraction(referenceDate_, dates[i]); |
57 | 0 | } |
58 | |
|
59 | 0 | GridModelLocalVolSurface::generateArguments(); |
60 | 0 | } Unexecuted instantiation: QuantLib::GridModelLocalVolSurface::GridModelLocalVolSurface(QuantLib::Date const&, std::__1::vector<QuantLib::Date, std::__1::allocator<QuantLib::Date> > const&, std::__1::vector<boost::shared_ptr<std::__1::vector<double, std::__1::allocator<double> > >, std::__1::allocator<boost::shared_ptr<std::__1::vector<double, std::__1::allocator<double> > > > > const&, QuantLib::DayCounter const&, QuantLib::FixedLocalVolSurface::Extrapolation, QuantLib::FixedLocalVolSurface::Extrapolation) Unexecuted instantiation: QuantLib::GridModelLocalVolSurface::GridModelLocalVolSurface(QuantLib::Date const&, std::__1::vector<QuantLib::Date, std::__1::allocator<QuantLib::Date> > const&, std::__1::vector<boost::shared_ptr<std::__1::vector<double, std::__1::allocator<double> > >, std::__1::allocator<boost::shared_ptr<std::__1::vector<double, std::__1::allocator<double> > > > > const&, QuantLib::DayCounter const&, QuantLib::FixedLocalVolSurface::Extrapolation, QuantLib::FixedLocalVolSurface::Extrapolation) |
61 | | |
62 | 0 | void GridModelLocalVolSurface::update() { |
63 | 0 | LocalVolTermStructure::update(); |
64 | 0 | CalibratedModel::update(); |
65 | 0 | } |
66 | | |
67 | 0 | Date GridModelLocalVolSurface::maxDate() const { |
68 | 0 | return localVol_->maxDate(); |
69 | 0 | } |
70 | 0 | Time GridModelLocalVolSurface::maxTime() const { |
71 | 0 | return localVol_->maxTime(); |
72 | 0 | } |
73 | 0 | Real GridModelLocalVolSurface::minStrike() const { |
74 | 0 | return localVol_->minStrike(); |
75 | 0 | } |
76 | 0 | Real GridModelLocalVolSurface::maxStrike() const { |
77 | 0 | return localVol_->maxStrike(); |
78 | 0 | } |
79 | | |
80 | | Volatility GridModelLocalVolSurface::localVolImpl(Time t, Real strike) |
81 | 0 | const { |
82 | 0 | return localVol_->localVol(t, strike, true); |
83 | 0 | } |
84 | | |
85 | 0 | void GridModelLocalVolSurface::generateArguments() { |
86 | 0 | const ext::shared_ptr<Matrix> localVolMatrix( |
87 | 0 | new Matrix(strikes_.front()->size(), times_.size())); |
88 | |
|
89 | 0 | std::transform(arguments_.begin(), arguments_.end(), |
90 | 0 | localVolMatrix->begin(), |
91 | 0 | [](const Parameter& p) { return p(0.0); }); |
92 | |
|
93 | 0 | localVol_ = ext::make_shared<FixedLocalVolSurface>( |
94 | 0 | referenceDate_, |
95 | 0 | times_, |
96 | 0 | strikes_, |
97 | 0 | localVolMatrix, |
98 | 0 | dayCounter_, |
99 | 0 | lowerExtrapolation_, |
100 | 0 | upperExtrapolation_); |
101 | 0 | } |
102 | | } |