Example: Price of a Discounted Security

The price per $100 face value of a discounted 1 year bond is returned in this example.
import com.imsl.finance.*;
import java.text.*;
import java.util.*;

public class pricediscEx1 {
    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/86");
        double rate = .05;
        double redemption = 100.;
        DayCountBasis dcb = DayCountBasis.BasisNASD;
        double pricedisc = Bond.pricedisc(settlement, maturity,
        rate, redemption, dcb);
        System.out.println("The price of the discounted bond is " +pricedisc);
    }
}

Output

The price of the discounted bond is 95.0
Link to Java source.