# Long/Short Gross-Net Constraints

`D14-F04-A04` · Portfolio Construction → Practical Constraints · archetype `record-transform` · difficulty 4/5 · verification **contract**

Full page: https://docs.thefintechbuilder.com/portfolio-construction/practical-constraints/long-short-gross-net-constraints/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

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

## Signature

```ts
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

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `mu` | `unknown` | yes |  |
| `covariance` | `unknown` | yes |  |
| `lambdaRisk` | `unknown` | yes |  |
| `netMin` | `unknown` | yes |  |
| `netMax` | `unknown` | yes |  |
| `grossMax` | `unknown` | yes |  |
| `options` | `GrossNetOptions` | no | default: "{}" |

## Worked example

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`:

```json
[0.2, 0.04]
```

`covariance`:

```json
[
  [0.04, 0],
  [0, 0.01]
]
```

`lambdaRisk`:

```json
1
```

`netMin`:

```json
1
```

`netMax`:

```json
1
```

`grossMax`:

```json
1.6
```

`options`:

```json
{}
```

### Call

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

### Returns

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

```json
{
  "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

`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.

## Verification and provenance

Tier: **contract**.

The module loads, the entry point is callable and its declared signature matches the compiled code. The example below is real captured output, but no independently published figure asserts the numbers.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.2.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/portfolio-construction/practical-constraints/long-short-gross-net-constraints/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/portfolio-construction/practical-constraints/long-short-gross-net-constraints/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/portfolio-construction/llms.txt
