Skip to content

Commit

Permalink
Restore backward compatibility (#1939)
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio authored Apr 2, 2024
2 parents 2f384b1 + c71e253 commit 0e68922
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Examples/Gaussian1dModels/Gaussian1dModels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ void printBasket(
"==================" << std::endl;
for (const auto& j : basket) {
auto helper = ext::dynamic_pointer_cast<SwaptionHelper>(j);
Date endDate = helper->underlyingSwap()->fixedSchedule().dates().back();
Real nominal = helper->underlyingSwap()->nominal();
Date endDate = helper->underlying()->fixedSchedule().dates().back();
Real nominal = helper->underlying()->nominal();
Real vol = helper->volatility()->value();
Real rate = helper->underlyingSwap()->fixedRate();
Real rate = helper->underlying()->fixedRate();
Date expiry = helper->swaption()->exercise()->date(0);
Swap::Type type = helper->swaption()->type();
std::ostringstream expiryString, endDateString;
Expand Down
2 changes: 1 addition & 1 deletion ql/experimental/basismodels/swaptioncfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace QuantLib {
SwaptionCashFlows::SwaptionCashFlows(const ext::shared_ptr<Swaption>& swaption,
const Handle<YieldTermStructure>& discountCurve,
bool contTenorSpread)
: SwapCashFlows(swaption->underlyingSwap(), discountCurve, contTenorSpread),
: SwapCashFlows(swaption->underlying(), discountCurve, contTenorSpread),
swaption_(swaption) {
// assemble raw cash flow data...
Actual365Fixed dc;
Expand Down
2 changes: 1 addition & 1 deletion ql/instruments/nonstandardswaption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace QuantLib {
: Option(ext::shared_ptr<Payoff>(),
const_cast<Swaption &>(fromSwaption).exercise()),
swap_(ext::make_shared<NonstandardSwap>(
*fromSwaption.underlyingSwap())),
*fromSwaption.underlying())),
settlementType_(fromSwaption.settlementType()),
settlementMethod_(fromSwaption.settlementMethod()) {

Expand Down
2 changes: 2 additions & 0 deletions ql/instruments/swaption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ namespace QuantLib {
// wouldn't recalculate. To avoid this, we override the
// default behavior of the underlying swap.
swap_->alwaysForwardNotifications();

vanilla_ = ext::dynamic_pointer_cast<VanillaSwap>(swap_);
}

void Swaption::deepUpdate() {
Expand Down
13 changes: 12 additions & 1 deletion ql/instruments/swaption.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <ql/option.hpp>
#include <ql/instruments/fixedvsfloatingswap.hpp>
#include <ql/instruments/vanillaswap.hpp>
#include <ql/termstructures/yieldtermstructure.hpp>
#include <ql/termstructures/volatility/volatilitytype.hpp>

Expand Down Expand Up @@ -108,9 +109,17 @@ namespace QuantLib {
return settlementMethod_;
}
Swap::Type type() const { return swap_->type(); }
const ext::shared_ptr<FixedVsFloatingSwap>& underlyingSwap() const {
const ext::shared_ptr<FixedVsFloatingSwap>& underlying() const {
return swap_;
}
/*! \deprecated Use the Swaption::underlying method instead.
Deprecated in version 1.34.
*/
[[deprecated("Use the Swaption::underlying method instead")]]
const ext::shared_ptr<VanillaSwap>& underlyingSwap() const {
QL_REQUIRE(vanilla_, "underlying is not a vanilla swap");
return vanilla_;
}
//@}
//! implied volatility
Volatility impliedVolatility(
Expand All @@ -129,6 +138,8 @@ namespace QuantLib {
//Handle<YieldTermStructure> termStructure_;
Settlement::Type settlementType_;
Settlement::Method settlementMethod_;
// until we remove underlyingSwap();
ext::shared_ptr<VanillaSwap> vanilla_;
};

//! %Arguments for swaption calculation
Expand Down
12 changes: 11 additions & 1 deletion ql/models/shortrate/calibrationhelpers/swaptionhelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,20 @@ namespace QuantLib {
Real modelValue() const override;
Real blackPrice(Volatility volatility) const override;

ext::shared_ptr<FixedVsFloatingSwap> underlyingSwap() const {
const ext::shared_ptr<FixedVsFloatingSwap>& underlying() const {
calculate();
return swap_;
}
/*! \deprecated Use the SwaptionHelper::underlying method instead.
Deprecated in version 1.34.
*/
[[deprecated("Use the SwaptionHelper::underlying method instead")]]
ext::shared_ptr<VanillaSwap> underlyingSwap() const {
calculate();
auto vanilla = ext::dynamic_pointer_cast<VanillaSwap>(swap_);
QL_REQUIRE(vanilla, "underlying is not a vanilla swap");
return vanilla;
}
ext::shared_ptr<Swaption> swaption() const { calculate(); return swaption_; }

private:
Expand Down
4 changes: 2 additions & 2 deletions test-suite/swaption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ BOOST_AUTO_TEST_CASE(testVega) {
<< "\n strike: " << io::rate(strike)
<< "\n settlement: " << types[h]
<< "\n nominal: "
<< swaption->underlyingSwap()->nominal()
<< swaption->underlying()->nominal()
<< "\n npv: " << swaptionNPV
<< "\n calculated vega: " << analyticalVegaPerPoint
<< "\n expected vega: " << numericalVegaPerPoint
Expand Down Expand Up @@ -1107,7 +1107,7 @@ void checkSwaptionDelta(bool useBachelierVol)
<< "\n swap tenor: " << length << "\n strike: "
<< strike << "\n settlement: " << types[h]
<< "\n method: " << methods[h]
<< "\n nominal: " << swaption->underlyingSwap()->nominal()
<< "\n nominal: " << swaption->underlying()->nominal()
<< "\n npv: " << value << "\n calculated delta: "
<< delta << "\n expected delta: " << approxDelta);
}
Expand Down
4 changes: 2 additions & 2 deletions test-suite/swaptionvolatilitymatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ struct CommonVars {
"\nactual option date: " << exerciseDate <<
"\n exp. option date: " << vol->optionDates()[i]);

Date start = swaption.underlyingSwap()->startDate();
Date end = swaption.underlyingSwap()->maturityDate();
Date start = swaption.underlying()->startDate();
Date end = swaption.underlying()->maturityDate();
Time swapLength2 = vol->swapLength(start, end);
if (!close(swapLength2,swapLength))
BOOST_FAIL("\nswapLength failure for " <<
Expand Down

0 comments on commit 0e68922

Please sign in to comment.