Example: Yield on a Security Which Pays at Maturity
The yield on a bond which pays at maturity is returned in this example.
import com.imsl.finance.*;
import java.text.*;
import java.util.*;
public class yieldmatEx1 {
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("8/1/85");
GregorianCalendar maturity = parse("7/1/95");
GregorianCalendar issue = parse("7/1/85");
double rate = .06;
double price = 95.40663;
DayCountBasis dcb = DayCountBasis.BasisNASD;
double yieldmat = Bond.yieldmat(settlement, maturity, issue, rate,
price, dcb);
System.out.println("The yield on a bond which pays at maturity is " +
yieldmat);
}
}
Output
The yield on a bond which pays at maturity is 0.06739051278091948
Link to Java source.