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

Percentage of positive values in array or matrix.

Calculates the percentage of positive (non-negative) values in an array or matrix. This is a common metric to assess the consistency of returns.

Examples

Percentage of positive values in a single array

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(percpos(x), 0.8);

Percentage of positive values in different array

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

const y = [-0.005, 0.081, 0.04, -0.037, -0.061, 0.058, -0.049, -0.021, 0.062, 0.058];
assertEquals(percpos(y), 0.5);

Percentage of positive values with threshold

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

assertEquals(percpos([0.05, 0.03, -0.02, 0.08]), 0.75);

Parameters

array of elements

optional
dim: 0 | 1

dimension 0: row, 1: column (def: 0)

Return Type

number

Percentage of positive values

percpos(
x: matrix,
dim?: 0 | 1,
): array | matrix

Percentage of positive values in array or matrix.

Calculates the percentage of positive (non-negative) values in an array or matrix. This is a common metric to assess the consistency of returns.

Examples

Percentage of positive values in a single array

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(percpos(x), 0.8);

Percentage of positive values in different array

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

const y = [-0.005, 0.081, 0.04, -0.037, -0.061, 0.058, -0.049, -0.021, 0.062, 0.058];
assertEquals(percpos(y), 0.5);

Percentage of positive values with threshold

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

assertEquals(percpos([0.05, 0.03, -0.02, 0.08]), 0.75);

Parameters

array of elements

optional
dim: 0 | 1

dimension 0: row, 1: column (def: 0)

Return Type

Percentage of positive values