QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
andreasenhugevolatilityinterpl.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2017, 2018 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 andreasenhugevolatilityinterpl.hpp
21 \brief Andreasen-Huge local volatility calibration and interpolation
22*/
23
24#ifndef quantlib_andreasen_huge_local_volatility_hpp
25#define quantlib_andreasen_huge_local_volatility_hpp
26
27#include <ql/quote.hpp>
28#include <ql/handle.hpp>
29#include <ql/option.hpp>
30#include <ql/math/matrix.hpp>
35
36#include <ql/tuple.hpp>
37#include <utility>
38
39namespace QuantLib {
40
41 class VanillaOption;
42 class YieldTermStructure;
43 class FdmMesherComposite;
44 class AndreasenHugeCostFunction;
45
46 //! Calibration of a local volatility surface to a sparse grid of options
47
48 /*! References:
49
50 Andreasen J., Huge B., 2010. Volatility Interpolation
51 https://ssrn.com/abstract=1694972
52 */
53
55
56 public:
60
61 typedef std::vector<std::pair<
62 ext::shared_ptr<VanillaOption>, ext::shared_ptr<Quote> > >
64
66 const CalibrationSet& calibrationSet,
67 Handle<Quote> spot,
70 InterpolationType interpolationType = CubicSpline,
71 CalibrationType calibrationType = Call,
72 Size nGridPoints = 500,
75 ext::shared_ptr<OptimizationMethod> optimizationMethod =
76 ext::shared_ptr<OptimizationMethod>(new LevenbergMarquardt),
77 const EndCriteria& endCriteria = EndCriteria(500, 100, 1e-12, 1e-10, 1e-10));
78
79 Date maxDate() const;
80 Real minStrike() const;
81 Real maxStrike() const;
82
83 Real fwd(Time t) const;
85
86 // returns min, max and average error in volatility units
87 ext::tuple<Real, Real, Real> calibrationError() const;
88
89 // returns the option price of the calibration type. In case
90 // of CallPut it return the call option price
91 Real optionPrice(Time t, Real strike, Option::Type optionType) const;
92
93 Volatility localVol(Time t, Real strike) const;
94
95 protected:
96 void performCalculations() const override;
97
98 private:
99 typedef std::map<Time,
100 ext::tuple<
101 Real,
102 ext::shared_ptr<Array>,
103 ext::shared_ptr<Interpolation> > > TimeValueCacheType;
104
107 ext::shared_ptr<AndreasenHugeCostFunction> costFunction;
108 };
109
110 ext::shared_ptr<AndreasenHugeCostFunction> buildCostFunction(
111 Size iExpiry, Option::Type optionType,
112 const Array& previousNPVs) const;
113
115
117 Real strike, const TimeValueCacheType::const_iterator& f) const;
118
119 Array getPriceSlice(Time t, Option::Type optionType) const;
120
121 Array getLocalVolSlice(Time t, Option::Type optionType) const;
122
129
132
133 const ext::shared_ptr<OptimizationMethod> optimizationMethod_;
135
136 std::vector<Real> strikes_;
137 std::vector<Date> expiries_;
138 mutable std::vector<Time> expiryTimes_, dT_;
139
140 std::vector<std::vector<Size> > calibrationMatrix_;
142
143 mutable ext::shared_ptr<FdmMesherComposite> mesher_;
145
146 mutable std::vector<SingleStepCalibrationResult> calibrationResults_;
147
149 };
150
151}
152
153#endif
Calibration of a local volatility surface to a sparse grid of options.
ext::tuple< Real, Real, Real > calibrationError() const
Array getPriceSlice(Time t, Option::Type optionType) const
Array getLocalVolSlice(Time t, Option::Type optionType) const
std::vector< std::pair< ext::shared_ptr< VanillaOption >, ext::shared_ptr< Quote > > > CalibrationSet
std::map< Time, ext::tuple< Real, ext::shared_ptr< Array >, ext::shared_ptr< Interpolation > > > TimeValueCacheType
Real getCacheValue(Real strike, const TimeValueCacheType::const_iterator &f) const
ext::shared_ptr< AndreasenHugeCostFunction > buildCostFunction(Size iExpiry, Option::Type optionType, const Array &previousNPVs) const
std::vector< SingleStepCalibrationResult > calibrationResults_
const ext::shared_ptr< OptimizationMethod > optimizationMethod_
Real optionPrice(Time t, Real strike, Option::Type optionType) const
const Handle< YieldTermStructure > & riskFreeRate() const
1-D array used in linear algebra.
Definition: array.hpp:52
Concrete date class.
Definition: date.hpp:125
Criteria to end optimization process:
Definition: endcriteria.hpp:40
Shared handle to an observable.
Definition: handle.hpp:41
Framework for calculation on demand and result caching.
Definition: lazyobject.hpp:35
Levenberg-Marquardt optimization method.
template class providing a null value for a given type.
Definition: null.hpp:76
const DefaultType & t
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
Globally accessible relinkable pointer.
framework for calculation on demand and result caching
Levenberg-Marquardt optimization method.
linear interpolation between discrete points
Local volatility term structure base class.
matrix used in linear algebra.
Definition: any.hpp:35
Base option class.
purely virtual base class for market observables
Maps tuple to either the boost or std implementation.