black-scholes-model
Version:
Complete plug and play Black-Scholes-Merton model for option pricing with features including implied volatility and Greeks.
24 lines • 768 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.bisection = void 0;
const bisection = (params) => {
const { fn, highStartVolatility, iterations, lowStartVolatility, seekValue, tolerance, } = params;
let _a = lowStartVolatility;
let _b = highStartVolatility;
for (let i = 0; i < iterations; i++) {
const c = (_a + _b) / 2;
const y = fn(c);
const error = Math.abs(y - seekValue);
if (error === 0 || error < tolerance || (_b - _a) / 2 < tolerance) {
return c;
}
if (y > seekValue) {
_b = c;
}
else {
_a = c;
}
}
};
exports.bisection = bisection;
//# sourceMappingURL=bisection.js.map