quantitivecalc
Version:
A TypeScript library providing advanced quantitative finance functions for risk analysis, performance metrics, and technical indicators. (Currently in development)
17 lines • 1.28 kB
TypeScript
/**
* Calculates the daily returns for a given array of data objects.
*
* The function computes the daily return for each row based on the specified `sourceColumn`.
* The daily return is calculated as `(current - previous) / previous` for each consecutive row.
* The result is stored in a new column specified by `resultColumn` (default: `'dailyReturn'`).
* The first row's daily return is set to `initialValue` (default: `0`).
* If the required values are not valid numbers or the previous value is zero, the daily return is set to `null`.
*
* @param data - Array of data objects containing the source values.
* @param sourceColumn - The key in each object from which to read the value for return calculation.
* @param resultColumn - The key under which to store the calculated daily return (default: `'dailyReturn'`).
* @param initialValue - The value to assign as the daily return for the first row (default: `0`).
* @returns A new array of data objects with the daily returns added in the specified result column.
*/
export declare function calculateDailyReturns(data: Array<Record<string, unknown>>, sourceColumn: string, resultColumn?: string, initialValue?: number | null): Array<Record<string, unknown>>;
//# sourceMappingURL=calculateDailyReturns.d.ts.map