Example: Accrued Interest - Periodic Payments

In this example, the accrued interest is calculated for a bond which pays interest semiannually. The day count basis used is 30/360.
import com.imsl.finance.*;
import java.text.*;
import java.util.*;

public class accrintEx1 {
    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 issue = parse("10/1/91");
        GregorianCalendar firstCoupon = parse("3/31/92");
        GregorianCalendar settlement = parse("11/3/91");
        double rate = .06;
        double par = 1000.;
        int freq = Bond.SEMIANNUAL;
        DayCountBasis dcb = DayCountBasis.BasisNASD;
        double accrint = Bond.accrint(issue, firstCoupon, settlement, rate,
        par, freq, dcb);
        System.out.println("The accrued interest is " +accrint);
    }
}

Output

The accrued interest is 5.333333333333334
Link to Java source.