-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add BlackVolatilitySurfaceDelta class for FX options
#2368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lballabio
merged 32 commits into
lballabio:master
from
paolodelia99:feature/fx-options-utils
Mar 13, 2026
Merged
Changes from 9 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
490046d
Added first fx vol utils classes from ORE
paolodelia99 be091ed
Add unit test for BlackVolatilitySurfaceDelta with non-constant volat…
paolodelia99 5d346f8
make InterpolatedFxSmileSection lazy, possibility to pass handle<quot…
paolodelia99 93c57cb
Fix compilation errors
paolodelia99 dddeafd
Replace InterpolatedFxSmileSection with already present InterpolatedS…
paolodelia99 94f4762
renaming vars, added docs string for the blackvolsurfacedelta
paolodelia99 3e61f8d
set flatStrikeExtrapolation to false, add checkStrike sanity check in…
paolodelia99 9a58b8a
fix win compilation error, in generate doc error
paolodelia99 813c1bf
Updated initial comment in the tests
paolodelia99 ff66504
Fix various oversights and add interpolatedsmilesection first tests
paolodelia99 8e6afe6
no anonymous namespace anymore, removed #pragma once
paolodelia99 856b096
Correct logical error when creating InterpolatedSmileSection in tests
paolodelia99 57372ce
Update old license links
lballabio-bot 12c44d1
Update copyright list in license
lballabio-bot 2494b90
Reorder some params of the blackvolsurfacedelta ctor
paolodelia99 239504d
Remove obsolete rights attribution
lballabio ce07bb4
Merge branch 'master' into feature/fx-options-utils
lballabio ddfc9be
Fix typo in function names
lballabio a068265
Refactoring according to suggestions: BlackVolTimeExtrapolation inste…
paolodelia99 d74ebac
Fix docstring in blackvolsurfacedelta class
paolodelia99 859f97b
Move BlackVolTimeExtrapolation to own file.
lballabio 7ac8677
Don't make the common case look like an early exit
lballabio 19a597a
Add missing header
lballabio 38da695
Use linear extrapolation in variance
lballabio becd335
Merge branch 'master' into feature/fx-options-utils
lballabio cd132fc
Clean up inclusions
lballabio 3881c9c
Let the inner interpolator extrapolate when needed
lballabio a84e248
Standard syntax for enum
lballabio 86a07d8
Time extrapolation tests
lballabio 569052a
Prevent negative volatility when extrapolating
lballabio e344bfc
Add smile interpolation/extrapolation test
lballabio d9af61e
Clean up test messages
lballabio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
ql/termstructures/volatility/equityfx/blackvariancetimeextrapolation.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
|
|
||
| /* | ||
| Copyright (C) 2025 AcadiaSoft Inc. | ||
|
|
||
| This file is part of QuantLib, a free-software/open-source library | ||
| for financial quantitative analysts and developers - http://quantlib.org/ | ||
|
|
||
| QuantLib is free software: you can redistribute it and/or modify it | ||
| under the terms of the QuantLib license. You should have received a | ||
| copy of the license along with this program; if not, please email | ||
| <quantlib-dev@lists.sf.net>. The license is also available online at | ||
| <http://quantlib.org/license.shtml>. | ||
|
|
||
| This program is distributed in the hope that it will be useful, but WITHOUT | ||
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| FOR A PARTICULAR PURPOSE. See the license for more details. | ||
| */ | ||
|
|
||
| /*! \file blackvariancetimeextrapolation.hpp | ||
| \brief Utility function for time extrapolation in Black volatility in black variance term structures | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include <array> | ||
| #include <functional> | ||
| #include <ql/math/comparison.hpp> | ||
| #include <ql/math/interpolation.hpp> | ||
| #include <ql/math/interpolations/interpolation2d.hpp> | ||
| #include <ql/math/interpolations/linearinterpolation.hpp> | ||
|
|
||
| namespace QuantLib { | ||
|
|
||
| namespace { | ||
| Real linearExtrapolation(const double t, const std::array<double, 2>& times, const std::array<double, 2>& variances); | ||
|
|
||
| inline Real linearExtrapolation(const double t, const std::array<double, 2>& times, | ||
| const std::array<double, 2>& variances) { | ||
| QL_REQUIRE(t > times[1], "t must be greater than times[1]"); | ||
| QL_REQUIRE(times[1] > times[0], "times must be sorted"); | ||
| QL_REQUIRE(variances[1] >= variances[0], "variances must be non-decreasing"); | ||
| std::array<double, 2> vols; | ||
| vols[0] = close_enough(times[0], 0.0) ? 0.0 : std::sqrt(variances[0] / times[0]); | ||
| vols[1] = close_enough(times[1], 0.0) ? 0.0 : std::sqrt(variances[1] / times[1]); | ||
| LinearInterpolation interpolation(times.begin(), times.end(), vols.begin()); | ||
| return std::max(interpolation(t, true), 0.0); | ||
| } | ||
| } // namespace | ||
|
|
||
|
|
||
|
|
||
| //! Extrapolate black variance using flat vol extrapolation in time direction | ||
| Real timeExtrapolatationBlackVarianceFlat(const Time t, const std::vector<double>& times, | ||
|
||
| const Interpolation& varianceCurve); | ||
|
|
||
| //! Extrapolate black variance using flat vol extrapolation in time direction | ||
| template <typename F> | ||
| Real timeExtrapolatationBlackVarianceFlat(const Time t, const Real strike, const std::vector<double>& times, | ||
| const F& varianceSurface) { | ||
| return std::max(varianceSurface(times.back(), strike, true), 0.0) / times.back() * t; | ||
| } | ||
|
|
||
|
|
||
| //! Extrapolate black variance in vol space and time direction using interpolation | ||
| //! Takes black variances convert them to volatilities and then linearly extrapolates | ||
| //! the volatilities in time direction | ||
| Real timeExtrapolatationBlackVarianceInVolatility(const Time t, const std::vector<double>& times, | ||
| const Interpolation& varianceCurve); | ||
|
|
||
| //! Extrapolate black variance in vol space and time direction using interpolation | ||
| //! Takes black variances convert them to volatilities and then linearly extrapolates | ||
| //! the volatilities in time direction | ||
| template <typename F> | ||
| Real timeExtrapolatationBlackVarianceInVolatility(const Time t, const Real strike, const std::vector<double>& times, | ||
| const F& varianceSurface) { | ||
| Size ind1 = times.size() - 2; | ||
| Size ind2 = times.size() - 1; | ||
| std::array<Real, 2> xs{times[ind1], times[ind2]}; | ||
| std::array<Real, 2> variances; | ||
| variances[0] = varianceSurface(xs[0], strike, true); | ||
| variances[1] = varianceSurface(xs[1], strike, true); | ||
| Real v = linearExtrapolation(t, xs, variances); | ||
| return v * v * t; | ||
| } | ||
|
|
||
| inline Real timeExtrapolatationBlackVarianceFlat(const Time t, const std::vector<double>& times, | ||
| const Interpolation& varianceCurve) { | ||
| return std::max(varianceCurve(times.back(), true), 0.0) / times.back() * t; | ||
| } | ||
|
|
||
| inline Real timeExtrapolatationBlackVarianceInVolatility(const Time t, const std::vector<double>& times, | ||
| const Interpolation& varianceCurve) { | ||
| Size ind1 = times.size() - 2; | ||
| Size ind2 = times.size() - 1; | ||
| std::array<Real, 2> xs{times[ind1], times[ind2]}; | ||
| std::array<Real, 2> variances; | ||
| variances[0] = varianceCurve(xs[0], true); | ||
| variances[1] = varianceCurve(xs[1], true); | ||
| Real v = linearExtrapolation(t, xs, variances); | ||
| return v * v * t; | ||
| } | ||
| } // namespace QuantLib | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.