Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-calculate the FixedRateCoupon::amount() #1759

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions ql/cashflows/fixedratecoupon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ namespace QuantLib {
const Date& refPeriodStart,
const Date& refPeriodEnd,
const Date& exCouponDate)
: Coupon(paymentDate, nominal, accrualStartDate, accrualEndDate,
refPeriodStart, refPeriodEnd, exCouponDate),
rate_(InterestRate(rate, dayCounter, Simple, Annual)) {}
: FixedRateCoupon(paymentDate,
nominal,
InterestRate(rate, dayCounter, Simple, Annual),
accrualStartDate,
accrualEndDate,
refPeriodStart,
refPeriodEnd,
exCouponDate) {}

FixedRateCoupon::FixedRateCoupon(const Date& paymentDate,
Real nominal,
Expand All @@ -57,17 +62,10 @@ namespace QuantLib {
refPeriodStart,
refPeriodEnd,
exCouponDate),
rate_(std::move(interestRate)) {}

Real FixedRateCoupon::amount() const {
calculate();
return amount_;
}

void FixedRateCoupon::performCalculations() const {
amount_ = nominal() * (rate_.compoundFactor(accrualStartDate_, accrualEndDate_,
refPeriodStart_, refPeriodEnd_) -
1.0);
rate_(std::move(interestRate)) {
amount_ = Coupon::nominal() * (rate_.compoundFactor(accrualStartDate_, accrualEndDate_,
refPeriodStart_, refPeriodEnd_) -
1.0);
}

Real FixedRateCoupon::accruedAmount(const Date& d) const {
Expand Down
8 changes: 2 additions & 6 deletions ql/cashflows/fixedratecoupon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,9 @@ namespace QuantLib {
const Date& refPeriodEnd = Date(),
const Date& exCouponDate = Date());
//@}
//! \name LazyObject interface
//@{
void performCalculations() const override;
//@}
//! \name CashFlow interface
//@{
Real amount() const override;
Real amount() const override { return amount_; }
//@}
//! \name Coupon interface
//@{
Expand All @@ -81,7 +77,7 @@ namespace QuantLib {
//@}
private:
InterestRate rate_;
mutable Real amount_;
Real amount_;
};


Expand Down