Skip to content

Commit

Permalink
Merge 67b6633 into 717025c
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed May 27, 2021
2 parents 717025c + 67b6633 commit 9dae66a
Show file tree
Hide file tree
Showing 28 changed files with 235 additions and 189 deletions.
75 changes: 40 additions & 35 deletions Examples/CDS/CDS.cpp
Expand Up @@ -275,44 +275,46 @@ std::copy(cdsSchedule.begin(), cdsSchedule.end(),
<< "of the ISDA rate curve." << std::endl;
}

DayCounter thirty360 = Thirty360(Thirty360::BondBasis);

ext::shared_ptr<SwapRateHelper> sw2y = ext::make_shared<SwapRateHelper>(
0.002230, 2 * Years, TARGET(), Annual, ModifiedFollowing, Thirty360(),
0.002230, 2 * Years, TARGET(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw3y = ext::make_shared<SwapRateHelper>(
0.002760, 3 * Years, TARGET(), Annual, ModifiedFollowing, Thirty360(),
0.002760, 3 * Years, TARGET(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw4y = ext::make_shared<SwapRateHelper>(
0.003530, 4 * Years, TARGET(), Annual, ModifiedFollowing, Thirty360(),
0.003530, 4 * Years, TARGET(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw5y = ext::make_shared<SwapRateHelper>(
0.004520, 5 * Years, TARGET(), Annual, ModifiedFollowing, Thirty360(),
0.004520, 5 * Years, TARGET(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw6y = ext::make_shared<SwapRateHelper>(
0.005720, 6 * Years, TARGET(), Annual, ModifiedFollowing, Thirty360(),
0.005720, 6 * Years, TARGET(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw7y = ext::make_shared<SwapRateHelper>(
0.007050, 7 * Years, TARGET(), Annual, ModifiedFollowing, Thirty360(),
0.007050, 7 * Years, TARGET(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw8y = ext::make_shared<SwapRateHelper>(
0.008420, 8 * Years, TARGET(), Annual, ModifiedFollowing, Thirty360(),
0.008420, 8 * Years, TARGET(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw9y = ext::make_shared<SwapRateHelper>(
0.009720, 9 * Years, TARGET(), Annual, ModifiedFollowing, Thirty360(),
0.009720, 9 * Years, TARGET(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw10y = ext::make_shared<SwapRateHelper>(
0.010900, 10 * Years, TARGET(), Annual, ModifiedFollowing, Thirty360(),
0.010900, 10 * Years, TARGET(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw12y = ext::make_shared<SwapRateHelper>(
0.012870, 12 * Years, TARGET(), Annual, ModifiedFollowing, Thirty360(),
0.012870, 12 * Years, TARGET(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw15y = ext::make_shared<SwapRateHelper>(
0.014970, 15 * Years, TARGET(), Annual, ModifiedFollowing, Thirty360(),
0.014970, 15 * Years, TARGET(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw20y = ext::make_shared<SwapRateHelper>(
0.017000, 20 * Years, TARGET(), Annual, ModifiedFollowing, Thirty360(),
0.017000, 20 * Years, TARGET(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw30y = ext::make_shared<SwapRateHelper>(
0.018210, 30 * Years, TARGET(), Annual, ModifiedFollowing, Thirty360(),
0.018210, 30 * Years, TARGET(), Annual, ModifiedFollowing, thirty360,
euribor6m);

std::vector<ext::shared_ptr<RateHelper> > isdaRateHelper;
Expand Down Expand Up @@ -453,82 +455,85 @@ void example03() {

Settings::instance().evaluationDate() = tradeDate;

DayCounter actual360 = Actual360();
DayCounter thirty360 = Thirty360(Thirty360::BondBasis);

ext::shared_ptr<DepositRateHelper> dp1m =
ext::make_shared<DepositRateHelper>(0.00445, 1 * Months, 2,
WeekendsOnly(), ModifiedFollowing,
false, Actual360());
false, actual360);
ext::shared_ptr<DepositRateHelper> dp2m =
ext::make_shared<DepositRateHelper>(0.00949, 2 * Months, 2,
WeekendsOnly(), ModifiedFollowing,
false, Actual360());
false, actual360);
ext::shared_ptr<DepositRateHelper> dp3m =
ext::make_shared<DepositRateHelper>(0.01234, 3 * Months, 2,
WeekendsOnly(), ModifiedFollowing,
false, Actual360());
false, actual360);
ext::shared_ptr<DepositRateHelper> dp6m =
ext::make_shared<DepositRateHelper>(0.01776, 6 * Months, 2,
WeekendsOnly(), ModifiedFollowing,
false, Actual360());
false, actual360);
ext::shared_ptr<DepositRateHelper> dp9m =
ext::make_shared<DepositRateHelper>(0.01935, 9 * Months, 2,
WeekendsOnly(), ModifiedFollowing,
false, Actual360());
false, actual360);
ext::shared_ptr<DepositRateHelper> dp1y =
ext::make_shared<DepositRateHelper>(0.02084, 12 * Months, 2,
WeekendsOnly(), ModifiedFollowing,
false, Actual360());
false, actual360);

// this index is probably not important since we are not using
// IborCoupon::usingAtParCoupons() == false
// - define it "isda compliant" anyway
ext::shared_ptr<IborIndex> euribor6m = ext::make_shared<IborIndex>(
"IsdaIbor", 6 * Months, 2, EURCurrency(), WeekendsOnly(),
ModifiedFollowing, false, Actual360());
ModifiedFollowing, false, actual360);

ext::shared_ptr<SwapRateHelper> sw2y = ext::make_shared<SwapRateHelper>(
0.01652, 2 * Years, WeekendsOnly(), Annual, ModifiedFollowing, Thirty360(),
0.01652, 2 * Years, WeekendsOnly(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw3y = ext::make_shared<SwapRateHelper>(
0.02018, 3 * Years, WeekendsOnly(), Annual, ModifiedFollowing, Thirty360(),
0.02018, 3 * Years, WeekendsOnly(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw4y = ext::make_shared<SwapRateHelper>(
0.02303, 4 * Years, WeekendsOnly(), Annual, ModifiedFollowing, Thirty360(),
0.02303, 4 * Years, WeekendsOnly(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw5y = ext::make_shared<SwapRateHelper>(
0.02525, 5 * Years, WeekendsOnly(), Annual, ModifiedFollowing, Thirty360(),
0.02525, 5 * Years, WeekendsOnly(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw6y = ext::make_shared<SwapRateHelper>(
0.02696, 6 * Years, WeekendsOnly(), Annual, ModifiedFollowing, Thirty360(),
0.02696, 6 * Years, WeekendsOnly(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw7y = ext::make_shared<SwapRateHelper>(
0.02825, 7 * Years, WeekendsOnly(), Annual, ModifiedFollowing, Thirty360(),
0.02825, 7 * Years, WeekendsOnly(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw8y = ext::make_shared<SwapRateHelper>(
0.02931, 8 * Years, WeekendsOnly(), Annual, ModifiedFollowing, Thirty360(),
0.02931, 8 * Years, WeekendsOnly(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw9y = ext::make_shared<SwapRateHelper>(
0.03017, 9 * Years, WeekendsOnly(), Annual, ModifiedFollowing, Thirty360(),
0.03017, 9 * Years, WeekendsOnly(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw10y = ext::make_shared<SwapRateHelper>(
0.03092, 10 * Years, WeekendsOnly(), Annual, ModifiedFollowing, Thirty360(),
0.03092, 10 * Years, WeekendsOnly(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw11y = ext::make_shared<SwapRateHelper>(
0.03160, 11 * Years, WeekendsOnly(), Annual, ModifiedFollowing, Thirty360(),
0.03160, 11 * Years, WeekendsOnly(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw12y = ext::make_shared<SwapRateHelper>(
0.03231, 12 * Years, WeekendsOnly(), Annual, ModifiedFollowing, Thirty360(),
0.03231, 12 * Years, WeekendsOnly(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw15y = ext::make_shared<SwapRateHelper>(
0.03367, 15 * Years, WeekendsOnly(), Annual, ModifiedFollowing, Thirty360(),
0.03367, 15 * Years, WeekendsOnly(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw20y = ext::make_shared<SwapRateHelper>(
0.03419, 20 * Years, WeekendsOnly(), Annual, ModifiedFollowing, Thirty360(),
0.03419, 20 * Years, WeekendsOnly(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw25y = ext::make_shared<SwapRateHelper>(
0.03411, 25 * Years, WeekendsOnly(), Annual, ModifiedFollowing, Thirty360(),
0.03411, 25 * Years, WeekendsOnly(), Annual, ModifiedFollowing, thirty360,
euribor6m);
ext::shared_ptr<SwapRateHelper> sw30y = ext::make_shared<SwapRateHelper>(
0.03412, 30 * Years, WeekendsOnly(), Annual, ModifiedFollowing, Thirty360(),
0.03412, 30 * Years, WeekendsOnly(), Annual, ModifiedFollowing, thirty360,
euribor6m);

std::vector<ext::shared_ptr<RateHelper> > isdaYieldHelpers;
Expand Down
2 changes: 1 addition & 1 deletion Examples/ConvertibleBonds/ConvertibleBonds.cpp
Expand Up @@ -86,7 +86,7 @@ int main(int, char* []) {

std::vector<Real> coupons(1, 0.05);

DayCounter bondDayCount = Thirty360();
DayCounter bondDayCount = Thirty360(Thirty360::BondBasis);

Integer callLength[] = { 2, 4 }; // Call dates, years 2, 4.
Integer putLength[] = { 3 }; // Put dates year 3
Expand Down
8 changes: 4 additions & 4 deletions Examples/Gaussian1dModels/Gaussian1dModels.cpp
Expand Up @@ -193,7 +193,7 @@ int main(int argc, char *argv[]) {

ext::shared_ptr<NonstandardSwap> underlying =
ext::make_shared<NonstandardSwap>(VanillaSwap(
VanillaSwap::Payer, 1.0, fixedSchedule, strike, Thirty360(),
VanillaSwap::Payer, 1.0, fixedSchedule, strike, Thirty360(Thirty360::BondBasis),
floatingSchedule, euribor6m, 0.00, Actual360()));

std::vector<Date> exerciseDates;
Expand Down Expand Up @@ -356,7 +356,7 @@ int main(int argc, char *argv[]) {

ext::shared_ptr<NonstandardSwap> underlying2(new NonstandardSwap(
VanillaSwap::Payer, nominalFixed, nominalFloating, fixedSchedule,
strikes, Thirty360(), floatingSchedule, euribor6m, 1.0, 0.0,
strikes, Thirty360(Thirty360::BondBasis), floatingSchedule, euribor6m, 1.0, 0.0,
Actual360()));
ext::shared_ptr<NonstandardSwaption> swaption2 =
ext::make_shared<NonstandardSwaption>(underlying2, exercise);
Expand Down Expand Up @@ -392,7 +392,7 @@ int main(int argc, char *argv[]) {

ext::shared_ptr<NonstandardSwap> underlying3(new NonstandardSwap(
VanillaSwap::Receiver, nominalFixed2, nominalFloating2,
fixedSchedule, strikes, Thirty360(), floatingSchedule, euribor6m,
fixedSchedule, strikes, Thirty360(Thirty360::BondBasis), floatingSchedule, euribor6m,
1.0, 0.0, Actual360(), false,
true)); // final capital exchange

Expand Down Expand Up @@ -487,7 +487,7 @@ int main(int argc, char *argv[]) {

ext::shared_ptr<FloatFloatSwap> underlying4(new FloatFloatSwap(
VanillaSwap::Payer, 1.0, 1.0, fixedSchedule, swapBase,
Thirty360(), floatingSchedule, euribor6m, Actual360(), false,
Thirty360(Thirty360::BondBasis), floatingSchedule, euribor6m, Actual360(), false,
false, 1.0, 0.0, Null<Real>(), Null<Real>(), 1.0, 0.0010));

ext::shared_ptr<FloatFloatSwaption> swaption4 =
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/cpicoupon.cpp
Expand Up @@ -152,7 +152,7 @@ namespace QuantLib {
const Real baseCPI,
const Period& observationLag)
: schedule_(schedule), index_(std::move(index)), baseCPI_(baseCPI),
observationLag_(observationLag), paymentDayCounter_(Thirty360()),
observationLag_(observationLag), paymentDayCounter_(Thirty360(Thirty360::BondBasis)),
paymentAdjustment_(ModifiedFollowing), paymentCalendar_(schedule.calendar()),
fixingDays_(std::vector<Natural>(1, 0)), observationInterpolation_(CPI::AsIndex),
subtractInflationNominal_(true), spreads_(std::vector<Real>(1, 0)) {}
Expand Down
2 changes: 1 addition & 1 deletion ql/instruments/makeyoyinflationcapfloor.cpp
Expand Up @@ -34,7 +34,7 @@ namespace QuantLib {
: capFloorType_(capFloorType), length_(length), calendar_(std::move(cal)),
index_(std::move(index)), observationLag_(observationLag), strike_(Null<Rate>()),
firstCapletExcluded_(false), asOptionlet_(false), effectiveDate_(Date()),
dayCounter_(Thirty360()), roll_(ModifiedFollowing), fixingDays_(0), nominal_(1000000.0) {}
dayCounter_(Thirty360(Thirty360::BondBasis)), roll_(ModifiedFollowing), fixingDays_(0), nominal_(1000000.0) {}

MakeYoYInflationCapFloor::operator YoYInflationCapFloor() const {
ext::shared_ptr<YoYInflationCapFloor> capfloor = *this;
Expand Down
2 changes: 1 addition & 1 deletion ql/time/daycounters/simpledaycounter.cpp
Expand Up @@ -22,7 +22,7 @@

namespace QuantLib {

namespace { DayCounter fallback = Thirty360(); }
namespace { DayCounter fallback = Thirty360(Thirty360::BondBasis); }

Date::serial_type SimpleDayCounter::Impl::dayCount(const Date& d1,
const Date& d2) const {
Expand Down
58 changes: 39 additions & 19 deletions ql/time/daycounters/thirty360.cpp
Expand Up @@ -27,16 +27,19 @@ namespace QuantLib {
Thirty360::implementation(Thirty360::Convention c, bool isLastPeriod) {
switch (c) {
case USA:
case BondBasis:
case NASD:
return ext::shared_ptr<DayCounter::Impl>(new US_Impl);
case European:
case EurobondBasis:
return ext::shared_ptr<DayCounter::Impl>(new EU_Impl);
case Italian:
return ext::shared_ptr<DayCounter::Impl>(new IT_Impl);
case ISMA:
case BondBasis:
return ext::shared_ptr<DayCounter::Impl>(new ISMA_Impl);
case ISDA:
case German:
return ext::shared_ptr<DayCounter::Impl>(
new GER_Impl(isLastPeriod));
return ext::shared_ptr<DayCounter::Impl>(new ISDA_Impl(isLastPeriod));
default:
QL_FAIL("unknown 30/360 convention");
}
Expand All @@ -48,10 +51,23 @@ namespace QuantLib {
Integer mm1 = d1.month(), mm2 = d2.month();
Year yy1 = d1.year(), yy2 = d2.year();

if (dd1 == 31) { dd1 = 30; }
if (dd2 == 31 && dd1 >= 30) { dd2 = 30; }
if (dd2 == 31 && dd1 < 30) { dd2 = 1; mm2++; }

return 360*(yy2-yy1) + 30*(mm2-mm1-1) +
std::max(Integer(0),30-dd1) + std::min(Integer(30),dd2);
return 360*(yy2-yy1) + 30*(mm2-mm1) + (dd2-dd1);
}

Date::serial_type Thirty360::ISMA_Impl::dayCount(const Date& d1,
const Date& d2) const {
Day dd1 = d1.dayOfMonth(), dd2 = d2.dayOfMonth();
Integer mm1 = d1.month(), mm2 = d2.month();
Year yy1 = d1.year(), yy2 = d2.year();

if (dd1 == 31) { dd1 = 30; }
if (dd2 == 31 && dd1 == 30) { dd2 = 30; }

return 360*(yy2-yy1) + 30*(mm2-mm1) + (dd2-dd1);
}

Date::serial_type Thirty360::EU_Impl::dayCount(const Date& d1,
Expand All @@ -60,8 +76,10 @@ namespace QuantLib {
Month mm1 = d1.month(), mm2 = d2.month();
Year yy1 = d1.year(), yy2 = d2.year();

return 360*(yy2-yy1) + 30*(mm2-mm1-1) +
std::max(Integer(0),30-dd1) + std::min(Integer(30),dd2);
if (dd1 == 31) { dd1 = 30; }
if (dd2 == 31) { dd2 = 30; }

return 360*(yy2-yy1) + 30*(mm2-mm1) + (dd2-dd1);
}

Date::serial_type Thirty360::IT_Impl::dayCount(const Date& d1,
Expand All @@ -70,26 +88,28 @@ namespace QuantLib {
Month mm1 = d1.month(), mm2 = d2.month();
Year yy1 = d1.year(), yy2 = d2.year();

if (mm1 == 2 && dd1 > 27) dd1 = 30;
if (mm2 == 2 && dd2 > 27) dd2 = 30;
if (dd1 == 31) { dd1 = 30; }
if (dd2 == 31) { dd2 = 30; }

if (mm1 == 2 && dd1 > 27) { dd1 = 30; }
if (mm2 == 2 && dd2 > 27) { dd2 = 30; }

return 360*(yy2-yy1) + 30*(mm2-mm1-1) +
std::max(Integer(0),30-dd1) + std::min(Integer(30),dd2);
return 360*(yy2-yy1) + 30*(mm2-mm1) + (dd2-dd1);
}

Date::serial_type Thirty360::GER_Impl::dayCount(const Date& d1,
const Date& d2) const {
Date::serial_type Thirty360::ISDA_Impl::dayCount(const Date& d1,
const Date& d2) const {
Day dd1 = d1.dayOfMonth(), dd2 = d2.dayOfMonth();
Month mm1 = d1.month(), mm2 = d2.month();
Year yy1 = d1.year(), yy2 = d2.year();

if (mm1 == 2 && dd1 == 28 + (Date::isLeap(yy1) ? 1 : 0))
dd1 = 30;
if (!isLastPeriod_ && mm2 == 2 && dd2 == 28 + (Date::isLeap(yy2) ? 1 : 0))
dd2 = 30;
if (dd1 == 31) { dd1 = 30; }
if (dd2 == 31) { dd2 = 30; }

if (mm1 == 2 && dd1 == 28 + (Date::isLeap(yy1) ? 1 : 0)) { dd1 = 30; }
if (!isLastPeriod_ && mm2 == 2 && dd2 == 28 + (Date::isLeap(yy2) ? 1 : 0)) { dd2 = 30; }

return 360*(yy2-yy1) + 30*(mm2-mm1-1) +
std::max(Integer(0),30-dd1) + std::min(Integer(30),dd2);
return 360*(yy2-yy1) + 30*(mm2-mm1) + (dd2-dd1);
}

}

0 comments on commit 9dae66a

Please sign in to comment.