Example: Discount Rate for a Security

In this example, the discount rate for a security is returned.
import com.imsl.finance.*;
import java.text.*;
import java.util.*;

public class discEx1 {
    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("2/15/92");
        GregorianCalendar maturity = parse("6/10/92");
        double price = 97.975;
        double redemption = 100.;
        DayCountBasis dcb = DayCountBasis.BasisActual365;
        double disc = Bond.disc(settlement, maturity, price, redemption, dcb);
        System.out.println("The discount rate for the security is " +disc);
    }
}

Output

The discount rate for the security is 0.06371767241379328
Link to Java source.