Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
sabrparametricvolatility.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 sabrparametricvolatility.hpp
20 \brief sabr volatility structure
21*/
22
23#pragma once
24
26
27#include <ql/math/interpolations/interpolation2d.hpp>
28
29namespace QuantExt {
30
32public:
33 enum class ModelVariant {
39 FlochKennedy = 5
40 };
41
42 /*! modelParameters are given by (tte, underlyingLen) as a vector of parameter values and
43 whether the values are fixed */
45 const ModelVariant modelVariant, const std::vector<MarketSmile> marketSmiles,
46 const MarketModelType marketModelType, const MarketQuoteType inputMarketQuoteType,
47 const QuantLib::Handle<QuantLib::YieldTermStructure> discountCurve,
48 const std::map<std::pair<QuantLib::Real, QuantLib::Real>, std::vector<std::pair<Real, bool>>> modelParameters =
49 {},
50 const QuantLib::Size maxCalibrationAttempts = 10, const QuantLib::Real exitEarlyErrorThreshold = 0.005,
51 const QuantLib::Real maxAcceptableError = 0.05);
52
53 QuantLib::Real
54 evaluate(const QuantLib::Real timeToExpiry, const QuantLib::Real underlyingLength, const QuantLib::Real strike,
55 const QuantLib::Real forward, const MarketQuoteType outputMarketQuoteType,
56 const QuantLib::Real outputLognormalShift = QuantLib::Null<QuantLib::Real>(),
57 const boost::optional<QuantLib::Option::Type> outputOptionType = boost::none) const override;
58
59 // the calculated grid of option expiries and the underlying lenghts
60 const std::vector<Real>& timeToEpiries() const;
61 const std::vector<Real>& underlyingLenghts() const;
62 // calibrated or interpolated model parameters (rows = underlying lenghts, cols = option expiries)
63 const QuantLib::Matrix& alpha() const { return alpha_; }
64 const QuantLib::Matrix& beta() const { return beta_; }
65 const QuantLib::Matrix& nu() const { return nu_; }
66 const QuantLib::Matrix& rho() const { return rho_; }
67 const QuantLib::Matrix& lognormalShift() const { return lognormalShift_; }
68 const QuantLib::Matrix& numberOfCalibrationAttempts() const { return numberOfCalibrationAttempts_; }
69 // calibration error
70 const QuantLib::Matrix& calibrationError() const { return calibrationError_; }
71 // indicator whether smile params were interpolated (1) or calibrated (0)
72 const QuantLib::Matrix& isInterpolated() const { return isInterpolated_; }
73
74private:
75 static constexpr double eps1 = .0000001;
76 static constexpr double eps2 = .9999;
77 static constexpr double max_nvol_equiv = 0.02;
78 static constexpr double max_nu = 2.0;
79
80 void calculate();
81
82 std::vector<std::pair<Real, bool>> defaultModelParameters() const;
83 std::vector<Real> getGuess(const std::vector<std::pair<Real, bool>>& params, const std::vector<Real>& randomSeq,
84 const Real forward, const Real lognormalShift) const;
86 std::vector<Real> direct(const std::vector<Real>& x, const Real forward, const Real lognormalShift) const;
87 std::vector<Real> inverse(const std::vector<Real>& y, const Real forward, const Real lognormalShift) const;
88 std::vector<Real> evaluateSabr(const std::vector<Real>& params, const Real forward, const Real timeToExpiry,
89 const Real lognormalShift, const std::vector<Real>& strikes) const;
90 std::tuple<std::vector<Real>, Real, QuantLib::Size>
91 calibrateModelParameters(const MarketSmile& marketSmile, const std::vector<std::pair<Real, bool>>& params) const;
92
94 std::map<std::pair<QuantLib::Real, QuantLib::Real>, std::vector<std::pair<Real, bool>>> modelParameters_;
97 QuantLib::Real maxAcceptableError_;
98
99 mutable std::map<std::pair<Real, Real>, std::vector<Real>> calibratedSabrParams_;
100 mutable std::map<std::pair<Real, Real>, Real> lognormalShifts_;
101 mutable std::map<std::pair<Real, Real>, Real> calibrationErrors_;
102 mutable std::map<std::pair<Real, Real>, QuantLib::Size> noOfAttempts_;
103
104 mutable std::vector<Real> underlyingLengths_, timeToExpiries_;
110};
111
112} // namespace QuantExt
const std::vector< Real > & timeToEpiries() const
const QuantLib::Matrix & calibrationError() const
const QuantLib::Matrix & rho() const
QuantLib::Interpolation2D lognormalShiftInterpolation_
std::vector< std::pair< Real, bool > > defaultModelParameters() const
const QuantLib::Matrix & alpha() const
std::vector< Real > evaluateSabr(const std::vector< Real > &params, const Real forward, const Real timeToExpiry, const Real lognormalShift, const std::vector< Real > &strikes) const
std::map< std::pair< Real, Real >, Real > calibrationErrors_
const QuantLib::Matrix & beta() const
const QuantLib::Matrix & lognormalShift() const
std::vector< Real > inverse(const std::vector< Real > &y, const Real forward, const Real lognormalShift) const
QuantLib::Real evaluate(const QuantLib::Real timeToExpiry, const QuantLib::Real underlyingLength, const QuantLib::Real strike, const QuantLib::Real forward, const MarketQuoteType outputMarketQuoteType, const QuantLib::Real outputLognormalShift=QuantLib::Null< QuantLib::Real >(), const boost::optional< QuantLib::Option::Type > outputOptionType=boost::none) const override
std::map< std::pair< Real, Real >, QuantLib::Size > noOfAttempts_
const std::vector< Real > & underlyingLenghts() const
const QuantLib::Matrix & numberOfCalibrationAttempts() const
std::map< std::pair< Real, Real >, std::vector< Real > > calibratedSabrParams_
std::vector< Real > getGuess(const std::vector< std::pair< Real, bool > > &params, const std::vector< Real > &randomSeq, const Real forward, const Real lognormalShift) const
const QuantLib::Matrix & isInterpolated() const
std::map< std::pair< QuantLib::Real, QuantLib::Real >, std::vector< std::pair< Real, bool > > > modelParameters_
const QuantLib::Matrix & nu() const
std::tuple< std::vector< Real >, Real, QuantLib::Size > calibrateModelParameters(const MarketSmile &marketSmile, const std::vector< std::pair< Real, bool > > &params) const
std::map< std::pair< Real, Real >, Real > lognormalShifts_
std::vector< Real > direct(const std::vector< Real > &x, const Real forward, const Real lognormalShift) const
ParametricVolatility::MarketQuoteType preferredOutputQuoteType() const
cross-asset, generic volatility structure
vector< Real > strikes