Skip to content

Commit

Permalink
Added first stub dayCounter to FixedRateBond
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobleehowes committed Jul 22, 2020
1 parent 0366583 commit 4d89058
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
24 changes: 20 additions & 4 deletions ql/instruments/bonds/fixedratebond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,21 @@ namespace QuantLib {
const Period& exCouponPeriod,
const Calendar& exCouponCalendar,
const BusinessDayConvention exCouponConvention,
bool exCouponEndOfMonth)
bool exCouponEndOfMonth,
const DayCounter& stubAccrualDayCounter)
: Bond(settlementDays,
paymentCalendar==Calendar() ? schedule.calendar() : paymentCalendar,
issueDate),
frequency_(schedule.hasTenor() ? schedule.tenor().frequency() : NoFrequency),
dayCounter_(accrualDayCounter) {
dayCounter_(accrualDayCounter),
stubDayCounter_(stubAccrualDayCounter) {

maturityDate_ = schedule.endDate();

cashflows_ = FixedRateLeg(schedule)
.withNotionals(faceAmount)
.withCouponRates(coupons, accrualDayCounter)
.withFirstPeriodDayCounter(stubAccrualDayCounter==DayCounter() ? accrualDayCounter : stubAccrualDayCounter)
.withPaymentCalendar(calendar_)
.withPaymentAdjustment(paymentConvention)
.withExCouponPeriod(exCouponPeriod,
Expand Down Expand Up @@ -84,11 +87,13 @@ namespace QuantLib {
const Period& exCouponPeriod,
const Calendar& exCouponCalendar,
const BusinessDayConvention exCouponConvention,
bool exCouponEndOfMonth)
bool exCouponEndOfMonth,
const DayCounter& stubAccrualDayCounter)
: Bond(settlementDays,
paymentCalendar==Calendar() ? calendar : paymentCalendar,
issueDate),
frequency_(tenor.frequency()), dayCounter_(accrualDayCounter) {
frequency_(tenor.frequency()), dayCounter_(accrualDayCounter),
stubDayCounter_(stubAccrualDayCounter) {

maturityDate_ = maturityDate;

Expand Down Expand Up @@ -120,6 +125,7 @@ namespace QuantLib {
cashflows_ = FixedRateLeg(schedule)
.withNotionals(faceAmount)
.withCouponRates(coupons, accrualDayCounter)
.withFirstPeriodDayCounter(stubAccrualDayCounter==DayCounter() ? accrualDayCounter : stubAccrualDayCounter)
.withPaymentCalendar(calendar_)
.withPaymentAdjustment(paymentConvention)
.withExCouponPeriod(exCouponPeriod,
Expand Down Expand Up @@ -168,5 +174,15 @@ namespace QuantLib {
QL_ENSURE(!cashflows().empty(), "bond with no cashflows!");
QL_ENSURE(redemptions_.size() == 1, "multiple redemptions created");
}
const DayCounter& FixedRateBond::dayCounter(const Date& d){
if (stubDayCounter_==DayCounter())
return dayCounter_;
else
QL_ENSURE(d!=Date(),"No Date given for bond with short stub dayCounter");
if(d<(cashflows()[1])->date())
return stubDayCounter_;
else
return dayCounter_;
}

}
9 changes: 6 additions & 3 deletions ql/instruments/bonds/fixedratebond.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ namespace QuantLib {
const Period& exCouponPeriod = Period(),
const Calendar& exCouponCalendar = Calendar(),
BusinessDayConvention exCouponConvention = Unadjusted,
bool exCouponEndOfMonth = false);
bool exCouponEndOfMonth = false,
const DayCounter& stubDayCounter = DayCounter());
/*! simple annual compounding coupon rates
with internal schedule calculation */
FixedRateBond(Natural settlementDays,
Expand All @@ -80,7 +81,8 @@ namespace QuantLib {
const Period& exCouponPeriod = Period(),
const Calendar& exCouponCalendar = Calendar(),
BusinessDayConvention exCouponConvention = Unadjusted,
bool exCouponEndOfMonth = false);
bool exCouponEndOfMonth = false,
const DayCounter& stubDayCounter = DayCounter());
//! generic compounding and frequency InterestRate coupons
FixedRateBond(Natural settlementDays,
Real faceAmount,
Expand All @@ -95,10 +97,11 @@ namespace QuantLib {
BusinessDayConvention exCouponConvention = Unadjusted,
bool exCouponEndOfMonth = false);
Frequency frequency() const { return frequency_; }
const DayCounter& dayCounter() const { return dayCounter_; }
const DayCounter& dayCounter(const Date& d=Date());
protected:
Frequency frequency_;
DayCounter dayCounter_;
DayCounter stubDayCounter_;
};

}
Expand Down

0 comments on commit 4d89058

Please sign in to comment.