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

Mean-Absolute-Deviation Optimization

Install and import#

bash
npm install fintech-algorithms
ts
import { meanMad } from "fintech-algorithms/portfolio-construction/mean-risk-optimization/mean-absolute-deviation-optimization";

Signature#

meanMad(assetIdsInput, returnsInput, probabilitiesInput, targetReturnInput, options)

Minimizes mean absolute deviation subject to a return target by solving the linear program the absolute value reduces to, over a discrete scenario set.

Parameters#

NameTypeNotes
assetIdsInputunique string arraystable input order
returnsInputfinite `T×N` matrixsimple returns, one horizon and base currency
probabilitiesInputfinite length-`T` arrayscenario mass
targetReturnInputfinite numbersame horizon/unit as returns
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
["DISPERSED", "STABLE"]
returnsInput
[
  [0.2, 0.03],
  [0.1, 0.03],
  [0.05, 0.03]
]

Showing 3 of 4 elements.

probabilitiesInput
[0.25, 0.25, 0.25, 0.25]
targetReturnInput
0.055

Call#

meanMad(assetIdsInput, returnsInput, probabilitiesInput, targetReturnInput, options)

Returns#

object with 17 fields: status, variant, method, assetIds, weights, meanReturns, expectedReturn, mad, …

{
  "status": "optimal",
  "variant": "mean-mad-return-floor-long-only",
  "method": "lp-vertex-enumeration",
  "assetIds": ["DISPERSED", "STABLE"],
  "weights": [0.49999999999999983, 0.5000000000000002],
  "meanReturns": [0.08000000000000002, 0.03],
  "expectedReturn": 0.05499999999999999,
  "mad": 0.03499999999999999,
  "targetReturn": 0.05499999999999999,
  "budgetResidual": 0,
  "lowerBoundResidual": 0,
  "targetResidual": 0,
  "probabilityResidual": 0,
  "iterations": 3003
}

Showing 14 of 17 fields.

Diagrams#

Mean-Absolute-Deviation Optimization — article hero

Calculation flow#

Diagram
flowchart TB
  A["Validate rows and mass"]
  B["Center around the mean"]
  C["Build deviation LP"]
  D["Impose return floor"]
  E["Audit MAD and feasibility"]
  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 source
  • Implementation corroboration
  • Evidence classification
  • Source roles
  • 2026-09-16

The rest of the Mean-Risk Optimization family#