Re: Yield, Macaulay duration and Convexity calculation for Notes/Bonds

Posted by Smith, Dale (Norcross) on
URL: http://quantlib.414.s1.nabble.com/Yield-Macaulay-duration-and-Convexity-calculation-for-Notes-Bonds-tp14641p14646.html

Thanks for posting your code. It’s refreshing to see someone actually get this close to Bloomberg’s results. I salute you, as I know how hard it is to get this far. What yield curve are you using on Bloomberg – I25? How are you building your yield curve in QuantLib?

 

Based on my own experience, I would say you are very close to Bloomberg. I suspect it’s simply not worth chasing down the discrepancy, unless you want to fully investigate differences in

 

·         Day counts

·         Business rules (modified following, etc)

·         Yield curve interpolation

·         Compounding

·         Max evaluations

·         Etc

 

In other words, subtle differences in, say, Actual/Actual implementations between QuantLib and Bloomberg may be causing these small differences. Is it really worth chasing them down when you can’t necessarily change them to match the Bloomberg implementation?

 

Dale Smith, Ph.D.

Senior Financial Quantitative Analyst

Financial & Risk Management Solutions

Fiserv

Office: 678-375-5315

www.fiserv.com

 

From: Senevi J Kankanamge Don [mailto:[hidden email]]
Sent: Monday, November 04, 2013 10:25 AM
To: [hidden email]
Subject: [Quantlib-users] Yield, Macaulay duration and Convexity calculation for Notes/Bonds

 

Hi,

 

I am attempting to use QuantLib library in order to calculate yield, Macaulay duration and convexity for US Treasury Notes and Bonds.

 

This is how the values compare in Bloomberg and QuantLib for one example where the price is 99.8984375.

 

Bloomberg                          QuantLib

Yield                                      0.302775                              0.3027679582

Macaulay Duration          1.928                                     1.9129221698

Convexity                            0.047                                     0.0460608896

 

Can you please let me know what I need to change in my code in order to get the results matching with Bloomberg?

 

This is a snippet of my code.

 

 

        double ql_price = 99.8984375;

 

        Date settlementDate = Date(25, Oct, 2013);

        Date firstCouponDate = Date(31, Mar, 2014);

        Date datedDate = Date(30, Sep, 2013);

        Date maturityDate = Date(30, Sep, 2015);

 

        //

        // Parameters required to define the bond

        //

        Natural settlementDays = 0;

        Real faceAmount = 100;

        DayCounter bondDayCount = ActualActual(ActualActual::Bond);

        BusinessDayConvention paymentConvention = ModifiedFollowing;

        Real redemption = 100.0;

        Compounding compoundingMethod = SimpleThenCompounded;

        DateGeneration::Rule dateGeneration = DateGeneration::Forward;

        Frequency frequency = Semiannual;

        Real accuracy = 1.0e-11;

        Size maxEvaluations = 100;

 

 

        //

        // Create the Schedule

        //

        Schedule fixedBondSchedule(

                                    datedDate,                                  // Dated Date

                                    maturityDate,                               // Maturity Date

                                    Period(Semiannual),                         // Period

                                    UnitedStates(UnitedStates::GovernmentBond), // Calendar

                                    Unadjusted,                                 // BusinessDayConvention - convention

                                    Unadjusted,                                 // BusinessDayConvention - terminationDateConvention

                                    dateGeneration,                             // DateGeneration::Rule rule

                                    false,                                      // endOfMonth

                                    firstCouponDate);                           // First Date

 

 

        //

        // Create the Fixed Rate Bond

        //

        FixedRateBond bond(

                            settlementDays,                        // Settlement Days

                            faceAmount,                            // Face Amount

                            fixedBondSchedule,                     // Schedule

                            std::vector<Rate>(1, ql_coupon),       // Coupons

                            bondDayCount,                          // DayCounter

                            paymentConvention,                     // BusinessDayConvention

                            redemption);                           // Redemption

 

 

        Real ql_yield       = BondFunctions::yield( bond, ql_price, bondDayCount, compoundingMethod, frequency, settlementDate, accuracy, maxEvaluations);

 

        InterestRate interestRate(ql_yield, bondDayCount, compoundingMethod, frequency );

        Real ql_convexity = BondFunctions::convexity( bond, interestRate, settlementDate );

 

        Compounding compoundingMethod4Duration = Compounded;

        Time ql_duration = BondFunctions::duration( bond, ql_yield, bondDayCount, compoundingMethod4Duration, frequency, Duration::Macaulay, settlementDate );

 

 

Thanks

-Senevi


------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users