Example: Yield on a Discounted Security
The yield on a discounted 10 year bond is returned in this example.
import com.imsl.finance.*;
import java.text.*;
import java.util.*;
public class yielddiscEx1 {
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 settlement = parse("7/1/85");
GregorianCalendar maturity = parse("7/1/95");
double price = 95.40663;
double redemption = 105.;
DayCountBasis dcb = DayCountBasis.BasisNASD;
double yielddisc = Bond.yielddisc(settlement, maturity, price,
redemption, dcb);
System.out.println("The yield on the discounted bond is " + yielddisc);
}
}
Output
The yield on the discounted bond is 0.010055244588347783
Link to Java source.