This commit is contained in:
Boki 2025-06-11 10:38:05 -04:00
parent 9d38f9a7b6
commit eeae192872
26 changed files with 532 additions and 186 deletions

View file

@ -242,7 +242,9 @@ export function identifyVolatilityRegimes(
// Classify returns into regimes
const regimeSequence = absReturns.map(absRet => {
for (let i = 0; i < thresholds.length; i++) {
if (absRet <= thresholds[i]) {return i;}
if (absRet <= thresholds[i]) {
return i;
}
}
return numRegimes - 1;
});
@ -537,7 +539,9 @@ export function calculateYangZhangVolatility(
* Parkinson volatility estimator
*/
export function parkinsonVolatility(ohlcv: OHLCVData[], annualizationFactor: number = 252): number {
if (ohlcv.length < 2) {return 0;}
if (ohlcv.length < 2) {
return 0;
}
const sum = ohlcv.slice(1).reduce((acc, curr) => {
const range = Math.log(curr.high / curr.low);
return acc + range * range;