Skip to content

Commit 9ff0542

Browse files
authored
allow swaptions to take OvernightIndexedSwap (#1593)
2 parents d6f6c13 + 9b4efa3 commit 9ff0542

File tree

22 files changed

+375
-151
lines changed

22 files changed

+375
-151
lines changed

Examples/BermudanSwaption/BermudanSwaption.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#if !defined(BOOST_ALL_NO_LIB) && defined(BOOST_MSVC)
2424
# include <ql/auto_link.hpp>
2525
#endif
26+
#include <ql/instruments/vanillaswap.hpp>
2627
#include <ql/instruments/swaption.hpp>
2728
#include <ql/pricingengines/swap/discountingswapengine.hpp>
2829
#include <ql/pricingengines/swaption/treeswaptionengine.hpp>

ql/cashflows/overnightindexedcoupon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ namespace QuantLib {
153153
overnightIndex,
154154
gearing, spread,
155155
refPeriodStart, refPeriodEnd,
156-
dayCounter, false) {
156+
dayCounter, false), averagingMethod_(averagingMethod) {
157157

158158
// value dates
159159
Date tmpEndDate = endDate;

ql/cashflows/overnightindexedcoupon.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ namespace QuantLib {
7171
const std::vector<Rate>& indexFixings() const;
7272
//! value dates for the rates to be compounded
7373
const std::vector<Date>& valueDates() const { return valueDates_; }
74+
//! averaging method
75+
const RateAveraging::Type averagingMethod() const { return averagingMethod_; }
7476
//@}
7577
//! \name FloatingRateCoupon interface
7678
//@{
@@ -87,6 +89,7 @@ namespace QuantLib {
8789
mutable std::vector<Rate> fixings_;
8890
Size n_;
8991
std::vector<Time> dt_;
92+
RateAveraging::Type averagingMethod_;
9093

9194
Rate averageRate(const Date& date) const;
9295
};

ql/experimental/basismodels/swaptioncfs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ namespace QuantLib {
9191
floatWeights_.push_back(k->amount());
9292
}
9393

94-
SwapCashFlows::SwapCashFlows(const ext::shared_ptr<VanillaSwap>& swap,
94+
SwapCashFlows::SwapCashFlows(const ext::shared_ptr<FixedVsFloatingSwap>& swap,
9595
const Handle<YieldTermStructure>& discountCurve,
9696
bool contTenorSpread)
9797
: IborLegCashFlows(swap->floatingLeg(), discountCurve, contTenorSpread) {

ql/experimental/basismodels/swaptioncfs.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace QuantLib {
5959
std::vector<Real> annuityWeights_;
6060

6161
public:
62-
SwapCashFlows(const ext::shared_ptr<VanillaSwap>& swap,
62+
SwapCashFlows(const ext::shared_ptr<FixedVsFloatingSwap>& swap,
6363
const Handle<YieldTermStructure>& discountCurve,
6464
bool contTenorSpread = true);
6565
SwapCashFlows() = default;

ql/experimental/basismodels/tenorswaptionvts.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details.
2424

2525
#include <ql/experimental/basismodels/tenorswaptionvts.hpp>
2626
#include <ql/experimental/basismodels/swaptioncfs.hpp>
27+
#include <ql/instruments/vanillaswap.hpp>
2728
#include <ql/exercise.hpp>
2829
#include <ql/indexes/iborindex.hpp>
2930
#include <ql/math/rounding.hpp>
@@ -60,15 +61,15 @@ namespace QuantLib {
6061
volTS.baseIndex_->fixingCalendar(), ModifiedFollowing,
6162
Unadjusted, DateGeneration::Backward, false);
6263
// and swaps
63-
ext::shared_ptr<VanillaSwap> baseSwap(new VanillaSwap(
64+
auto baseSwap = ext::make_shared<VanillaSwap>(
6465
Swap::Payer, 1.0, baseFixedSchedule, 1.0, volTS.baseFixedDC_, baseFloatSchedule,
65-
volTS.baseIndex_, 0.0, volTS.baseIndex_->dayCounter()));
66-
ext::shared_ptr<VanillaSwap> targSwap(new VanillaSwap(
66+
volTS.baseIndex_, 0.0, volTS.baseIndex_->dayCounter());
67+
auto targSwap = ext::make_shared<VanillaSwap>(
6768
Swap::Payer, 1.0, baseFixedSchedule, 1.0, volTS.baseFixedDC_, targFloatSchedule,
68-
volTS.targIndex_, 0.0, volTS.targIndex_->dayCounter()));
69-
ext::shared_ptr<VanillaSwap> finlSwap(new VanillaSwap(
69+
volTS.targIndex_, 0.0, volTS.targIndex_->dayCounter());
70+
auto finlSwap = ext::make_shared<VanillaSwap>(
7071
Swap::Payer, 1.0, finlFixedSchedule, 1.0, volTS.targFixedDC_, targFloatSchedule,
71-
volTS.targIndex_, 0.0, volTS.targIndex_->dayCounter()));
72+
volTS.targIndex_, 0.0, volTS.targIndex_->dayCounter());
7273
// adding engines
7374
baseSwap->setPricingEngine(
7475
ext::shared_ptr<PricingEngine>(new DiscountingSwapEngine(volTS.discountCurve_)));

ql/instruments/makeswaption.cpp

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <ql/cashflows/cashflows.hpp>
2222
#include <ql/exercise.hpp>
2323
#include <ql/indexes/swapindex.hpp>
24+
#include <ql/instruments/makeois.hpp>
2425
#include <ql/instruments/makeswaption.hpp>
2526
#include <ql/instruments/makevanillaswap.hpp>
2627
#include <ql/pricingengines/swap/discountingswapengine.hpp>
@@ -71,39 +72,73 @@ namespace QuantLib {
7172
EuropeanExercise(exerciseDate_));
7273
}
7374

74-
Rate usedStrike = strike_;
75+
Rate usedStrike;
76+
ext::shared_ptr<OvernightIndexedSwapIndex> OIswap_index = ext::dynamic_pointer_cast<OvernightIndexedSwapIndex>(swapIndex_);
7577
if (strike_ == Null<Rate>()) {
7678
// ATM on curve(s) attached to index
7779
QL_REQUIRE(!swapIndex_->forwardingTermStructure().empty(),
7880
"null term structure set to this instance of " <<
7981
swapIndex_->name());
80-
ext::shared_ptr<VanillaSwap> temp =
81-
swapIndex_->underlyingSwap(fixingDate_);
82-
temp->setPricingEngine(
83-
ext::shared_ptr<PricingEngine>(new DiscountingSwapEngine(
84-
swapIndex_->exogenousDiscount()
82+
if (OIswap_index) {
83+
auto temp = OIswap_index->underlyingSwap(fixingDate_);
84+
temp->setPricingEngine(
85+
ext::make_shared<DiscountingSwapEngine>(
86+
swapIndex_->exogenousDiscount()
8587
? swapIndex_->discountingTermStructure()
8688
: swapIndex_->forwardingTermStructure(),
87-
false)));
88-
usedStrike = temp->fairRate();
89+
false
90+
)
91+
);
92+
usedStrike = temp->fairRate();
93+
} else {
94+
auto temp = swapIndex_->underlyingSwap(fixingDate_);
95+
temp->setPricingEngine(
96+
ext::make_shared<DiscountingSwapEngine>(
97+
swapIndex_->exogenousDiscount()
98+
? swapIndex_->discountingTermStructure()
99+
: swapIndex_->forwardingTermStructure(),
100+
false
101+
)
102+
);
103+
usedStrike = temp->fairRate();
104+
}
105+
} else {
106+
usedStrike = strike_;
89107
}
90108

91109
BusinessDayConvention bdc = swapIndex_->fixedLegConvention();
92-
underlyingSwap_ =
93-
MakeVanillaSwap(swapIndex_->tenor(),
94-
swapIndex_->iborIndex(), usedStrike)
95-
.withEffectiveDate(swapIndex_->valueDate(fixingDate_))
96-
.withFixedLegCalendar(swapIndex_->fixingCalendar())
97-
.withFixedLegDayCount(swapIndex_->dayCounter())
98-
.withFixedLegTenor(swapIndex_->fixedLegTenor())
99-
.withFixedLegConvention(bdc)
100-
.withFixedLegTerminationDateConvention(bdc)
101-
.withType(underlyingType_)
102-
.withNominal(nominal_)
103-
.withIndexedCoupons(useIndexedCoupons_);
104-
105-
ext::shared_ptr<Swaption> swaption(new Swaption(
106-
underlyingSwap_, exercise_, delivery_, settlementMethod_));
110+
if (OIswap_index) {
111+
underlyingSwap_ =
112+
(ext::shared_ptr<OvernightIndexedSwap>)(
113+
MakeOIS(swapIndex_->tenor(),
114+
OIswap_index->overnightIndex(), usedStrike)
115+
.withEffectiveDate(swapIndex_->valueDate(fixingDate_))
116+
.withPaymentCalendar(swapIndex_->fixingCalendar())
117+
.withFixedLegDayCount(swapIndex_->dayCounter())
118+
.withPaymentAdjustment(bdc)
119+
.withFixedLegConvention(bdc)
120+
.withFixedLegTerminationDateConvention(bdc)
121+
.withType(underlyingType_)
122+
.withNominal(nominal_)
123+
);
124+
} else {
125+
underlyingSwap_ =
126+
(ext::shared_ptr<VanillaSwap>)(
127+
MakeVanillaSwap(swapIndex_->tenor(),
128+
swapIndex_->iborIndex(), usedStrike)
129+
.withEffectiveDate(swapIndex_->valueDate(fixingDate_))
130+
.withFixedLegCalendar(swapIndex_->fixingCalendar())
131+
.withFixedLegDayCount(swapIndex_->dayCounter())
132+
.withFixedLegTenor(swapIndex_->fixedLegTenor())
133+
.withFixedLegConvention(bdc)
134+
.withFixedLegTerminationDateConvention(bdc)
135+
.withType(underlyingType_)
136+
.withNominal(nominal_)
137+
.withIndexedCoupons(useIndexedCoupons_)
138+
);
139+
}
140+
ext::shared_ptr<Swaption> swaption = ext::make_shared<Swaption>(
141+
underlyingSwap_, exercise_, delivery_, settlementMethod_);
107142
swaption->setPricingEngine(engine_);
108143
return swaption;
109144
}

ql/instruments/makeswaption.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ namespace QuantLib {
7070
ext::shared_ptr<SwapIndex> swapIndex_;
7171
Settlement::Type delivery_;
7272
Settlement::Method settlementMethod_;
73-
mutable ext::shared_ptr<VanillaSwap> underlyingSwap_;
73+
mutable ext::shared_ptr<FixedVsFloatingSwap> underlyingSwap_;
7474

7575
Period optionTenor_;
7676
BusinessDayConvention optionConvention_;

ql/instruments/nonstandardswap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
namespace QuantLib {
3535

36-
NonstandardSwap::NonstandardSwap(const VanillaSwap &fromVanilla)
36+
NonstandardSwap::NonstandardSwap(const FixedVsFloatingSwap &fromVanilla)
3737
: Swap(2), type_(fromVanilla.type()),
3838
fixedNominal_(std::vector<Real>(fromVanilla.fixedLeg().size(),
3939
fromVanilla.nominal())),

ql/instruments/nonstandardswap.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#define quantlib_nonstandard_swap_hpp
2626

2727
#include <ql/instruments/swap.hpp>
28-
#include <ql/instruments/vanillaswap.hpp>
28+
#include <ql/instruments/fixedvsfloatingswap.hpp>
2929
#include <ql/time/daycounter.hpp>
3030
#include <ql/time/schedule.hpp>
3131
#include <ql/optional.hpp>
@@ -42,7 +42,7 @@ namespace QuantLib {
4242
class arguments;
4343
class results;
4444
class engine;
45-
NonstandardSwap(const VanillaSwap &fromVanilla);
45+
explicit NonstandardSwap(const FixedVsFloatingSwap &fromVanilla);
4646
NonstandardSwap(Swap::Type type,
4747
std::vector<Real> fixedNominal,
4848
const std::vector<Real>& floatingNominal,

0 commit comments

Comments
 (0)