function twr
twr(
mv: array,
cf?: array | number,
): number

True Time-weighted return.

True Time-weighted return measures the returns of the assets irrespective of the amount invested. It eliminates the impact of cash flows, focusing solely on the performance of the investments themselves.

Examples

Calculate true time-weighted return with market values and cash flows

import { assertEquals } from "jsr:@std/assert";

const mv = [250000, 255000, 257000, 288000, 293000, 285000];
const cf = [0, 0, 25000, 0, -10000, 0];
assertEquals(twr(mv, cf), 0.07564769566198049);

TWR with no cash flows (default behavior)

import { assertEquals } from "jsr:@std/assert";

assertEquals(twr([100, 110, 120]), 0.19999999999999996);

TWR with uniform cash flow

import { assertEquals } from "jsr:@std/assert";

assertEquals(twr([100, 110, 120], 5), 0.0931677018633541);

Parameters

Array of market values at each time period

optional
cf: array | number = 0

Array of external cash flows (inflows/outflows) or a single number applied to all periods (defaults to 0)

Return Type

number

Time-weighted return

Throws

If market values and cash flows arrays have different lengths