29 const std::vector<Real>& notionals,
31 const std::vector<Rate>& coupons,
34 const Date& issueDate,
35 const Period& exCouponPeriod,
38 bool exCouponEndOfMonth,
39 const std::vector<Real>& redemptions,
41 :
Bond(settlementDays, schedule.calendar(), issueDate),
42 frequency_(schedule.tenor().frequency()),
43 dayCounter_(accrualDayCounter) {
67 Date maturityDate = startDate + bondLength;
76 std::pair<Integer,Integer> daysMinMax(
const Period& p) {
79 return std::make_pair(p.length(), p.length());
81 return std::make_pair(7*p.length(), 7*p.length());
83 return std::make_pair(28*p.length(), 31*p.length());
85 return std::make_pair(365*p.length(), 366*p.length());
91 bool isSubPeriod(
const Period& subPeriod,
92 const Period& superPeriod,
95 std::pair<Integer, Integer> superDays(daysMinMax(superPeriod));
96 std::pair<Integer, Integer> subDays(daysMinMax(subPeriod));
100 ((
Real)superDays.first)/((
Real)subDays.second);
101 Real maxPeriodRatio =
102 ((
Real)superDays.second)/((
Real)subDays.first);
103 auto lowRatio =
static_cast<Integer>(std::floor(minPeriodRatio));
104 auto highRatio =
static_cast<Integer>(std::ceil(maxPeriodRatio));
107 for(
Integer i=lowRatio; i <= highRatio; ++i) {
108 Period testPeriod = subPeriod * i;
109 if(testPeriod == superPeriod) {
126 Real initialNotional) {
129 "Bond frequency is incompatible with the maturity tenor");
131 std::vector<Real> notionals(nPeriods+1);
132 notionals.front() = initialNotional;
133 Real coupon = couponRate /
static_cast<Real>(sinkingFrequency);
134 Real compoundedInterest = 1.0;
135 Real totalValue = std::pow(1.0+coupon, nPeriods);
136 for (
Size i = 0; i < (
Size)nPeriods-1; ++i) {
137 compoundedInterest *= (1.0 + coupon);
138 Real currentNotional = 0.0;
139 if(coupon < 1.0e-12) {
140 currentNotional = initialNotional*(1.0 - (i+1.0)/nPeriods);
143 initialNotional*(compoundedInterest - (compoundedInterest-1.0)/(1.0 - 1.0/totalValue));
145 notionals[i+1] = currentNotional;
147 notionals.back() = 0.0;
amortizing fixed-rate bond
Cash flow vector builders.
AmortizingFixedRateBond(Natural settlementDays, const std::vector< Real > ¬ionals, Schedule schedule, const std::vector< Rate > &coupons, const DayCounter &accrualDayCounter, BusinessDayConvention paymentConvention=Following, const Date &issueDate=Date(), const Period &exCouponPeriod=Period(), const Calendar &exCouponCalendar=Calendar(), BusinessDayConvention exCouponConvention=Unadjusted, bool exCouponEndOfMonth=false, const std::vector< Real > &redemptions={ 100.0 }, Integer paymentLag=0)
const std::vector< Real > & notionals() const
void addRedemptionsToCashflows(const std::vector< Real > &redemptions=std::vector< Real >())
const Leg & cashflows() const
const Leg & redemptions() const
helper class building a sequence of fixed rate coupons
FixedRateLeg & withNotionals(Real)
FixedRateLeg & withPaymentLag(Integer lag)
FixedRateLeg & withPaymentAdjustment(BusinessDayConvention)
FixedRateLeg & withCouponRates(Rate, const DayCounter &paymentDayCounter, Compounding comp=Simple, Frequency freq=Annual)
FixedRateLeg & withExCouponPeriod(const Period &, const Calendar &, BusinessDayConvention, bool endOfMonth=false)
const Date & endDate() const
#define QL_ENSURE(condition, message)
throw an error if the given post-condition is not verified
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Frequency
Frequency of events.
BusinessDayConvention
Business Day conventions.
unsigned QL_INTEGER Natural
positive integer
QL_INTEGER Integer
integer number
std::size_t Size
size of a container
Schedule sinkingSchedule(const Date &startDate, const Period &bondLength, const Frequency &frequency, const Calendar &paymentCalendar)
returns a schedule for French amortization
std::vector< Real > sinkingNotionals(const Period &bondLength, const Frequency &sinkingFrequency, Rate couponRate, Real initialNotional)
returns a sequence of notionals for French amortization