PDA

View Full Version : Getting incorrect mduration value



Vijay
03-19-2008, 11:40 AM
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

Vijay
03-19-2008, 12:11 PM
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

pate
03-19-2008, 12:38 PM
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

ed
03-19-2008, 12:41 PM
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.

Vijay
03-20-2008, 03:35 AM
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

ed
03-20-2008, 05:28 AM
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 (file:///C:/Program%20Files/VNI/imsl/jmsl500/manual/api/com/imsl/finance/Bond.html#field_summary) instead (at least it becomes a little more readable then).

nawaz
11-09-2014, 09:47 PM
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.