# Markowitz Mean-Variance

`D14-F01-A01` · Portfolio Construction → Mean-Risk Optimization · archetype `record-transform` · difficulty 4/5 · verification **contract**

Full page: https://docs.thefintechbuilder.com/portfolio-construction/mean-risk-optimization/markowitz-mean-variance/
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 { markowitzMeanVariance } from "fintech-algorithms/portfolio-construction/mean-risk-optimization/markowitz-mean-variance";
```

## Signature

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

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `assetIdsInput` | `ordered string array` | yes | One stable identifier per column/row |
| `muInput` | `finite number array` | yes | Expected return for one declared horizon |
| `covarianceInput` | `finite number matrix` | yes | Variance/covariance for that same horizon and return unit |
| `targetReturnInput` | `finite number` | yes | Same expected-return unit/horizon as `mu` |
| `options` | `MarkowitzOptions` | 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

`assetIdsInput`:

```json
["A", "B"]
```

`muInput`:

```json
[0.06, 0.14]
```

`covarianceInput`:

```json
[
  [0.04, 0.01],
  [0.01, 0.09]
]
```

`targetReturnInput`:

```json
0.1
```

`options`:

```json
{
  "maxIterations": 10000
}
```

### Call

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

### Returns

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

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

## 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/mean-risk-optimization/markowitz-mean-variance/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/portfolio-construction/mean-risk-optimization/markowitz-mean-variance/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/portfolio-construction/llms.txt
