Results 1 to 7 of 7

Thread: Getting incorrect mduration value

  1. #1
    Junior Member
    Join Date
    Mar 2008
    Posts
    3

    Error in getting mduration

    Hello,

    I am jmsl library to calculate the mduration. I am getting the same mduration value for the different Day count basis value. But when I try the same thing is excel it returns a different value. For example all three examples given below returning the same mduration value.

    GregorianCalendar date1 .......
    GregorianCalendar date2 .......
    double coupon = 0.059;
    double yield = 0.1013;
    int freq = 1;


    double duration = Bond.mduration(settlement, maturity, coupon,
    yield, freq, DayCountBasis.BasisActualActual);

    duration = Bond.mduration(settlement, maturity, coupon,
    yield, freq, DayCountBasis.BasisActual360);

    duration = Bond.mduration(settlement, maturity, coupon,
    yield, freq, DayCountBasis.BasisActual365);

    All above three calculation returns the same value. But not in excel mduration formula.

    thanks
    Vijay

  2. #2
    Junior Member
    Join Date
    Mar 2008
    Posts
    3

    Getting incorrect mduration value

    Hello,

    My below code calculates the mduration.

    GregorianCalendar settlement = parse("2008-04-08");
    GregorianCalendar maturity = parse("2013-03-20");
    double coupon = 0.075;
    double yield = 0.1181;
    int freq = 1;
    double duration = Bond.mduration(settlement, maturity, coupon,
    yield, freq, DayCountBasis.BasisActual360);

    The output is : 3.785622161480098

    For the same input values the output returned in excel mduration formula is : 3.784975544

    Let me why this difference is coming. Also this causing us some calculation errors in the end result.

    thanks
    Vijay

  3. #3
    Senior Member
    Join Date
    Sep 2005
    Posts
    105
    I get the same problem as well. I'll have to log this is something to be looked at by development. If there is a workaround, I will post it here.

    -Merv

  4. #4
    Senior Member ed's Avatar
    Join Date
    Aug 2005
    Posts
    312
    Since Excel is giving a different answer, it would help if you could supply a more complete example, and we could look into the details.
    [edit: never mind, I see the post in another thread; I'll merge the threads]


    I tested the example in the JMSL documentation using Java and Excel, but they both give the same answer for all 3 day count basis values so it might not be the best example to use.


    The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.

  5. #5
    Junior Member
    Join Date
    Mar 2008
    Posts
    3

    error getting mduration value

    ed,

    I am always getting the incorrect mduration value for the DayCountBasis 'BasisActual365' and 'BasisActual360'.

    Below are my examples:

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar cal1 = Calendar.getInstance();
    cal1.setTime(sdf.parse("2008-04-16"));
    GregorianCalendar date1 = (GregorianCalendar)cal1;
    Calendar cal2 = Calendar.getInstance();
    cal2.setTime(sdf.parse("2013-03-20"));
    GregorianCalendar date2 = (GregorianCalendar)cal2;
    double coupon = 0.05;
    double yield = 0.0926;
    int freq = 4;
    DayCountBasis dcb1 = DayCountBasis.BasisActual360;
    double duration1 = Bond.mduration(date1, date2, coupon,
    yield, freq, dcb1);
    System.out.println("The ACT/360 duration of the bond with" +
    "\nQuarterly interest payments is " + duration1);

    DayCountBasis dcb2 = DayCountBasis.BasisActual365;
    double duration2 = Bond.mduration(date1, date2, coupon,
    yield, freq, dcb2);
    System.out.println("The ACT/365 duration of the bond with" +
    "\nQuarterly interest payments is " + duration2);

    For both 360 and 365 the mduration value I am getting back is 4.21701138858181

    If I use the same inout values in excel then the mduration value I am getting back is
    For BasisActual360 the mduration value is : 4.215417844
    For BasisActual365 the mduration value is : 4.216421996

    Any help on this issue is much appreciated.

    thanks
    Vijay

  6. #6
    Senior Member ed's Avatar
    Join Date
    Aug 2005
    Posts
    312
    One of us will have a closer look at this later today, but please check to make sure the Frequency is the same between Excel and JMSL. In the first example, this is "1" but in the second example it is "4". I'd suggest using the static fields instead (at least it becomes a little more readable then).


    The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.

  7. #7
    Junior Member
    Join Date
    Nov 2014
    Posts
    1
    Hello,

    I am jmsl library to calculate the mduration. I am getting the same mduration value for the different Day count basis value. But when I try the same thing is excel it returns a different value. For example all three examples given below returning the same mduration value.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •