Example: Treasury Bill Yield

The yield for a 1 year Treasury bill is returned in this example.

import com.imsl.finance.*;
import java.text.*;
import java.util.*;

public class tbillyieldEx1 {

    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 price = 94.93;
        double tbillyield = Bond.tbillyield(settlement, maturity, price);
        System.out.println("The yield for the T-bill is " + tbillyield);
    }
}

Output

The yield for the T-bill is 0.05267616080486118
Link to Java source.