|
27 | 27 | #include "utilities.hpp" |
28 | 28 | #include <ql/cashflows/iborcoupon.hpp> |
29 | 29 | #include <ql/instruments/swaption.hpp> |
| 30 | +#include <ql/instruments/makeswaption.hpp> |
30 | 31 | #include <ql/instruments/makevanillaswap.hpp> |
31 | 32 | #include <ql/instruments/makeois.hpp> |
| 33 | +#include <ql/indexes/swap/euriborswap.hpp> |
| 34 | +#include <ql/time/calendars/unitedstates.hpp> |
32 | 35 | #include <ql/termstructures/yield/flatforward.hpp> |
33 | 36 | #include <ql/termstructures/yield/zerospreadedtermstructure.hpp> |
34 | 37 | #include <ql/indexes/ibor/euribor.hpp> |
@@ -1143,6 +1146,52 @@ BOOST_AUTO_TEST_CASE(testSwaptionDeltaInBachelierModel) { |
1143 | 1146 | checkSwaptionDelta<BachelierSwaptionEngine>(true); |
1144 | 1147 | } |
1145 | 1148 |
|
| 1149 | +BOOST_AUTO_TEST_CASE(testMakeSwaptionWithExerciseCalendar) { |
| 1150 | + |
| 1151 | + BOOST_TEST_MESSAGE("Testing MakeSwaption with exercise calendar override..."); |
| 1152 | + |
| 1153 | + // Use a specific date where TARGET and US Settlement diverge: |
| 1154 | + // 1Y advance from Oct 9, 2015 gives Oct 10, 2016 (TARGET) |
| 1155 | + // vs Oct 11, 2016 (US), because Oct 10 is Columbus Day. |
| 1156 | + Date today(9, October, 2015); |
| 1157 | + Settings::instance().evaluationDate() = today; |
| 1158 | + RelinkableHandle<YieldTermStructure> termStructure; |
| 1159 | + termStructure.linkTo(flatRate(today, 0.05, Actual365Fixed())); |
| 1160 | + |
| 1161 | + auto swapIndex = ext::make_shared<EuriborSwapIsdaFixA>(5*Years, termStructure); |
| 1162 | + Calendar targetCalendar = swapIndex->fixingCalendar(); |
| 1163 | + Calendar usCalendar = UnitedStates(UnitedStates::Settlement); |
| 1164 | + |
| 1165 | + // Default uses swap index's fixing calendar (TARGET) |
| 1166 | + Swaption defaultSwaption = |
| 1167 | + MakeSwaption(swapIndex, 1*Years, 0.05); |
| 1168 | + Date defaultExercise = defaultSwaption.exercise()->dates().front(); |
| 1169 | + |
| 1170 | + Date expected = targetCalendar.advance( |
| 1171 | + targetCalendar.adjust(today), 1*Years, ModifiedFollowing); |
| 1172 | + BOOST_CHECK_EQUAL(defaultExercise, expected); |
| 1173 | + |
| 1174 | + // With custom calendar, exercise date differs |
| 1175 | + Swaption customSwaption = |
| 1176 | + MakeSwaption(swapIndex, 1*Years, 0.05) |
| 1177 | + .withExerciseCalendar(usCalendar); |
| 1178 | + Date customExercise = customSwaption.exercise()->dates().front(); |
| 1179 | + |
| 1180 | + Date expectedCustom = usCalendar.advance( |
| 1181 | + usCalendar.adjust(today), 1*Years, ModifiedFollowing); |
| 1182 | + BOOST_CHECK_EQUAL(customExercise, expectedCustom); |
| 1183 | + BOOST_CHECK_NE(customExercise, defaultExercise); |
| 1184 | + |
| 1185 | + // Explicit withExerciseDate takes precedence over calendar |
| 1186 | + Date explicitDate = targetCalendar.advance(today, 6*Months); |
| 1187 | + Date fixingDate = targetCalendar.advance(today, 1*Years); |
| 1188 | + Swaption explicitSwaption = |
| 1189 | + MakeSwaption(swapIndex, fixingDate, 0.05) |
| 1190 | + .withExerciseCalendar(usCalendar) |
| 1191 | + .withExerciseDate(explicitDate); |
| 1192 | + BOOST_CHECK_EQUAL(explicitSwaption.exercise()->dates().front(), explicitDate); |
| 1193 | +} |
| 1194 | + |
1146 | 1195 | BOOST_AUTO_TEST_SUITE_END() |
1147 | 1196 |
|
1148 | 1197 | BOOST_AUTO_TEST_SUITE_END() |
0 commit comments