function ret2tick
ret2tick(
x: array,
mode?: string,
sval?: number,
dim?: 0 | 1,
): array

Convert a return series to a value series with a start value.

Converts a return series to a value series (prices) given a starting value. Can handle both simple and continuous (log) returns.

Examples

Converting returns to prices with a custom start value

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

assertEquals(ret2tick([0.5, -0.5, 1.0], 'simple', 100), [100, 150, 75, 150]);

Converting returns to prices with continuous method

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

assertEquals(ret2tick([0.1, -0.05, 0.2], 'continuous', 100), [100, 110.51709180756477, 105.12710963760242, 128.40254166877418]);

Converting matrix of returns to prices

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

assertEquals(ret2tick([[0.1, 0.2], [0.05, -0.1]], 'simple', 100), [[100, 110.00000000000001, 132], [100, 105, 94.5]]);

Parameters

Array of returns

optional
mode: string

Method to compute values: 'simple' or 'continuous' (defaults to 'simple')

optional
sval: number

Starting value (defaults to 1)

optional
dim: 0 | 1

Dimension to operate on (0: row-wise, 1: column-wise) (defaults to 0)

Return Type

Value series (prices)

Throws

If unknown return method specified

ret2tick(
x: matrix,
mode?: string,
sval?: number,
dim?: 0 | 1,
): matrix

Convert a return series to a value series with a start value.

Converts a return series to a value series (prices) given a starting value. Can handle both simple and continuous (log) returns.

Examples

Converting returns to prices with a custom start value

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

assertEquals(ret2tick([0.5, -0.5, 1.0], 'simple', 100), [100, 150, 75, 150]);

Converting returns to prices with continuous method

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

assertEquals(ret2tick([0.1, -0.05, 0.2], 'continuous', 100), [100, 110.51709180756477, 105.12710963760242, 128.40254166877418]);

Converting matrix of returns to prices

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

assertEquals(ret2tick([[0.1, 0.2], [0.05, -0.1]], 'simple', 100), [[100, 110.00000000000001, 132], [100, 105, 94.5]]);

Parameters

Array of returns

optional
mode: string

Method to compute values: 'simple' or 'continuous' (defaults to 'simple')

optional
sval: number

Starting value (defaults to 1)

optional
dim: 0 | 1

Dimension to operate on (0: row-wise, 1: column-wise) (defaults to 0)

Return Type

Value series (prices)

Throws

If unknown return method specified