|
21 | 21 | #include <ql/cashflows/cashflows.hpp> |
22 | 22 | #include <ql/exercise.hpp> |
23 | 23 | #include <ql/indexes/swapindex.hpp> |
| 24 | +#include <ql/instruments/makeois.hpp> |
24 | 25 | #include <ql/instruments/makeswaption.hpp> |
25 | 26 | #include <ql/instruments/makevanillaswap.hpp> |
26 | 27 | #include <ql/pricingengines/swap/discountingswapengine.hpp> |
@@ -71,39 +72,73 @@ namespace QuantLib { |
71 | 72 | EuropeanExercise(exerciseDate_)); |
72 | 73 | } |
73 | 74 |
|
74 | | - Rate usedStrike = strike_; |
| 75 | + Rate usedStrike; |
| 76 | + ext::shared_ptr<OvernightIndexedSwapIndex> OIswap_index = ext::dynamic_pointer_cast<OvernightIndexedSwapIndex>(swapIndex_); |
75 | 77 | if (strike_ == Null<Rate>()) { |
76 | 78 | // ATM on curve(s) attached to index |
77 | 79 | QL_REQUIRE(!swapIndex_->forwardingTermStructure().empty(), |
78 | 80 | "null term structure set to this instance of " << |
79 | 81 | 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() |
85 | 87 | ? swapIndex_->discountingTermStructure() |
86 | 88 | : 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_; |
89 | 107 | } |
90 | 108 |
|
91 | 109 | 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_); |
107 | 142 | swaption->setPricingEngine(engine_); |
108 | 143 | return swaption; |
109 | 144 | } |
|
0 commit comments