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

Almgren-Chriss Optimal Execution

Install and import#

bash
npm install fintech-algorithms
ts
import { almgrenChrissOptimalExecution } from "fintech-algorithms/execution-and-transaction-cost-analysis/cost-risk-optimization/almgren-chriss-optimal-execution";

Signature#

almgrenChrissOptimalExecution(input)

The canonical optimal execution trajectory: trades off market impact against the risk of holding the position longer. Risk aversion is the single parameter that shapes the answer — at zero it degenerates to TWAP.

Parameters#

NameTypeNotes
inputAlmgrenChrissInputTotal quantity, horizon, volatility, temporary and permanent impact coefficients, and the risk-aversion parameter. The impact coefficients are estimates, and the trajectory is only as good as they are.

Returns#

{ trajectory, expected_cost, cost_variance, efficient_frontier_point, … }

The trading trajectory with expected cost **and** its variance — reporting cost alone hides the trade being made.

Errors#

  • When risk aversion is negative, or an impact coefficient is not positive — throws

Complexity: time O(steps), space O(steps).

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#

input
{
  "total_quantity": 12000,
  "interval_count": 12,
  "lot_size": 100,
  "temporary_impact_weight": 100,
  "inventory_risk_weight": 1
}

Call#

almgrenChrissOptimalExecution(input)

Returns#

object with 13 fields: total_quantity, interval_count, lot_size, temporary_impact_weight, inventory_risk_weight, kappa, scheduled_quantity, remaining_quantity, …

{
  "total_quantity": 12000,
  "interval_count": 12,
  "lot_size": 100,
  "temporary_impact_weight": 100,
  "inventory_risk_weight": 1,
  "kappa": 0.099958380139,
  "scheduled_quantity": 12000,
  "remaining_quantity": 0,
  "temporary_impact_score": 1248000000,
  "inventory_risk_score": 410470000,
  "objective_score": 1658470000,
  "schedule": [
    {
      "interval": 1,
      "target_quantity": 1400,
      "target_remaining_quantity": 10600,
      "temporary_impact_score": 196000000,
      "inventory_risk_score": 112360000
    },
    {
      "interval": 2,
      "target_quantity": 1300,
      "target_remaining_quantity": 9300,
      "temporary_impact_score": 169000000,
      "inventory_risk_score": 86490000
    },
    {
      "interval": 3,
      "target_quantity": 1200,
      "target_remaining_quantity": 8100,
      "temporary_impact_score": 144000000,
      "inventory_risk_score": 65610000
    }
  ],
  "state": "risk-adjusted"
}

Other exports#

This module also exports implementationShortfallExecution, arrivalPriceExecution, liquiditySeekingExecution, opportunisticDarkPoolExecution, calculate. 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#

Almgren-Chriss Optimal Execution — system map

Calculation flow#

Almgren-Chriss Optimal Execution calculation flow
flowchart LR
    S1["Validate parent intervals lot and nonnegative weights"]
    S2["Compute kappa and continuous trade weights or equal we"]
    S3["Allocate every parent lot by largest remainder"]
    S4["Accumulate temporaryimpact and inventoryrisk score com"]
    S1 --> S2
    S2 --> S3
    S3 --> S4
    S4 --> D{"inventory risk exactly zero"}
    D --> O["schedule + diagnostics"]
    O --> A["Audit: Scheduled quantity equals the parent"]

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#

The rest of the Cost/Risk Optimization family#