Skip to content

Commit

Permalink
Merge pull request #788.
Browse files Browse the repository at this point in the history
Implement Bond::Price::Type parameter in Bond::yield() method
  • Loading branch information
lballabio committed Mar 31, 2020
2 parents 1ae07d9 + a94807e commit 47b54d7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
22 changes: 15 additions & 7 deletions ql/instruments/bond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,19 @@ namespace QuantLib {
Compounding comp,
Frequency freq,
Real accuracy,
Size maxEvaluations) const {
Size maxEvaluations,
Real guess,
Bond::Price::Type priceType) const {
Real currentNotional = notional(settlementDate());
if (currentNotional == 0.0)
return 0.0;

return BondFunctions::yield(*this, cleanPrice(), dc, comp, freq,
Real price = priceType == Bond::Price::Clean ? cleanPrice() : dirtyPrice();

return BondFunctions::yield(*this, price, dc, comp, freq,
settlementDate(),
accuracy, maxEvaluations);
accuracy, maxEvaluations,
guess, priceType);
}

Real Bond::cleanPrice(Rate y,
Expand All @@ -236,19 +241,22 @@ namespace QuantLib {
+ accruedAmount(settlement);
}

Rate Bond::yield(Real cleanPrice,
Rate Bond::yield(Real price,
const DayCounter& dc,
Compounding comp,
Frequency freq,
Date settlement,
Real accuracy,
Size maxEvaluations) const {
Size maxEvaluations,
Real guess,
Bond::Price::Type priceType) const {
Real currentNotional = notional(settlement);
if (currentNotional == 0.0)
return 0.0;

return BondFunctions::yield(*this, cleanPrice, dc, comp, freq,
settlement, accuracy, maxEvaluations);
return BondFunctions::yield(*this, price, dc, comp, freq,
settlement, accuracy, maxEvaluations,
guess, priceType);
}

Real Bond::accruedAmount(Date settlement) const {
Expand Down
8 changes: 6 additions & 2 deletions ql/instruments/bond.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ namespace QuantLib {
Compounding comp,
Frequency freq,
Real accuracy = 1.0e-8,
Size maxEvaluations = 100) const;
Size maxEvaluations = 100,
Real guess = 0.05,
Bond::Price::Type priceType = Bond::Price::Clean) const;

//! clean price given a yield and settlement date
/*! The default bond settlement is used if no date is given. */
Expand Down Expand Up @@ -200,7 +202,9 @@ namespace QuantLib {
Frequency freq,
Date settlementDate = Date(),
Real accuracy = 1.0e-8,
Size maxEvaluations = 100) const;
Size maxEvaluations = 100,
Real guess = 0.05,
Bond::Price::Type priceType = Bond::Price::Clean) const;

//! accrued amount at a given date
/*! The default bond settlement is used if no date is given. */
Expand Down

0 comments on commit 47b54d7

Please sign in to comment.