Date issue = UtilFns.stringToDate(args[0].toString());
Date firI = UtilFns.stringToDate(args[1].toString());
Date settlement = UtilFns.stringToDate(args[2].toString());
if(settlement.before(issue))
{
throw new SSErrorXelException(SSError.NUM);
}
double rate = CommonFns.toNumber(args[3]).doubleValue();
double Par;
int freq;
try{
Par = CommonFns.toNumber(args[4]).doubleValue();
}catch(ClassCastException e){
Par = 10E+3; //provided as MSFT Excel help says
}
try{
freq = CommonFns.toNumber(args[5]).intValue();
}catch(ClassCastException e){
throw new SSErrorXelException(SSError.NUM);
}
int basis = 0;
boolean method = true;
if(args.length == 7)
{
try{
basis = basis(CommonFns.toNumber(args[6]).intValue());
}catch(ClassCastException e){
basis = 0;
}
}
else if(args.length == 8)
{
try{
basis = basis(CommonFns.toNumber(args[6]).intValue());
}catch(ClassCastException e){
basis = 0;
}
try{
method = CommonFns.toBoolean(args[7]);
}catch(ClassCastException e){
method = true;
}
}
if(!(freq == 1 || freq == 2 || freq == 4))
{
throw new SSErrorXelException(SSError.NUM);
}
if( rate <= 0 || Par <= 0)
{
throw new SSErrorXelException(SSError.NUM);
}
double result = 0;
//TODO:only only a few situations are correct
if(method) //because Par * rate / freq * diff * freq == Par * rate * diff