On Thu, 19 Dec 2013 08:53:14 -0500, [email protected] wrote:
Gilles,
Thank you for answering. PowellOptimizer did not work very well for
our
particular function, and other optimizers in scalar.noderiv are not
easily
understandable.
It would be interesting to know what you tested, and what did not work
as
you expected, in order to look for bugs in "PowellOptimizer".
For the other optimizer, it is perhaps an issue of setting good
parameters
and initial guess...
BOBYQAOptimizer usually works well. Do you have
suggestions that we might work around this particular case so it does
not
hang?
I have no idea.
If I had to debug it, I'd first trace the code execution to locate
where it
hangs.
We minimize LS with grid (x,y) having 9 points.
Did you consider using the "LevenbergMarquardtOptimizer"?
Best regards,
Gilles
Andrew
class LS implements MultivariateFunction {
private BS bs = new BS();
private double[] x;
private double[] y;
private double const1;
private int optionType;
public LS(double[] x, double[] y, int optionType, double
const1) {
this.x = x;
this.y = y;
this.optionType = optionType;
this.const1 = const1;
}
@Override
public double value(double point[]) {
int len = x.length;
double val = 0;
for (int i=0; i<len; i++) {
double yc = bs.f2(x[i], point[0]*const1,
point[1],
point[2], optionType);
val += Math.pow(yc-y[i], 2);
}
return val;
}
}
class BS {
public double blackScholes(double price, double strike,
double
time, double vol, int optionType) {
double volrootime = Math.pow(time, 0.5) * vol;
double topline1 = Math.log(price/strike);
double topline2 = Math.pow(vol, 2)/2* time;
double topline = topline1 + topline2;
double d1 = topline / volrootime;
double d2 = d1 - volrootime;
double val = 0.0;
NormalDistribution normal = new NormalDistribution();
if (optionType==1)
val = (price * normal.cumulativeProbability(d1) -
strike *
normal.cumulativeProbability(d2));
else
val = (strike * normal.cumulativeProbability(-d2) -
price
* normal.cumulativeProbability(-d1));
return val;
}
public double f2(double x, double ah, double ai, double aj,
int
ak) {
return ah*bScore(x, ai, aj, ak);
}
public double bScore(double price, double strike, double vol,
int
optionType) {
return blackScholes(price, strike, 1, vol,
optionType);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]