Example: Treasury Bill Price
The price per $100 face value for a 1 year Treasury bill is returned in this example.
import com.imsl.finance.*;
import java.text.*;
import java.util.*;
public class tbillpriceEx1 {
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 discount = .05;
double tbillprice = Bond.tbillprice(settlement, maturity, discount);
System.out.println("The price per $100 face value for the T-bill is "
+ tbillprice);
}
}
Output
The price per $100 face value for the T-bill is 94.93055555555556
Link to Java source.