Re: Question about using QuantLib

Posted by Luigi Ballabio on
URL: http://quantlib.414.s1.nabble.com/Question-about-using-QuantLib-tp3801p3802.html

Hi Dale,

On 05/25/2005 09:50:51 PM, Dale Smith wrote:
> I am a new QuantLib user. Right now I'm trying to use QuantLib to
> price straight Treasury bonds using a specified yield curve. I have  
> read over the documentation, and more importantly, looked at the  
> examples and test suite code. I still don't have a picture about how  
> things should work.
> I'm following the swap valuation example to get a Handle to a
> YieldTermStructure. My specific question is how do I get back the
> discretely compounded forward rates for use in the pricing formula  
> for the Treasury bond.

You can get the discount factors directly from the curve; once you have  
a handle h, you can use h->discount(d) to get the discount factor at a  
date d. You can then obtain the price as the sum of the discounted  
coupons. By the way, this is already implemented in the  
performCalculations() method of class Bond; you can write e.g.

Handle<YieldTermStructure> h;
...initialize the term structure...
FixedCouponBond bond(parameters including h);
Real price = bond.cleanPrice();

to trigger the calculation.

On the other hand, if you want to get at the single forward rates, you  
can use the forwardRate() method of YieldTermStructure. Given a handle  
h, you can write e.g.

InterestRate f = h->forwardRate(d1,d2,dayCounter,Compounded,Annual);

to get the forward (where d1 and d2 are the start and end dates of the  
coupon and dayCounter its day-count convention.) You can then combine  
the forwards according to the formula.

One final remark: the yield term-structure in the swap-valuation  
example is bootstrapped based on deposit-rate and swap-rate fixings,  
which might or might not be appropriate for bond pricing. We'd welcome  
any contribution aimed at obtaining a proper bond curve.

Later,
        Luigi


----------------------------------------

The rule on staying alive as a forecaster is to give 'em a number or
give 'em a date, but never give 'em both at once.
-- Jane Bryant Quinn