QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
gridmodellocalvolsurface.cpp
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
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
29namespace QuantLib {
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)
38 referenceDate, NullCalendar(), Following, dayCounter),
39 CalibratedModel(dates.size()*strikes.front()->size()),
40 referenceDate_(referenceDate),
41 times_(dates.size()),
42 strikes_(strikes),
43 dayCounter_(dayCounter),
44 lowerExtrapolation_(lowerExtrapolation),
45 upperExtrapolation_(upperExtrapolation) {
46
47 for (Size i=1; i < strikes_.size(); ++i) {
48 QL_REQUIRE(strikes_[i]->size() == strikes_.front()->size(),
49 "strike vectors must have the same dimension");
50 }
51
52 std::fill(arguments_.begin(), arguments_.end(),
54
55 for (Size i=0; i < dates.size(); ++i) {
57 }
58
60 }
61
65 }
66
68 return localVol_->maxDate();
69 }
71 return localVol_->maxTime();
72 }
74 return localVol_->minStrike();
75 }
77 return localVol_->maxStrike();
78 }
79
81 const {
82 return localVol_->localVol(t, strike, true);
83 }
84
86 const ext::shared_ptr<Matrix> localVolMatrix(
87 new Matrix(strikes_.front()->size(), times_.size()));
88
89 std::transform(arguments_.begin(), arguments_.end(),
90 localVolMatrix->begin(),
91 [](const Parameter& p) { return p(0.0); });
92
93 localVol_ = ext::make_shared<FixedLocalVolSurface>(
95 times_,
97 localVolMatrix,
101 }
102}
Calibrated model class.
Definition: model.hpp:86
void update() override
Definition: model.hpp:90
std::vector< Parameter > arguments_
Definition: model.hpp:126
Standard constant parameter .
Definition: parameter.hpp:71
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Definition: daycounter.hpp:128
ext::shared_ptr< LocalVolTermStructure > localVol_
Real minStrike() const override
the minimum strike for which the term structure can return vols
Volatility localVolImpl(Time t, Real strike) const override
local vol calculation
const std::vector< ext::shared_ptr< std::vector< Real > > > strikes_
GridModelLocalVolSurface(const Date &referenceDate, const std::vector< Date > &dates, const std::vector< ext::shared_ptr< std::vector< Real > > > &strikes, const DayCounter &dayCounter, Extrapolation lowerExtrapolation=FixedLocalVolSurface::ConstantExtrapolation, Extrapolation upperExtrapolation=FixedLocalVolSurface::ConstantExtrapolation)
Date maxDate() const override
the latest date for which the curve can return values
Real maxStrike() const override
the maximum strike for which the term structure can return vols
Time maxTime() const override
the latest time for which the curve can return values
Matrix used in linear algebra.
Definition: matrix.hpp:41
Calendar for reproducing theoretical calculations.
virtual void update()=0
Base class for model arguments.
Definition: parameter.hpp:38
Constraint imposing positivity to all arguments
Definition: constraint.hpp:92
virtual DayCounter dayCounter() const
the day counter used for 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