quantitivecalc
Version:
A TypeScript library providing advanced quantitative finance functions for risk analysis, performance metrics, and technical indicators. (Currently in development)
17 lines • 1.29 kB
TypeScript
/**
* Calculates the moving average (simple or exponential) for a given dataset.
*
* @param data - The input array of objects containing the data to process.
* @param sourceColumn - The key in each object from which to read the numeric value.
* @param resultColumn - The key in each object where the calculated moving average will be stored.
* @param windowSize - The number of periods to use for the moving average calculation. Defaults to 20.
* @param type - The type of moving average to calculate: `'simple'` for Simple Moving Average (SMA), `'exponential'` for Exponential Moving Average (EMA). Defaults to `'simple'`.
* @returns A new array of objects with the moving average values added to each object under `resultColumn`.
*
* @remarks
* - For SMA, the result for the first `windowSize - 1` elements will be `null`.
* - For EMA, the first valid value is used as the initial EMA.
* - Non-numeric or invalid values in `sourceColumn` are skipped for SMA and carry forward the previous EMA for EMA.
*/
export declare function calculateMovingAverage(data: Array<Record<string, unknown>>, sourceColumn: string, resultColumn: string, windowSize?: number, type?: 'simple' | 'exponential'): Array<Record<string, unknown>>;
//# sourceMappingURL=calculateMovingAverage.d.ts.map