QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
localvolrndcalculator.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2015 Johannes Göttker-Schnetmann
5 Copyright (C) 2015 Klaus Spanderen
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
25#ifndef quantlib_local_vol_rnd_calculator_hpp
26#define quantlib_local_vol_rnd_calculator_hpp
27
28#include <ql/math/matrix.hpp>
29#include <ql/quotes/simplequote.hpp>
30#include <ql/patterns/lazyobject.hpp>
31#include <ql/termstructures/yieldtermstructure.hpp>
32#include <ql/methods/finitedifferences/meshers/fdm1dmesher.hpp>
33#include <ql/methods/finitedifferences/utilities/riskneutraldensitycalculator.hpp>
34
35#include <vector>
36
37namespace QuantLib {
38 class TimeGrid;
39 class Fdm1dMesher;
40 class Interpolation;
41 class LocalVolTermStructure;
42
44 public LazyObject {
45 public:
46 LocalVolRNDCalculator(ext::shared_ptr<Quote> spot,
47 ext::shared_ptr<YieldTermStructure> rTS,
48 ext::shared_ptr<YieldTermStructure> qTS,
49 const ext::shared_ptr<LocalVolTermStructure>& localVol,
50 Size xGrid = 101,
51 Size tGrid = 51,
52 Real x0Density = 0.1,
53 Real localVolProbEps = 1e-6,
54 Size maxIter = 10000,
55 Time gaussianStepSize = -Null<Time>());
56
57 LocalVolRNDCalculator(ext::shared_ptr<Quote> spot,
58 ext::shared_ptr<YieldTermStructure> rTS,
59 ext::shared_ptr<YieldTermStructure> qTS,
60 ext::shared_ptr<LocalVolTermStructure> localVol,
61 const ext::shared_ptr<TimeGrid>& timeGrid,
62 Size xGrid = 101,
63 Real x0Density = 0.1,
64 Real eps = 1e-6,
65 Size maxIter = 10000,
66 Time gaussianStepSize = -Null<Time>());
67
68 Real pdf(Real x, Time t) const override;
69 Real cdf(Real x, Time t) const override;
70 Real invcdf(Real p, Time t) const override;
71
72 ext::shared_ptr<TimeGrid> timeGrid() const;
73 ext::shared_ptr<Fdm1dMesher> mesher(Time t) const;
74 std::vector<Size> rescaleTimeSteps() const;
75
76 protected:
77 void performCalculations() const override;
78
79 private:
81 Array rescalePDF(const Array& x, const Array& p) const;
82
83
89 const ext::shared_ptr<Quote> spot_;
90 const ext::shared_ptr<LocalVolTermStructure> localVol_;
91 const ext::shared_ptr<YieldTermStructure> rTS_;
92 const ext::shared_ptr<YieldTermStructure> qTS_;
93 const ext::shared_ptr<TimeGrid> timeGrid_;
94 mutable std::vector<ext::shared_ptr<Fdm1dMesher> > xm_;
95 const ext::shared_ptr<Matrix> pm_;
96 mutable std::vector<Size> rescaleTimeSteps_;
97 mutable std::vector<ext::shared_ptr<Interpolation> > pFct_;
98 };
99}
100
101#endif
1-D array used in linear algebra.
Definition: array.hpp:52
Framework for calculation on demand and result caching.
Definition: lazyobject.hpp:35
std::vector< ext::shared_ptr< Interpolation > > pFct_
const ext::shared_ptr< Quote > spot_
Array rescalePDF(const Array &x, const Array &p) const
const ext::shared_ptr< YieldTermStructure > qTS_
std::vector< Size > rescaleTimeSteps() const
ext::shared_ptr< TimeGrid > timeGrid() const
Real pdf(Real x, Time t) const override
Real cdf(Real x, Time t) const override
const ext::shared_ptr< YieldTermStructure > rTS_
const ext::shared_ptr< TimeGrid > timeGrid_
const ext::shared_ptr< Matrix > pm_
ext::shared_ptr< Fdm1dMesher > mesher(Time t) const
std::vector< ext::shared_ptr< Fdm1dMesher > > xm_
Real invcdf(Real p, Time t) const override
Real probabilityInterpolation(Size idx, Real x) const
const ext::shared_ptr< LocalVolTermStructure > localVol_
template class providing a null value for a given type.
Definition: null.hpp:76
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35