fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Mean-CVaR Optimization

Install and import#

bash
npm install fintech-algorithms
ts
import { meanCvar } from "fintech-algorithms/portfolio-construction/mean-risk-optimization/mean-cvar-optimization";

Signature#

meanCvar(assetIdsInput, returnsInput, probabilitiesInput, betaInput, gammaInput, options)

Optimizes a portfolio against conditional value at risk over a discrete scenario set, including the partial tail mass a discrete distribution creates at the confidence level.

Parameters#

NameTypeNotes
assetIdsInputunique non-empty stringsstable asset order
returnsInputfinite `T×N` numberssimple return, one horizon/base currency
probabilitiesInputfinite length-`T` numbersprobability mass
betaInputfinite numberconfidence
gammaInputfinite numberreturn/CVaR units
options{ maxIterations?: unknown; }optional

Worked example#

executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

Input#

assetIdsInput
["A", "B"]
returnsInput
[
  [0.24, 0.08],
  [0.2, 0.06],
  [0.16, 0.04]
]

Showing 3 of 4 elements.

probabilitiesInput
[0.25, 0.25, 0.25, 0.25]
betaInput
0.75
gammaInput
0.5

Call#

meanCvar(assetIdsInput, returnsInput, probabilitiesInput, betaInput, gammaInput, options)

Returns#

object with 20 fields: status, variant, method, branch, assetIds, weights, expectedReturn, cvar, …

{
  "status": "optimal",
  "variant": "mean-cvar-long-only",
  "method": "lp-vertex-enumeration",
  "branch": "positive_gamma_lp",
  "assetIds": ["A", "B"],
  "weights": [0, 1],
  "expectedReturn": 0.039999999999999994,
  "cvar": 0.019999999999999993,
  "thresholdZ": -0.04,
  "tailSlacks": [0, 0, 0, 0.06],
  "scenarioLosses": [-0.08, -0.06, -0.04, 0.02],
  "objective": 0.03,
  "budgetResidual": 0,
  "lowerBoundResidual": 0
}

Showing 14 of 20 fields.

Other exports#

This module also exports weightedVarCvar. Every module additionally exports run as an alias of its primary function, and a meta object carrying its catalog id, domain, family, shape and article URL.

Diagrams#

Mean-CVaR Optimization — article hero

Calculation flow#

Diagram
flowchart TB
  A["Validate rows and mass"]
  B["Convert return to loss"]
  C["Build threshold LP"]
  D["Inspect weighted tail"]
  E["Audit objective and ties"]
  A --> B --> C --> D --> E

How it works#

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References#

  • Primary and technical sources
  • Google discovery audit
  • Contextual prior method
  • Source roles
  • 2026-09-16

The rest of the Mean-Risk Optimization family#