Example: Price of a Security

The price per $100 face value of a 10 year bond which pays interest semiannually is returned in this example.
import com.imsl.finance.*;
import java.text.*;
import java.util.*;

public class priceEx1 {
    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 rate = .06;
        double yield = .07;
        double redemption = 105.;
        int frequency = Bond.SEMIANNUAL;
        DayCountBasis dcb = DayCountBasis.BasisNASD;
        double price = Bond.price(settlement, maturity, rate, yield, 
        redemption, frequency, dcb);
        System.out.println("The price of the bond is " +price);
    }
}

Output

The price of the bond is 95.40662777118231
Link to Java source.