Price of a Discounted Security
The price of a discounted 1 year bond is returned in this example.priceyieldEx1
import com.imsl.finance.*;
import java.text.*;
import java.util.*;
public class priceyieldEx1 {
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 yield = 0.010055244588347783;
double redemption = 105.;
DayCountBasis dcb = DayCountBasis.BasisNASD;
double priceyield = Bond.priceyield(settlement, maturity,
yield, redemption, dcb);
System.out.println("The price of the discounted bond is "
+ priceyield);
}
}
Output
The price of the discounted bond is 95.40663
Link to Java source.