Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 1x 1x 1x 1x 2x 7x 2x 2x 2x 2x 7x 2x | import { irr } from '../irr'
import { RootFinderOptions } from '../../root-finder'
import { XirrInput } from '../definition'
import { transform } from '../transform'
import { zeros } from '../../utils'
export function xirr(
inputs: XirrInput[],
options: Partial<RootFinderOptions> = {},
): { days: number; rate: number } {
const transformedInputs = transform(inputs)
const days = transformedInputs.map(input => input.day)
const firstDay = Math.min(...days)
const lastDay = Math.max(...days)
const totalDays = lastDay - firstDay + 1
const coefficients: number[] = zeros(totalDays)
transformedInputs.forEach(({ amount, day }) => (coefficients[day] += amount))
return {
days: totalDays,
rate: irr(coefficients, options),
}
}
|