Skip to content

Commit c9f0b44

Browse files
authored
Merge branch 'lballabio:master' into feature/smilesection-optional-forward
2 parents 5878112 + 68f4edf commit c9f0b44

10 files changed

Lines changed: 79 additions & 20 deletions

File tree

ql/instruments/makecds.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <ql/instruments/makecds.hpp>
2222
#include <ql/time/daycounters/actual360.hpp>
2323
#include <ql/time/calendars/weekendsonly.hpp>
24+
#include <utility>
2425

2526

2627
namespace QuantLib {
@@ -153,7 +154,7 @@ namespace QuantLib {
153154
}
154155

155156
MakeCreditDefaultSwap& MakeCreditDefaultSwap::withClaim(ext::shared_ptr<Claim> claim) {
156-
claim_ = claim;
157+
claim_ = std::move(claim);
157158
return *this;
158159
}
159160

ql/instruments/makeswaption.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,16 @@ namespace QuantLib {
5353

5454
MakeSwaption::operator ext::shared_ptr<Swaption>() const {
5555

56-
const Calendar& fixingCalendar = swapIndex_->fixingCalendar();
56+
const Calendar& calendar = exerciseCalendar_.empty()
57+
? swapIndex_->fixingCalendar()
58+
: exerciseCalendar_;
5759
Date refDate = Settings::instance().evaluationDate();
5860
// if the evaluation date is not a business day
5961
// then move to the next business day
60-
refDate = fixingCalendar.adjust(refDate);
62+
refDate = calendar.adjust(refDate);
6163
if (fixingDate_ == Date())
62-
fixingDate_ = fixingCalendar.advance(refDate, optionTenor_,
63-
optionConvention_);
64+
fixingDate_ = calendar.advance(refDate, optionTenor_,
65+
optionConvention_);
6466
if (exerciseDate_ == Date()) {
6567
exercise_ = ext::shared_ptr<Exercise>(new
6668
EuropeanExercise(fixingDate_));
@@ -165,6 +167,11 @@ namespace QuantLib {
165167
return *this;
166168
}
167169

170+
MakeSwaption& MakeSwaption::withExerciseCalendar(const Calendar& cal) {
171+
exerciseCalendar_ = cal;
172+
return *this;
173+
}
174+
168175
MakeSwaption& MakeSwaption::withUnderlyingType(const Swap::Type type) {
169176
underlyingType_ = type;
170177
return *this;

ql/instruments/makeswaption.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ namespace QuantLib {
6060
MakeSwaption& withSettlementMethod(Settlement::Method settlementMethod);
6161
MakeSwaption& withOptionConvention(BusinessDayConvention bdc);
6262
MakeSwaption& withExerciseDate(const Date&);
63+
MakeSwaption& withExerciseCalendar(const Calendar&);
6364
MakeSwaption& withUnderlyingType(Swap::Type type);
6465
MakeSwaption& withIndexedCoupons(const ext::optional<bool>& b = true);
6566
MakeSwaption& withAtParCoupons(bool b = true);
@@ -76,6 +77,7 @@ namespace QuantLib {
7677
BusinessDayConvention optionConvention_;
7778
mutable Date fixingDate_;
7879
Date exerciseDate_;
80+
Calendar exerciseCalendar_;
7981
mutable ext::shared_ptr<Exercise> exercise_;
8082

8183
Rate strike_;

ql/instruments/multipleresetsswap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace QuantLib {
3737

3838
MultipleResetsSwap::MultipleResetsSwap(
3939
Type type, Real nominal,
40-
Schedule fixedSchedule, Rate fixedRate, DayCounter fixedDayCount,
40+
const Schedule& fixedSchedule, Rate fixedRate, DayCounter fixedDayCount,
4141
Schedule fullResetSchedule,
4242
const ext::shared_ptr<IborIndex>& iborIndex, Size resetsPerCoupon,
4343
Spread spread, RateAveraging::Type averagingMethod,

ql/instruments/multipleresetsswap.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace QuantLib {
4141
public:
4242
MultipleResetsSwap(Type type,
4343
Real nominal,
44-
Schedule fixedSchedule,
44+
const Schedule& fixedSchedule,
4545
Rate fixedRate,
4646
DayCounter fixedDayCount,
4747
Schedule fullResetSchedule,

ql/termstructures/volatility/equityfx/blackvolsurfacedelta.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ namespace QuantLib {
113113
//@}
114114
//! \name Visitability
115115
//@{
116-
virtual void accept(AcyclicVisitor&) override;
116+
void accept(AcyclicVisitor&) override;
117117
//@}
118118

119119
//! \name Inspectors
@@ -159,7 +159,7 @@ namespace QuantLib {
159159
ext::shared_ptr<SmileSection> blackVolSmile(const Date& d) const;
160160

161161
protected:
162-
virtual Volatility blackVolImpl(Time t, Real strike) const override;
162+
Volatility blackVolImpl(Time t, Real strike) const override;
163163

164164
private:
165165
std::vector<Date> dates_;
@@ -195,8 +195,8 @@ namespace QuantLib {
195195
// inline definitions
196196

197197
inline void BlackVolatilitySurfaceDelta::accept(AcyclicVisitor& v) {
198-
Visitor<BlackVolatilitySurfaceDelta>* v1 = dynamic_cast<Visitor<BlackVolatilitySurfaceDelta>*>(&v);
199-
if (v1 != 0)
198+
auto* v1 = dynamic_cast<Visitor<BlackVolatilitySurfaceDelta>*>(&v);
199+
if (v1 != nullptr)
200200
v1->visit(*this);
201201
else
202202
BlackVolatilityTermStructure::accept(v);

ql/termstructures/yield/multipleresetsswaphelper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ namespace QuantLib {
3434
RateAveraging::Type averagingMethod,
3535
Spread spread,
3636
Frequency fixedFrequency,
37-
DayCounter fixedDayCount,
37+
const DayCounter& fixedDayCount,
3838
BusinessDayConvention fixedConvention)
3939
: RelativeDateRateHelper(fixedRate), settlementDays_(settlementDays), tenor_(tenor),
4040
resetsPerCoupon_(resetsPerCoupon), averagingMethod_(averagingMethod), spread_(spread),
4141
fixedFrequency_(fixedFrequency),
42-
fixedDayCount_(!fixedDayCount.empty() ? std::move(fixedDayCount) : iborIndex->dayCounter()),
42+
fixedDayCount_(!fixedDayCount.empty() ? fixedDayCount : iborIndex->dayCounter()),
4343
fixedConvention_(fixedConvention), discountHandle_(std::move(discountingCurve)) {
4444

4545
// Clone the index so it forwards rates from termStructureHandle_,

ql/termstructures/yield/multipleresetsswaphelper.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace QuantLib {
4545
RateAveraging::Type averagingMethod = RateAveraging::Compound,
4646
Spread spread = 0.0,
4747
Frequency fixedFrequency = NoFrequency,
48-
DayCounter fixedDayCount = DayCounter(),
48+
const DayCounter& fixedDayCount = DayCounter(),
4949
BusinessDayConvention fixedConvention = ModifiedFollowing);
5050

5151
Real impliedQuote() const override;

test-suite/interpolatedsmilesection.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ BOOST_AUTO_TEST_CASE(testHandlesUpdatePropagates) {
121121
ext::shared_ptr<SimpleQuote> q1(new SimpleQuote(0.15 * sqrtT));
122122
ext::shared_ptr<SimpleQuote> q2(new SimpleQuote(0.18 * sqrtT));
123123
std::vector<Handle<Quote>> stdDevHandles;
124-
stdDevHandles.emplace_back(Handle<Quote>(q0));
125-
stdDevHandles.emplace_back(Handle<Quote>(q1));
126-
stdDevHandles.emplace_back(Handle<Quote>(q2));
124+
stdDevHandles.emplace_back(q0);
125+
stdDevHandles.emplace_back(q1);
126+
stdDevHandles.emplace_back(q2);
127127

128128
ext::shared_ptr<SimpleQuote> atm(new SimpleQuote(95.0));
129129
Handle<Quote> atmHandle(atm);
@@ -161,9 +161,9 @@ BOOST_AUTO_TEST_CASE(testFlatStrikeExtrapolation) {
161161
ext::shared_ptr<SimpleQuote> q1(new SimpleQuote(0.15 * sqrtT));
162162
ext::shared_ptr<SimpleQuote> q2(new SimpleQuote(0.18 * sqrtT));
163163
std::vector<Handle<Quote>> stdDevHandles;
164-
stdDevHandles.emplace_back(Handle<Quote>(q0));
165-
stdDevHandles.emplace_back(Handle<Quote>(q1));
166-
stdDevHandles.emplace_back(Handle<Quote>(q2));
164+
stdDevHandles.emplace_back(q0);
165+
stdDevHandles.emplace_back(q1);
166+
stdDevHandles.emplace_back(q2);
167167

168168
ext::shared_ptr<SimpleQuote> atm(new SimpleQuote(95.0));
169169
Handle<Quote> atmHandle(atm);

test-suite/swaption.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727
#include "utilities.hpp"
2828
#include <ql/cashflows/iborcoupon.hpp>
2929
#include <ql/instruments/swaption.hpp>
30+
#include <ql/instruments/makeswaption.hpp>
3031
#include <ql/instruments/makevanillaswap.hpp>
3132
#include <ql/instruments/makeois.hpp>
33+
#include <ql/indexes/swap/euriborswap.hpp>
34+
#include <ql/time/calendars/unitedstates.hpp>
3235
#include <ql/termstructures/yield/flatforward.hpp>
3336
#include <ql/termstructures/yield/zerospreadedtermstructure.hpp>
3437
#include <ql/indexes/ibor/euribor.hpp>
@@ -1143,6 +1146,52 @@ BOOST_AUTO_TEST_CASE(testSwaptionDeltaInBachelierModel) {
11431146
checkSwaptionDelta<BachelierSwaptionEngine>(true);
11441147
}
11451148

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+
11461195
BOOST_AUTO_TEST_SUITE_END()
11471196

11481197
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)