Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
kienitzlawsonswaynesabrpdedensity.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2024 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file kienitzlawsonswaynesabrpdedensity.hpp
20 \brief Adaption of VBA code by Jörg Kienitz, 2017, to create a SABR density with PDE methods
21
22 \ingroup termstructures
23*/
24
25#pragma once
26
27#include <ql/types.hpp>
28#include <ql/math/array.hpp>
29
30namespace QuantExt {
31
32using QuantLib::Real;
33using QuantLib::Size;
34using QuantLib::Array;
35
37public:
38 KienitzLawsonSwayneSabrPdeDensity(const Real alpha, const Real beta, const Real nu, const Real rho,
39 const Real forward, const Real expiryTime, const Real displacement,
40 const Size zSteps, const Size tSteps, const Real nStdDev);
41
42 // inspectors
43 Real alpha() const { return alpha_; }
44 Real beta() const { return beta_; }
45 Real nu() const { return nu_; }
46 Real rho() const { return rho_; }
47 Real forward() const { return forward_; }
48 Real expiryTime() const { return expiryTime_; }
49 Real displacement() const { return displacement_; }
50 Size zSteps() const { return zSteps_; }
51 Size tSteps() const { return tSteps_; }
52 Real nStdDev() const { return nStdDev_; }
53
54 // vanilla prices
55 std::vector<Real> callPrices(const std::vector<Real>& strikes) const;
56 std::vector<Real> putPrices(const std::vector<Real>& strikes) const;
57
58 // strike at which a given cumulative probability is hit
59 Real inverseCumulative(const Real p) const;
60
61 // results
62 const Array& sabrProb() const { return SABR_Prob_Vec_; }
63 Real zMin() const { return zMin_; }
64 Real zMax() const { return zMax_; }
65 Real hh() const { return hh_; }
66 Real pL() const { return pL_; }
67 Real pR() const { return pR_; }
68 Real theta0() const { return theta0_; }
69
70 // variable transformations
71 Real yf(const Real f) const;
72 Real fy(const Real y) const;
73 Real yz(const Real z) const;
74 Real zy(const Real y) const;
75
76private:
77 void calculate();
78 // VBA helper functions
79 void PDE_method(const Array& fm, const Array& Ccm, const Array& Gamma_Vec, const Real dt, const Size Nj);
80 void solveTimeStep_LS(const Array& fm, const Array& cm, const Array& Em, const Real dt, const Array& PP_in,
81 const Real PL_in, const Real PR_in, const Size n, Array& PP_out, Real& PL_out, Real& PR_out);
82 void tridag(const Array& a, const Array& b, const Array& c, const Array& R, Array& u, const Size n,
83 const bool firstLastRZero);
84 // inputs
86 const Size zSteps_, tSteps_;
87 const Real nStdDev_;
88 // outputs
91};
92
93} // namespace QuantExt
std::vector< Real > callPrices(const std::vector< Real > &strikes) const
void solveTimeStep_LS(const Array &fm, const Array &cm, const Array &Em, const Real dt, const Array &PP_in, const Real PL_in, const Real PR_in, const Size n, Array &PP_out, Real &PL_out, Real &PR_out)
void PDE_method(const Array &fm, const Array &Ccm, const Array &Gamma_Vec, const Real dt, const Size Nj)
std::vector< Real > putPrices(const std::vector< Real > &strikes) const
void tridag(const Array &a, const Array &b, const Array &c, const Array &R, Array &u, const Size n, const bool firstLastRZero)
vector< Real > strikes