fixed libs

This commit is contained in:
Bojan Kucera 2025-06-04 22:56:03 -04:00
parent 528be93804
commit 5cd24ade09
6 changed files with 29 additions and 420 deletions

View file

@ -535,43 +535,6 @@ export function parkinsonVolatility(
return Math.sqrt((sum / (ohlcv.length - 1)) * annualizationFactor);
}
/**
* Calculate Implied Volatility using Black-Scholes model (simplified)
*/
export function calculateImpliedVolatility(
optionPrice: number,
spotPrice: number,
strikePrice: number,
timeToExpiry: number,
riskFreeRate: number,
optionType: 'call' | 'put',
maxIterations: number = 100,
tolerance: number = 1e-6
): number {
// Bisection method for implied volatility calculation
let low = 0.01;
let high = 5.0;
let impliedVol = 0.0;
for (let i = 0; i < maxIterations; i++) {
impliedVol = (low + high) / 2;
const modelPrice = blackScholes(spotPrice, strikePrice, timeToExpiry, impliedVol, riskFreeRate, optionType);
const diff = optionPrice - modelPrice;
if (Math.abs(diff) < tolerance) {
return impliedVol;
}
if (diff > 0) {
low = impliedVol;
} else {
high = impliedVol;
}
}
return impliedVol; // Return best estimate if no convergence
}
/**
* Black-Scholes option pricing model
*/