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

Precompute annuities #1965

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,19 @@ namespace QuantLib {
// assuming terminal bond measure
// eq 5.4-5.7
const std::vector<Time>& taus=cs.rateTaus();
std::vector<Real> annuities(numberOfRates_);

for (Size j=0; j<numberOfRates_; ++j) {
annuities[j] = cs.coterminalSwapAnnuity(numberOfRates_, j);
}
for (Size k=0; k<numberOfFactors_; ++k) {
// taken care in the constructor
// wkpj1_[k][numberOfRates_-1]= 0.0;
// wkaj_[k][numberOfRates_-1] = 0.0;
for (Integer j=numberOfRates_-2; j>=static_cast<Integer>(alive_)-1; --j) {
// < W(k) | P(j+1)/P(n) > =
// = SR(j+1) a(j+1,k) A(j+1) / P(n) + SR(j+1) < W(k) | A(j+1)/P(n) >
Real annuity = cs.coterminalSwapAnnuity(numberOfRates_,j+1);
Real annuity = annuities[j+1];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can the same vector annuities be used also in the other loop ~20 lines below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! I'll make that change too, thanks for pointing it out. In fact the quantitative results stated above were including this change, but I forgot to add it when making the final PR.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks.

wkpj_[k][j+1]= SR[j+1] *
( pseudo_[j+1][k] * annuity + wkaj_[k][j+1] )+
pseudo_[j+1][k]*displacements_[j+1]* annuity;
Expand All @@ -108,7 +113,7 @@ namespace QuantLib {
// compute < Wk, PN/pn>
for (Size j=alive_; j<numberOfRates_; ++j)
{
wkajshifted_[k][j] = -wkaj_[k][j]/cs.coterminalSwapAnnuity(numberOfRates_,j)
wkajshifted_[k][j] = -wkaj_[k][j]/annuities[j]
+ wkpj_[k][numeraire_]
*numeraireRatio;
}
Expand Down
Loading