fixed libs
This commit is contained in:
parent
528be93804
commit
5cd24ade09
6 changed files with 29 additions and 420 deletions
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue