The finance developer workbenchSearch the reference Development · 0.1.4 · unpublished

risk / wire operation

Portfolio optimization

totalfinance.risk.optimize

Solve a portfolio: minVariance, maxSharpe (tangency), meanVariance utility, riskParity (equal risk contribution), hrp (hierarchical risk parity), or kelly. Returns the Computed envelope: value.weights + value.objective, assumptions echo the objective and budget, and diagnostics carry converged/iterations — a non-converged solve adds an optimize.not_converged warning instead of pretending.

Pack / profilesrisk / default, full, portfolio
Default discoveryIncluded
Required capabilitiesNone
Effects / authorizationnone / none
Cost / cancellationsmall / Do not assume inline interruption
Handle-eligible inputsNone
Idempotencynot-applicable
Input schema
{
  "type": "object",
  "properties": {
    "objective": {
      "type": "string",
      "enum": [
        "minVariance",
        "maxSharpe",
        "meanVariance",
        "riskParity",
        "hrp",
        "kelly"
      ],
      "description": "Which portfolio to solve for"
    },
    "covariance": {
      "type": "array",
      "items": {
        "type": "array",
        "items": {
          "type": "number"
        }
      },
      "description": "Asset covariance matrix (per-period, decimal² units), square"
    },
    "mean": {
      "type": "array",
      "items": {
        "type": "number"
      },
      "description": "Per-asset expected returns (decimals) — required for maxSharpe/meanVariance/kelly"
    },
    "riskFreeRatePerPeriod": {
      "type": "number",
      "description": "PER-PERIOD risk-free rate (decimal; maxSharpe only) — the same period as the covariance matrix, NOT annualized. Renamed from `riskFreeRate` because every other risk-free rate in the library is annual, and the two were silently interchangeable here"
    },
    "riskAversion": {
      "type": "number",
      "exclusiveMinimum": 0,
      "description": "λ for meanVariance (default 1)"
    },
    "fraction": {
      "type": "number",
      "exclusiveMinimum": 0,
      "description": "Kelly fraction (default 1 = full Kelly)"
    },
    "longOnly": {
      "type": "boolean",
      "description": "Forbid short positions"
    },
    "budget": {
      "type": "number",
      "description": "Σw target (default 1 = fully invested)"
    }
  },
  "additionalProperties": false,
  "required": [
    "objective",
    "covariance"
  ]
}
Output schema
{
  "type": "object",
  "properties": {
    "value": {
      "description": "The computed result"
    },
    "assumptions": {
      "type": "object",
      "description": "Every applied convention, echoed"
    },
    "diagnostics": {
      "type": "object",
      "description": "Engine/method/warnings (+ convergence where iterative)"
    }
  },
  "required": [
    "value",
    "assumptions",
    "diagnostics"
  ]
}

All operations · Setup, handles, jobs & permissions