Skip to content
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

Deprecate some unused parts of the old FD framework #2091

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ql/grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,28 @@

namespace QuantLib {

/*! \deprecated Part of the old FD framework; copy this function
in your codebase if needed.
Deprecated in version 1.37.
*/
[[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]]
Array CenteredGrid(Real center, Real dx, Size steps);

/*! \deprecated Part of the old FD framework; copy this function
in your codebase if needed.
Deprecated in version 1.37.
*/
[[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]]
Array BoundedGrid(Real xMin, Real xMax, Size steps);

/*! \deprecated Part of the old FD framework; copy this function
in your codebase if needed.
Deprecated in version 1.37.
*/
[[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]]
Array BoundedLogGrid(Real xMin, Real xMax, Size steps);


// inline definitions

inline Array CenteredGrid(Real center, Real dx, Size steps) {
Expand Down
19 changes: 14 additions & 5 deletions ql/math/transformedgrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@

namespace QuantLib {

//! transformed grid
/*! This package encapuslates an array of grid points. It is used primarily
in PDE calculations.
/*! \deprecated Part of the old FD framework; copy this function
in your codebase if needed.
Deprecated in version 1.37.
*/
class TransformedGrid {
class [[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]] TransformedGrid {
public:
TransformedGrid (const Array &grid) :
grid_(grid), transformedGrid_(grid),
Expand Down Expand Up @@ -93,14 +93,23 @@ namespace QuantLib {
Array dx_;
};

class LogGrid : public TransformedGrid {

QL_DEPRECATED_DISABLE_WARNING

/*! \deprecated Part of the old FD framework; copy this function
in your codebase if needed.
Deprecated in version 1.37.
*/
class [[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]] LogGrid : public TransformedGrid {
public:
LogGrid(const Array &grid) :
TransformedGrid(grid, [](Real x) -> Real { return std::log(x); }){};
const Array & logGridArray() const { return transformedGridArray();}
Real logGrid(Size i) const { return transformedGrid(i);}
};

QL_DEPRECATED_ENABLE_WARNING

}


Expand Down
4 changes: 4 additions & 0 deletions ql/methods/finitedifferences/bsmoperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

namespace QuantLib {

QL_DEPRECATED_DISABLE_WARNING

BSMOperator::BSMOperator(Size size, Real dx, Rate r,
Rate q, Volatility sigma)
: TridiagonalOperator(size) {
Expand All @@ -49,4 +51,6 @@ namespace QuantLib {
}
}

QL_DEPRECATED_ENABLE_WARNING

}
8 changes: 5 additions & 3 deletions ql/methods/finitedifferences/bsmoperator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@

namespace QuantLib {

//! Black-Scholes-Merton differential operator
/*! \ingroup findiff */
class BSMOperator : public TridiagonalOperator {
/*! \deprecated Part of the old FD framework; copy this function
in your codebase if needed.
Deprecated in version 1.37.
*/
class [[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]] BSMOperator : public TridiagonalOperator {
public:
BSMOperator() = default;
BSMOperator(Size size, Real dx, Rate r, Rate q, Volatility sigma);
Expand Down
30 changes: 26 additions & 4 deletions ql/methods/finitedifferences/pde.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@
#include <ql/math/transformedgrid.hpp>

namespace QuantLib {
class PdeSecondOrderParabolic {

/*! \deprecated Part of the old FD framework; copy this function
in your codebase if needed.
Deprecated in version 1.37.
*/
class [[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]] PdeSecondOrderParabolic {
public:
virtual ~PdeSecondOrderParabolic() = default;
virtual Real diffusion(Time t, Real x) const = 0;
virtual Real drift(Time t, Real x) const = 0;
virtual Real discount(Time t, Real x) const = 0;
QL_DEPRECATED_DISABLE_WARNING
virtual void
generateOperator(Time t, const TransformedGrid& tg, TridiagonalOperator& L) const {
for (Size i = 1; i < tg.size() - 1; i++) {
Expand All @@ -51,8 +57,12 @@ namespace QuantLib {
}
};

/*! \deprecated Part of the old FD framework; copy this function
in your codebase if needed.
Deprecated in version 1.37.
*/
template <class PdeClass>
class PdeConstantCoeff : public PdeSecondOrderParabolic {
class [[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]] PdeConstantCoeff : public PdeSecondOrderParabolic {
public:
PdeConstantCoeff(const typename PdeClass::argument_type &process,
Time t, Real x) {
Expand All @@ -71,8 +81,14 @@ namespace QuantLib {
Real discount_;
};

QL_DEPRECATED_ENABLE_WARNING

/*! \deprecated Part of the old FD framework; copy this function
in your codebase if needed.
Deprecated in version 1.37.
*/
template <class PdeClass>
class GenericTimeSetter:public TridiagonalOperator::TimeSetter {
class [[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]] GenericTimeSetter:public TridiagonalOperator::TimeSetter {
public:
template <class T>
GenericTimeSetter(const Array &grid, T process) :
Expand All @@ -86,17 +102,23 @@ namespace QuantLib {
PdeClass pde_;
};

/*! \deprecated Part of the old FD framework; copy this function
in your codebase if needed.
Deprecated in version 1.37.
*/
template <class PdeClass>
class PdeOperator:public TridiagonalOperator {
class [[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]] PdeOperator:public TridiagonalOperator {
public:
template <class T>
PdeOperator(const Array& grid,
T process,
Time residualTime = 0.0) :
TridiagonalOperator(grid.size()) {
QL_DEPRECATED_DISABLE_WARNING
timeSetter_ =
ext::shared_ptr<GenericTimeSetter<PdeClass> >(
new GenericTimeSetter<PdeClass>(grid, process));
QL_DEPRECATED_ENABLE_WARNING
setTime(residualTime);
}
};
Expand Down
13 changes: 10 additions & 3 deletions ql/methods/finitedifferences/pdebsm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@

namespace QuantLib {

class PdeBSM : public PdeSecondOrderParabolic {
QL_DEPRECATED_DISABLE_WARNING

/*! \deprecated Part of the old FD framework; copy this function
in your codebase if needed.
Deprecated in version 1.37.
*/
class [[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]] PdeBSM : public PdeSecondOrderParabolic {
public:
typedef ext::shared_ptr<GeneralizedBlackScholesProcess>
argument_type;
typedef ext::shared_ptr<GeneralizedBlackScholesProcess> argument_type;
typedef LogGrid grid_type;
PdeBSM(argument_type process) : process_(std::move(process)){};
Real diffusion(Time t, Real x) const override { return process_->diffusion(t, x); }
Expand All @@ -48,6 +53,8 @@ namespace QuantLib {
const argument_type process_;
};

QL_DEPRECATED_ENABLE_WARNING

}


Expand Down
6 changes: 6 additions & 0 deletions test-suite/operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ BOOST_AUTO_TEST_CASE(testConsistency) {
BOOST_AUTO_TEST_CASE(testBSMOperatorConsistency) {
BOOST_TEST_MESSAGE("Testing consistency of BSM operators...");

QL_DEPRECATED_DISABLE_WARNING

Array grid(10);
Real price = 20.0;
Real factor = 1.1;
Expand Down Expand Up @@ -198,6 +200,7 @@ BOOST_AUTO_TEST_CASE(testBSMOperatorConsistency) {
Handle<YieldTermStructure>(qTS),
Handle<YieldTermStructure>(rTS),
Handle<BlackVolTermStructure>(volTS)));

PdeOperator<PdeBSM> op2(grid, stochProcess, residualTime);

Real tolerance = 1.0e-6;
Expand All @@ -222,6 +225,9 @@ BOOST_AUTO_TEST_CASE(testBSMOperatorConsistency) {
<< op2.upperDiagonal()[i]);
}
}

QL_DEPRECATED_ENABLE_WARNING

}

BOOST_AUTO_TEST_SUITE_END()
Expand Down
5 changes: 5 additions & 0 deletions test-suite/transformedgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ BOOST_AUTO_TEST_CASE(testConstruction) {

BOOST_TEST_MESSAGE("Testing transformed grid construction...");

QL_DEPRECATED_DISABLE_WARNING

PlusOne p1;
Array grid = BoundedGrid(0, 100, 100);
TransformedGrid tg(grid, p1);
Expand All @@ -48,6 +50,9 @@ BOOST_AUTO_TEST_CASE(testConstruction) {

if (std::fabs(tg.transformedGrid(0) - 1.0) > 1e-5)
BOOST_ERROR("grid transformation failed");

QL_DEPRECATED_ENABLE_WARNING

}

BOOST_AUTO_TEST_SUITE_END()
Expand Down
Loading