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

Transaction-Cost-Aware Optimization

Install and import#

bash
npm install fintech-algorithms
ts
import { optimizeTransactionCostAware } from "fintech-algorithms/portfolio-construction/practical-constraints/transaction-cost-aware-optimization";

Signature#

optimizeTransactionCostAware(mu, covariance, lambdaRisk, x0, buyCost, sellCost, options)

Parameters#

NameTypeNotes
muunknown
covarianceunknown
lambdaRiskunknown
x0unknown
buyCostunknown
sellCostunknown
options{ cashIndex?: number; costHorizon?: string; maxIterations?: number }optional

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.08, 0.04, 0]
covariance
[
  [0.04, 0, 0],
  [0, 0.01, 0],
  [0, 0, 0]
]
lambdaRisk
0.0005
x0
[600, 400, 100]
buyCost
[0.001, 0.002, 0]
sellCost
[0.001, 0.002, 0]
options
{
  "cashIndex": 2
}

Call#

optimizeTransactionCostAware(mu, covariance, lambdaRisk, x0, buyCost, sellCost, options)

Returns#

object with 15 fields: status, weights, trade, buy, sell, directCost, auxiliaryCost, budgetResidual, …

{
  "status": "optimal",
  "weights": [957.3853839647959, 141.74071207539012, 0],
  "trade": [357.3853839647959, -258.2592879246099, -100],
  "buy": [357.3853839647959, 0, 0],
  "sell": [0, 258.2592879246099, 100],
  "directCost": 0.8739039598140157,
  "auxiliaryCost": 0.8739039598140157,
  "budgetResidual": 0,
  "objective": 62.95436762449867,
  "iterations": 523,
  "cashIndex": 2,
  "costHorizon": "per-rebalance",
  "currentWealth": 1100,
  "cashBalance": 0
}

Showing 14 of 15 fields.

Other exports#

This module also exports auditTradeParts. 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#

Transaction-Cost-Aware Optimization — cost comparison
Transaction-Cost-Aware Optimization — epigraph audit
Transaction-Cost-Aware Optimization — transaction ledger

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#

  • MOSEK Portfolio Optimization Cookbook, Chapter 6 — MOSEK ApS.
  • Boyd et al., Multi-Period Trading via Convex Optimization — Stephen Boyd and collaborators.
  • Google discovery status

The rest of the Practical Constraints family#