Core mechanism
Paths provide realised future cash flows; regression estimates conditional continuation value from state variables; the exercise policy then selects exercise or continuation path by path.
TeaVM runs the Java Longstaff-Schwartz policy optimizer. The price is a lower bound; the spot Greek is the envelope-theorem sensitivity at the fitted policy.
The browser Java library uses its built-in gradient ascent and line search (up to 40 iterations). The original TypeScript task remains in the repository.
This exact source runs in TeaVM. Form changes update its Java literals and reset manual edits.
import com.nablatensor.quant.BermudanLsm;
import com.nablatensor.quant.EquityMarket;
import com.nablatensor.quant.OptionTypeEnum;
public final class BermudanLsmRiskStudio {
private BermudanLsmRiskStudio() {}
public static void main(String[] args) {
EquityMarket market = EquityMarket.of()
.spot(40)
.strike(40)
.vol(20 / 100.0)
.rate(6 / 100.0)
.maturity(1)
.build();
int dates = 8, stepsPerDate = 4;
int degree = 2;
long paths = 1500L, seed = 42L;
BermudanLsm.Result r = BermudanLsm.price(market, OptionTypeEnum.PUT, dates, stepsPerDate, degree,
0.6, paths, seed);
System.out.println("RESULT|" + r.price() + "|" + r.europeanFloor() + "|" + r.standardError()
+ "|" + r.earlyExercisePremium() + "|" + r.greeks()
.spot() + "|" + r.greeks()
.vol() + "|" + r.greeks()
.rate() + "|" + r.iterations() + "|" + r.converged());
double[][] b = r.boundaryCoefficients();
for (int d = 0; d < b.length; d++) {
String line = "BOUNDARY|" + d;
for (int j = 0; j < b[d].length; j++) line += "|" + b[d][j];
System.out.println(line);
}
}
}
Least-squares Monte Carlo estimates the continuation value needed to decide whether a Bermudan option should exercise at each date.
Paths provide realised future cash flows; regression estimates conditional continuation value from state variables; the exercise policy then selects exercise or continuation path by path.
Choose exercise dates, state basis and regression diagnostics; use independent paths or robust validation where appropriate; and report policy sensitivity alongside price and Greeks.
*Keywords: longstaff schwartz java, least squares monte carlo java, american option monte carlo java, bermudan option pricing java, lsm java, policy optimisation exercise boundary java*
Feature F1. The BermudanOption shell had the exercise-schedule machinery and a pluggable continuation value, but no way to *fit* the continuation. This adds it — by policy optimisation rather than a probe replay, so the whole valuation stays on one recorded tape.
The continuation value at each exercise date is a low-degree polynomial in log-moneyness whose coefficients beta are chosen to maximise the price under the smoothed exercise rule:
The coefficient gradient comes from MultiOutput (one forward sweep, one reverse sweep per output), exactly like every other adjoint calibration in the library; a backtracking gradient ascent drives beta.
The estimated exercise boundary introduces regression and simulation error. A reported Greek reflects that chosen policy and needs careful interpretation.