Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
blackvolsurfacebfrr.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 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 blackvolsurfacebfrr.hpp
20 \brief Black volatility surface based on bf/rr quotes
21*/
22
23#pragma once
24
25#include <ql/experimental/fx/deltavolquote.hpp>
26#include <ql/math/interpolation.hpp>
27#include <ql/option.hpp>
28#include <ql/termstructures/volatility/equityfx/blackvoltermstructure.hpp>
29#include <ql/termstructures/yieldtermstructure.hpp>
30#include <ql/time/calendar.hpp>
31#include <ql/time/daycounter.hpp>
32
33namespace QuantExt {
34
35using namespace QuantLib;
36
37namespace detail {
38class SimpleDeltaInterpolatedSmile;
39}
40
41class BlackVolatilitySurfaceBFRR : public BlackVolatilityTermStructure, public LazyObject {
42public:
45 Date referenceDate, const std::vector<Date>& dates, const std::vector<Real>& deltas,
46 const std::vector<std::vector<Real>>& bfQuotes, const std::vector<std::vector<Real>>& rrQuotes,
47 const std::vector<Real>& atmQuotes, const DayCounter& dayCounter, const Calendar& calendar,
48 const Handle<Quote>& spot, const Size spotDays, const Calendar spotCalendar,
49 const Handle<YieldTermStructure>& domesticTS, const Handle<YieldTermStructure>& foreignTS,
50 const DeltaVolQuote::DeltaType dt = DeltaVolQuote::DeltaType::Spot,
51 const DeltaVolQuote::AtmType at = DeltaVolQuote::AtmType::AtmDeltaNeutral,
52 const Period& switchTenor = 2 * Years, const DeltaVolQuote::DeltaType ltdt = DeltaVolQuote::DeltaType::Fwd,
53 const DeltaVolQuote::AtmType ltat = DeltaVolQuote::AtmType::AtmDeltaNeutral,
54 const Option::Type riskReversalInFavorOf = Option::Call, const bool butterflyIsBrokerStyle = true,
56
57 Date maxDate() const override { return Date::maxDate(); }
58 Real minStrike() const override { return 0; }
59 Real maxStrike() const override { return QL_MAX_REAL; }
60
61 const std::vector<QuantLib::Date>& dates() const { return dates_; }
62 const std::vector<Real>& deltas() const { return deltas_; }
63 const std::vector<Real>& currentDeltas() const { return currentDeltas_; }
64 const std::vector<std::vector<Real>>& bfQuotes() const { return bfQuotes_; }
65 const std::vector<std::vector<Real>>& rrQuotes() const { return rrQuotes_; }
66 const std::vector<Real>& atmQuotes() const { return atmQuotes_; }
67 const Handle<Quote>& spot() const { return spot_; }
68 const Handle<YieldTermStructure>& domesticTS() const { return domesticTS_; }
69 const Handle<YieldTermStructure>& foreignTS() const { return foreignTS_; }
70 DeltaVolQuote::DeltaType deltaType() const { return dt_; }
71 DeltaVolQuote::AtmType atmType() const { return at_; }
72 const Period& switchTenor() const { return switchTenor_; }
73 DeltaVolQuote::DeltaType longTermDeltaType() const { return ltdt_; }
74 DeltaVolQuote::AtmType longTermAtmType() const { return ltat_; }
75 Option::Type riskReversalInFavorOf() const { return riskReversalInFavorOf_; }
78
79 const std::vector<bool>& smileHasError() const;
80 const std::vector<std::string>& smileErrorMessage() const;
81
82private:
83 Volatility blackVolImpl(Time t, Real strike) const override;
84 void update() override;
85 void performCalculations() const override;
86 void clearCaches() const;
87
88 std::vector<Date> dates_;
89 std::vector<Real> deltas_;
90 std::vector<std::vector<Real>> bfQuotes_;
91 std::vector<std::vector<Real>> rrQuotes_;
92 std::vector<Real> atmQuotes_;
93 Handle<Quote> spot_;
95 Calendar spotCalendar_;
96 Handle<YieldTermStructure> domesticTS_;
97 Handle<YieldTermStructure> foreignTS_;
98 DeltaVolQuote::DeltaType dt_;
99 DeltaVolQuote::AtmType at_;
101 DeltaVolQuote::DeltaType ltdt_;
102 DeltaVolQuote::AtmType ltat_;
106
108 mutable std::vector<Real> expiryTimes_;
109 mutable std::vector<Date> settlementDates_;
110 mutable std::vector<Real> currentDeltas_;
111
112 mutable std::vector<QuantLib::ext::shared_ptr<detail::SimpleDeltaInterpolatedSmile>> smiles_;
113 mutable std::map<Real, QuantLib::ext::shared_ptr<detail::SimpleDeltaInterpolatedSmile>> cachedInterpolatedSmiles_;
114 mutable std::vector<bool> smileHasError_;
115 mutable std::vector<std::string> smileErrorMessage_;
116};
117
118namespace detail {
119
121public:
122 SimpleDeltaInterpolatedSmile(const Real spot, const Real domDisc, const Real forDisc, const Real expiryTime,
123 const std::vector<Real>& deltas, const std::vector<Real>& putVols,
124 const std::vector<Real>& callVols, const Real atmVol,
125 const DeltaVolQuote::DeltaType dt, const DeltaVolQuote::AtmType at,
126 const BlackVolatilitySurfaceBFRR::SmileInterpolation smileInterpolation,
127 const Real accuracy = 1E-6, const Size maxIterations = 1000);
128
129 Real volatilityAtSimpleDelta(const Real tnp);
130 Real volatility(const Real strike);
131 Real strikeFromDelta(const Option::Type type, const Real delta, const DeltaVolQuote::DeltaType dt);
132 Real atmStrike(const DeltaVolQuote::DeltaType dt, const DeltaVolQuote::AtmType at);
133
134private:
135 Real simpleDeltaFromStrike(const Real strike) const;
136
138 std::vector<Real> deltas_, putVols_, callVols_;
140 DeltaVolQuote::DeltaType dt_;
141 DeltaVolQuote::AtmType at_;
145
147 std::vector<Real> x_, y_;
148 QuantLib::ext::shared_ptr<Interpolation> interpolation_;
149};
150
151QuantLib::ext::shared_ptr<SimpleDeltaInterpolatedSmile>
152createSmile(const Real spot, const Real domDisc, const Real forDisc, const Real expiryTime,
153 const std::vector<Real>& deltas, const std::vector<Real>& bfQuotes, const std::vector<Real>& rrQuotes,
154 const Real atmVol, const DeltaVolQuote::DeltaType dt, const DeltaVolQuote::AtmType at,
155 const Option::Type riskReversalInFavorOf, const bool butterflyIsBrokerStyle,
156 const BlackVolatilitySurfaceBFRR::SmileInterpolation smileInterpolation);
157
158} // namespace detail
159
160} // namespace QuantExt
std::vector< std::string > smileErrorMessage_
DeltaVolQuote::DeltaType longTermDeltaType() const
std::map< Real, QuantLib::ext::shared_ptr< detail::SimpleDeltaInterpolatedSmile > > cachedInterpolatedSmiles_
const std::vector< Real > & atmQuotes() const
std::vector< std::vector< Real > > bfQuotes_
const std::vector< Real > & currentDeltas() const
const std::vector< std::vector< Real > > & rrQuotes() const
DeltaVolQuote::AtmType longTermAtmType() const
SmileInterpolation smileInterpolation() const
Handle< YieldTermStructure > foreignTS_
const std::vector< std::string > & smileErrorMessage() const
const Handle< Quote > & spot() const
Handle< YieldTermStructure > domesticTS_
const std::vector< Real > & deltas() const
const Handle< YieldTermStructure > & domesticTS() const
const Handle< YieldTermStructure > & foreignTS() const
std::vector< std::vector< Real > > rrQuotes_
DeltaVolQuote::DeltaType deltaType() const
DeltaVolQuote::AtmType atmType() const
Volatility blackVolImpl(Time t, Real strike) const override
const std::vector< QuantLib::Date > & dates() const
const std::vector< bool > & smileHasError() const
const std::vector< std::vector< Real > > & bfQuotes() const
std::vector< QuantLib::ext::shared_ptr< detail::SimpleDeltaInterpolatedSmile > > smiles_
Real atmStrike(const DeltaVolQuote::DeltaType dt, const DeltaVolQuote::AtmType at)
Real strikeFromDelta(const Option::Type type, const Real delta, const DeltaVolQuote::DeltaType dt)
BlackVolatilitySurfaceBFRR::SmileInterpolation smileInterpolation_
QuantLib::ext::shared_ptr< Interpolation > interpolation_
QuantLib::ext::shared_ptr< SimpleDeltaInterpolatedSmile > createSmile(const Real spot, const Real domDisc, const Real forDisc, const Real expiryTime, const std::vector< Real > &deltas, const std::vector< Real > &bfQuotes, const std::vector< Real > &rrQuotes, const Real atmVol, const DeltaVolQuote::DeltaType dt, const DeltaVolQuote::AtmType at, const Option::Type riskReversalInFavorOf, const bool butterflyIsBrokerStyle, const BlackVolatilitySurfaceBFRR::SmileInterpolation smileInterpolation)