-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fx options utils - BlackVolatilitySurfaceDelta class
#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
Open
paolodelia99
wants to merge
11
commits into
lballabio:master
Choose a base branch
from
paolodelia99:feature/fx-options-utils
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,006
−24
Open
Changes from 9 commits
Commits
Show all changes
11 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 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 | ||
| <[email protected]>. 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, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "extrapolatation" (here and everywhere) |
||
| 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An anonymous namespace in a header file doesn't make a lot of sense—
namespace detailis better.