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

Cardinality-Constrained Portfolio

Install and import#

bash
npm install fintech-algorithms
ts
import { optimizeCardinalityConstrained } from "fintech-algorithms/portfolio-construction/practical-constraints/cardinality-constrained-portfolio";

Signature#

optimizeCardinalityConstrained(mu, covariance, lambdaRisk, current, K, options)

Parameters#

NameTypeNotes
muunknown
covarianceunknown
lambdaRiskunknown
currentunknown
Kunknown
options{ lower?: unknown; upper?: unknown; maxSupports?: 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#

mu
[0.12, 0.1, 0.09, 0.08]
covariance
[
  [0.3, 0, 0, 0],
  [0, 0.02, 0, 0],
  [0, 0, 0.01, 0]
]

Showing 3 of 4 elements.

lambdaRisk
1
current
[0.25, 0.25, 0.25, 0.25]
K
2
options
{
  "lower": [0, 0, 0, 0],
  "upper": [1, 1, 1, 1]
}

Call#

optimizeCardinalityConstrained(mu, covariance, lambdaRisk, current, K, options)

Returns#

object with 12 fields: status, weights, selected, trade, objective, bestBound, relativeGap, enumeratedSupports, …

{
  "status": "optimal",
  "weights": [0, 0.5000000000000003, 0.49999999999999967, 0],
  "selected": [0, 1, 1, 0],
  "trade": [-0.25, 0.25000000000000033, 0.24999999999999967, -0.25],
  "objective": 0.0875,
  "bestBound": 0.0875,
  "relativeGap": 0,
  "enumeratedSupports": 10,
  "totalSupports": 10,
  "realizedSupport": 2,
  "tradeSupport": 4,
  "certificate": {
    "kind": "exhaustive-support-enumeration",
    "complete": true,
    "continuousKkt": true,
    "globalOptimality": "all supports and continuous KKT active sets were checked"
  }
}

Diagrams#

Cardinality-Constrained Portfolio — final vs trade support
Cardinality-Constrained Portfolio — support enumeration

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#

  • MOSEK Portfolio Optimization Cookbook, §6.4 and §6.5 — MOSEK ApS.
  • Moehle, Kochenderfer, Boyd, and Ang, “Tax-aware portfolio optimization” — Nicholas Moehle, Mykel J. Kochenderfer, Stephen Boyd, and Andrew Ang.
  • Google discovery status

The rest of the Practical Constraints family#