Re: Floating Rate bond pricing related questions in QL and QLXL
Posted by christos.arvanitis on
URL: http://quantlib.414.s1.nabble.com/Floating-Rate-bond-pricing-related-questions-in-QL-and-QLXL-tp14476p14481.html
Dear Luigi,
Thank you very much for your reply.
1. It is clear to me by know that whenever i have a floater without a cap or floor no optionlet vol is needed to pass to the coupon pricer. In fact the coupon pricer is not neeeded at all.
2. For the cpp code issue i have to tell that i dont understand fully what is going on........!
I have not manage to change properly the bond values with the changes induced by the bps change.
As far as I understand setValue() is a modifier method for SimpleQuote
I have instrumentsB which is a vector of shared_ptr<BondHelper> with a quoteHandle attached which is initiated by a SimpleQuote.
Therefore it looked reasonable to me to mimic the original code from the example FittedBondCurve.cpp of QL examples which compiles without a problem
Below I copy the part of the original code from the QL example and my code for reference
If way is not compiling properly can you suggest a code piece which can change the bond quotes by applying the bps change?
a. FittedBondCurve.cpp example loop across bonds
for (Size k=0; k<LENGTH(lengths)-1; k++) {
Real P = instrumentsA[k]->quote()->value(); // retrieve quote object & value from instrumentsA
const Bond& b = *instrumentsA[k]->bond(); // retrieve bond object from instrumentsA
// Calculate YTM
// BondFunctions is a structure containing Bond calculation methods
Rate ytm = BondFunctions::yield(b, // Bond object
P, // value clean price
dc, // day-counter
Compounded, // compounding
frequency, // Annual
today); // calculation date
// Calculate duration
Time dur = BondFunctions::duration(b, // Bond object
ytm, // yield
dc, // day-counter
Compounded, // compounding
frequency, // Annual
Duration::Modified, // modified duration
today); // calculation date
// Calculate convexity
Real convexity = BondFunctions::convexity(
b,
ytm,
dc,
Compounded,
frequency,
today);
// Rate shift
const Real bpsChange = 5.;
// dP = -dur * P * dY+0.5*P^2*convexity*dy^2
Real deltaP = -dur * P * (bpsChange/10000.)+ // duration correction
0.5*pow(P,2)*convexity*pow(bpsChange/10000.,2); // conv correction
// set calculate corrected values
quote[k+1]->setValue(P + deltaP);
}
which compiles fine
b. my code which in fact is a copy !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
for (Size k=0; k<LENGTH(mat_fix)-1; k++) { //start from 0
// retrieve quote object & value from instruments
Real P = instrumentsB[k]->quote()->value();
// retrieve bond object from instruments
const Bond& b = *instrumentsB[k]->bond();
// Calculate YTM
// BondFunctions is a structure containing Bond calculation methods
Rate ytm = BondFunctions::yield(b, // Bond object
P, // value clean price
dc_AA, // day-counter
Compounded, // compounding
Annual, // freq
today); // calculation date
// Calculate Duration
Time dur = BondFunctions::duration(b, // Bond object
ytm, // yield
dc_AA, // day-counter
Compounded, // compounding
Annual, // freq
Duration::Modified, // modified duration
today); // calculation date
// Calculate Convexity
Real convexity = BondFunctions::convexity(b,
ytm,
dc_AA,
Compounded,
Annual,
today);
// Rate shift
const Real bpsChange = 5.;
// dP = -dur * P * dY+0.5*P^2*convexity*dy^2
// duration correction
Real deltaP = -dur * P * (bpsChange/10000.)
// convexity correction
+0.5*pow(P,2)*convexity*pow(bpsChange/10000.,2);
// set calculate corrected values
quote[k+1]->setValue(P + deltaP);
}
Thanks in advance for the support and help provided
christos arvanitis