Function1D<Double, Double> payoff = ICP.getEuropeanPayoff(k, isCall);
BoundaryCondition lower;
BoundaryCondition upper;
PDEResults1D res;
if (isAmerican) {
if (isCall) {
lower = new NeumannBoundaryCondition(0.0, sMin, true);
upper = new NeumannBoundaryCondition(1.0, sMax, false);
} else {
lower = new NeumannBoundaryCondition(-1.0, sMin, true);
upper = new NeumannBoundaryCondition(0.0, sMax, false);
}
final Function<Double, Double> func = new Function<Double, Double>() {
@Override
public Double evaluate(Double... tx) {
final double x = tx[1];
return isCall ? Math.max(x - k, 0.0) : Math.max(k - x, 0);
}
};
final FunctionalDoublesSurface free = new FunctionalDoublesSurface(func);
if (USE_BURNIN) {
PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> dataBurn = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(coef, payoff, lower, upper, free, gridBurn);
PDEResults1D resBurn = INITIAL_SOLVER.solve(dataBurn);
PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> data = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(coef, resBurn.getTerminalResults(), lower, upper, free, grid);
res = SOLVER.solve(data);
} else {
PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> data = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(coef, payoff, lower, upper, free, grid);
res = SOLVER.solve(data);
}
} else {
if (isCall) {
lower = new NeumannBoundaryCondition(0.0, sMin, true);
Function1D<Double, Double> upFunc = new Function1D<Double, Double>() {
@Override
public Double evaluate(Double time) {
return Math.exp(-q * time);
}
};
upper = new NeumannBoundaryCondition(upFunc, sMax, false);
} else {
Function1D<Double, Double> downFunc = new Function1D<Double, Double>() {
@Override
public Double evaluate(Double time) {
return -Math.exp(-q * time);
}
};
lower = new NeumannBoundaryCondition(downFunc, sMin, true);
upper = new NeumannBoundaryCondition(0.0, sMax, false);
}
if (USE_BURNIN) {
PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> dataBurn = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(coef, payoff, lower, upper, gridBurn);
PDEResults1D resBurn = INITIAL_SOLVER.solve(dataBurn);
PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> data = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(coef, resBurn.getTerminalResults(), lower, upper, grid);
res = SOLVER.solve(data);
} else {
PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients> data = new PDE1DDataBundle<ConvectionDiffusionPDE1DCoefficients>(coef, payoff, lower, upper, grid);
res = SOLVER.solve(data);
}