Yield to Maturity and Duration example.

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

Yield to Maturity and Duration example.

mdp788
Hello,
I am new to Quantlib, and using the Java binding. I am interested in YTM, and duration calculation of Fixed as well floating rate coupon bond. Unfortunately I can't find any examples or docs on how to do so. Could you please point me to where I can find some example, or some other reference documents on how to do what I stated earlier.

Thanks a lor.
Reply | Threaded
Open this post in threaded view
|

Re: Yield to Maturity and Duration example.

Luigi Ballabio
On Wed, 2010-09-15 at 18:26 -0700, mdp788 wrote:
> I am new to Quantlib, and using the Java binding. I am interested in YTM,
> and duration calculation of Fixed as well floating rate coupon bond.
> Unfortunately I can't find any examples or docs on how to do so. Could you
> please point me to where I can find some example, or some other reference
> documents on how to do what I stated earlier.

Unfortunately, I have no example ready; however, once you have
instantiated your bond, you can extract its cashflows (by calling
bond.cashflows()) and pass them to the yield(...) and duration(...)
static methods of the CashFlows class.

Luigi


--

Humphrey's Requirements Uncertainty Principle:
For a new software system, the requirements will not be
completely known until after the users have used it.



------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Yield to Maturity and Duration example.

Dimathematician
I have some code which might help:

     boost::shared_ptr<YieldTermStructure> curvePtr=getBondYieldCurve();
// this function constructs the yield curve
    Handle<YieldTermStructure> curve(curvePtr);

    Natural settlementDays = 1;
    Calendar cal=UnitedStates(UnitedStates::GovernmentBond);
    Real faceAmount = 100.0;
    Date today(14,Sep,2009);
    Settings::instance().evaluationDate() = today;
    Date settlementDate=cal.advance(today,settlementDays,Days);
    Date maturityDate(15,Nov,2017);
    DayCounter dc=ActualActual(ActualActual::Bond);
    Date issueDate(15,Nov,2007);

    BusinessDayConvention bdc=Unadjusted;
   
    Schedule bondSchedule=MakeSchedule(issueDate,maturityDate,
Period(Semiannual), cal, bdc).backwards();

    std::vector<Date> couponDates=bondSchedule.dates();
   
    FixedRateBond fixedRateBond(
                 settlementDays,
                 faceAmount,
                 bondSchedule,
                 std::vector<Rate>(1, 0.0425),
                 dc,bdc,faceAmount,issueDate);

     boost::shared_ptr<PricingEngine> bondEngine(new
DiscountingBondEngine(curve));
     fixedRateBond.setPricingEngine(bondEngine);

     std::cout << "Clean Price:"<< fixedRateBond.cleanPrice() << std::endl;
     std::cout << "Dirty Price:"<< fixedRateBond.dirtyPrice() << std::endl;
   
     Real accruedInterest= fixedRateBond.dirtyPrice()-
fixedRateBond.cleanPrice();
     std::cout << "Accrued Interest:" << accruedInterest << std::endl;
   
     Rate yield=fixedRateBond.yield(dc,Compounded,Semiannual);
     InterestRate yieldRate=InterestRate(yield,dc,Compounded,Semiannual);
     std::cout << "Bond Yield:"<< yield << std::endl;
   
     Real
durationMod=CashFlows::duration(fixedRateBond.cashflows(),yieldRate,
Duration::Modified);
     std::cout << "Duration:" << - durationMod << std::endl;
     std::cout << "BPV:" <<
CashFlows::basisPointValue(fixedRateBond.cashflows(),yieldRate)*100 <<
std::endl;
   
     Real
convexity=CashFlows::convexity(fixedRateBond.cashflows(),yieldRate);
     std::cout << "Convexity:" << convexity << std::endl;
   



Luigi Ballabio schrieb:

> On Wed, 2010-09-15 at 18:26 -0700, mdp788 wrote:
>  
>> I am new to Quantlib, and using the Java binding. I am interested in YTM,
>> and duration calculation of Fixed as well floating rate coupon bond.
>> Unfortunately I can't find any examples or docs on how to do so. Could you
>> please point me to where I can find some example, or some other reference
>> documents on how to do what I stated earlier.
>>    
>
> Unfortunately, I have no example ready; however, once you have
> instantiated your bond, you can extract its cashflows (by calling
> bond.cashflows()) and pass them to the yield(...) and duration(...)
> static methods of the CashFlows class.
>
> Luigi
>
>
>  


------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev