Example: Interest Rate of a Fully Invested Security

The discount rate of a 10 year bond is returned in this example.
import com.imsl.finance.*;
import java.text.*;
import java.util.*;

public class intrateEx1 {
    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 investment = 7000.;
        double redemption = 10000.;
        DayCountBasis dcb = DayCountBasis.BasisActual365;
        double intrate = Bond.intrate(settlement, maturity, investment,
        redemption, dcb);
        System.out.println("The interest rate of the bond is " +intrate);
    }
}

Output

The interest rate of the bond is 0.042833672351744644
Link to Java source.