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

Long/Short Gross-Net Constraints

Install and import#

bash
npm install fintech-algorithms
ts
import { optimizeGrossNetConstrained } from "fintech-algorithms/portfolio-construction/practical-constraints/long-short-gross-net-constraints";

Signature#

optimizeGrossNetConstrained(mu, covariance, lambdaRisk, netMin, netMax, grossMax, options)

Computes long, short, net, and gross exposure from signed weights, checks a net interval and gross cap, and solves the mean-variance problem under both.

Parameters#

NameTypeNotes
muunknown
covarianceunknown
lambdaRiskunknown
netMinunknown
netMaxunknown
grossMaxunknown
optionsGrossNetOptionsoptional

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.2, 0.04]
covariance
[
  [0.04, 0],
  [0, 0.01]
]
lambdaRisk
1
netMin
1
netMax
1
grossMax
1.6
options
{}

Call#

optimizeGrossNetConstrained(mu, covariance, lambdaRisk, netMin, netMax, grossMax, options)

Returns#

object with 9 fields: status, weights, objective, exposures, constraints, minimalSplit, enumeratedStates, totalStates, …

{
  "status": "optimal",
  "weights": [1.3, -0.30000000000000004],
  "objective": 0.1795,
  "exposures": {
    "long": 1.3,
    "short": 0.30000000000000004,
    "net": 1,
    "gross": 1.6,
    "identityResidual": 0
  },
  "constraints": {
    "exposures": {
      "long": 1.3,
      "short": 0.30000000000000004,
      "net": 1,
      "gross": 1.6,
      "identityResidual": 0
    },
    "netLower": {
      "bound": 1,
      "residual": 0,
      "satisfied": true
    },
    "netUpper": {
      "bound": 1,
      "residual": 0,
      "satisfied": true
    },
    "grossCap": {
      "bound": 1.6,
      "residual": 0,
      "satisfied": true
    },
    "minimumFeasibleGross": 1,
    "boundsCompatible": true,
    "feasible": true
  },
  "minimalSplit": {
    "longPart": [1.3, 0],
    "shortPart": [0, 0.30000000000000004],
    "sum": 1.6
  },
  "enumeratedStates": 54,
  "totalStates": 54,
  "certificate": {
    "kind": "exhaustive-orthant-active-set",
    "complete": true,
    "continuousKkt": true,
    "kktResidual": 1.8070036208091741e-16,
    "grossFromSignedWeights": true,
    "globalOptimality": "every orthant and every active set of its concave subproblem was checked"
  }
}

Other exports#

This module also exports signedExposures, exposureMeasures, portfolioVariance, checkExposureConstraints, minimalSplit, auditAuxiliarySplit, canonicalExample. 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#

Long/Short Gross-Net Constraints — article hero

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#

  • Input data preparation
  • Transaction costs

The rest of the Practical Constraints family#