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

Markowitz Mean-Variance

Install and import#

bash
npm install fintech-algorithms
ts
import { markowitzMeanVariance } from "fintech-algorithms/portfolio-construction/mean-risk-optimization/markowitz-mean-variance";

Signature#

markowitzMeanVariance(assetIdsInput, muInput, covarianceInput, targetReturnInput, options)

Solves for the lowest-variance asset weights that still meet a declared return target, from expected returns and a covariance matrix.

Parameters#

NameTypeNotes
assetIdsInputordered string arrayOne stable identifier per column/row
muInputfinite number arrayExpected return for one declared horizon
covarianceInputfinite number matrixVariance/covariance for that same horizon and return unit
targetReturnInputfinite numberSame expected-return unit/horizon as mu
optionsMarkowitzOptionsoptional

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"]
muInput
[0.06, 0.14]
covarianceInput
[
  [0.04, 0.01],
  [0.01, 0.09]
]
targetReturnInput
0.1
options
{
  "maxIterations": 10000
}

Call#

markowitzMeanVariance(assetIdsInput, muInput, covarianceInput, targetReturnInput, options)

Returns#

object with 21 fields: assetIds, mu, targetReturn, weights, expectedReturn, variance, volatility, budgetResidual, …

{
  "assetIds": ["A", "B"],
  "mu": [0.06, 0.14],
  "targetReturn": 0.1,
  "weights": [0.4999999999999999, 0.5000000000000001],
  "expectedReturn": 0.1,
  "variance": 0.037500000000000006,
  "volatility": 0.19364916731037085,
  "budgetResidual": 0,
  "targetResidual": 0,
  "lowerBoundResidual": 0,
  "fwGapS": 0,
  "fwGap": 0,
  "matrixScale": 0.09,
  "status": "optimal"
}

Showing 14 of 21 fields.

Diagrams#

Markowitz Mean-Variance — article hero
Markowitz Mean-Variance — markowitz frontier

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 technical sources
  • Input-lineage sources
  • Contextual Google destinations inspected
  • Citation boundaries
  • 2026-09-16

The rest of the Mean-Risk Optimization family#