problem to get the yield to maturity for a zero coupon bond

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

problem to get the yield to maturity for a zero coupon bond

Adjriou Belak
Hi,
 
there is a problem when quantlib is trying to get the yield from the price for zero coupon bond.
 
In the dirtyPriceFromYield() method, quantlib sets time t2 to ( CouponDate - LastCouponDate) but in Once frequency lastCouponDate is the issue Date so the t2 time is wrong in this case :
 
   Real price = 0.0;
            DiscountFactor discount = 1.0;
            Date lastDate = Date();
            for (Size i=0; i<cashflows.size(); ++i) {
                // discard expired coupons
                #if QL_TODAYS_PAYMENTS
                if (cashflows[i]->date() < settlement)
                #else
                if (cashflows[i]->date() <= settlement)
                #endif
                    continue;
                Date nextDate = cashflows[i]->date();
                Real amount = cashflows[i]->amount();
                if (i == cashflows.size()-1)
                    amount += redemption;
                Time t1, t2;
                if (lastDate == Date()) {
                    // first not-expired coupon
                    if (i > 0) {
                        lastDate = cashflows[i-1]->date();
                    } else {
                        boost::shared_ptr<Coupon> coupon =
                            boost::dynamic_pointer_cast<Coupon>(cashflows[i]);
                        if (coupon)
                            lastDate = coupon->accrualStartDate();
                        else
                            lastDate = nextDate - 1*Years;
                    }
                    t1 = dayCounter.yearFraction(settlement, nextDate,
                                                 lastDate, nextDate);
                    t2 = dayCounter.yearFraction(lastDate, nextDate);
                } else  {
                    t1 = dayCounter.yearFraction(lastDate, nextDate);
                    t2 = t1;
                }
                discount /= QL_POW(1 + yield*t2, t1/t2);
                price += amount * discount;
                lastDate = nextDate;
            }
            return price;
        }
 
regards.



Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos mails !
Créez votre Yahoo! Mail
Reply | Threaded
Open this post in threaded view
|

Re: problem to get the yield to maturity for a zero coupon bond

Luigi Ballabio
On 04/14/05 11:02:57, Adjriou Belak wrote:
> Hi,
>
> there is a problem when quantlib is trying to get the yield from the  
> price for zero coupon bond.

Adjriou,
        this should be fixed in the upcoming 0.3.9 release. Can you check  
that it actually works? (You can check it out from CVS using the  
'R000309f0-branch' tag.)

Later,
        Luigi

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

I have yet to see any problem, however complicated, which, when you
looked at it in the right way, did not become still more complicated.
-- Poul Anderson