black-scholes-model
Version:
Complete plug and play Black-Scholes-Merton model for option pricing with features including implied volatility and Greeks.
35 lines • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.impliedVolatility = void 0;
const optionPrice_1 = require("./optionPrice");
const bisection_1 = require("./utils/bisection");
const impliedVolatility = (params) => {
const { K, S, derivativePrice, rf, t, type, highStartVol, lowStartVol, tolerance, iteration, } = params;
if (!K || !S || !derivativePrice || !rf || !t) {
throw new Error('Required fields were left empty');
}
const fn = (volatility) => {
const optionParams = {
S: S,
K: K,
rf: rf,
sigma: volatility,
t: t,
type: type,
};
const price = (0, optionPrice_1.optionPrice)(optionParams);
return price;
};
const bisectParams = {
seekValue: derivativePrice,
fn: fn,
highStartVolatility: highStartVol || 5,
lowStartVolatility: lowStartVol || 0.01,
iterations: iteration || Math.pow(10, 3),
tolerance: tolerance || Math.pow(10, -5),
};
const y = (0, bisection_1.bisection)(bisectParams);
return y;
};
exports.impliedVolatility = impliedVolatility;
//# sourceMappingURL=impliedVolatility.js.map