package com.imsl.test.example.finance; import com.imsl.finance.*; import java.text.*; import java.util.*; /** *

* Computes a specified year fraction.

* The year fraction of a 30/360 year starting 8/1/85 and ending 7/1/86 is * returned in this example. * * * @see Code * @see Output */ public class BondYearfracEx1 { static final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.US); static private GregorianCalendar parse(String s) throws ParseException { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(dateFormat.parse(s)); return cal; } public static void main(String args[]) throws ParseException { GregorianCalendar start = parse("8/1/85"); GregorianCalendar end = parse("7/1/86"); DayCountBasis dcb = DayCountBasis.BasisNASD; double yearfrac = Bond.yearfrac(start, end, dcb); System.out.println("The year fraction of the 30/360 period is " + yearfrac); } }