function annrisk
annrisk(
x: array,
t?: number,
dim?: 0 | 1,
): number

Computes the Annualized Risk (Standard Deviation).

Computes the annualized standard deviation of asset or portfolio returns. Standard deviation is scaled based on the frequency of the data.

Formula: Annualized Risk = √t × Standard Deviation (σ)

Examples

Annualized risk for a single asset (monthly data)

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

const x = [0.003, 0.026, 0.015, -0.009, 0.014, 0.024, 0.015, 0.066, -0.014, 0.039];
assertEquals(annrisk(x, 12), 0.08047276972160623);

Annualized risk with daily frequency

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

const x = [0.003, 0.026, 0.015, -0.009, 0.014, 0.024, 0.015, 0.066, -0.014, 0.039];

assertEquals(annrisk(x, 252), 0.368772558632011);

Annualized risk for multiple assets (matrix)

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

const x1 = [0.003, 0.026, 0.015, -0.009, 0.014];
const x2 = [0.024, 0.015, 0.066, -0.014, 0.039];
assertEquals(annrisk([x1, x2], 12), [0.046047801250439745, 0.10238163897887159]);

Parameters

Asset/portfolio returns

optional
t: number

Frequency of data points in a year: 1: yearly, 4: quarterly, 12: monthly, 52: weekly, 252: daily (default)

optional
dim: 0 | 1

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

Return Type

number

The computed annualized risk (standard deviation)

Throws

If the input is invalid

annrisk(
x: matrix,
t?: number,
dim?: 0 | 1,
): array | matrix

Computes the Annualized Risk (Standard Deviation).

Computes the annualized standard deviation of asset or portfolio returns. Standard deviation is scaled based on the frequency of the data.

Formula: Annualized Risk = √t × Standard Deviation (σ)

Examples

Annualized risk for a single asset (monthly data)

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

const x = [0.003, 0.026, 0.015, -0.009, 0.014, 0.024, 0.015, 0.066, -0.014, 0.039];
assertEquals(annrisk(x, 12), 0.08047276972160623);

Annualized risk with daily frequency

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

const x = [0.003, 0.026, 0.015, -0.009, 0.014, 0.024, 0.015, 0.066, -0.014, 0.039];

assertEquals(annrisk(x, 252), 0.368772558632011);

Annualized risk for multiple assets (matrix)

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

const x1 = [0.003, 0.026, 0.015, -0.009, 0.014];
const x2 = [0.024, 0.015, 0.066, -0.014, 0.039];
assertEquals(annrisk([x1, x2], 12), [0.046047801250439745, 0.10238163897887159]);

Parameters

Asset/portfolio returns

optional
t: number

Frequency of data points in a year: 1: yearly, 4: quarterly, 12: monthly, 52: weekly, 252: daily (default)

optional
dim: 0 | 1

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

Return Type

The computed annualized risk (standard deviation)

Throws

If the input is invalid