Return to Home
Quantitative Research Series

Integer Optimization
in Finance

From continuous theory to discrete execution. How Mixed-Integer Programming (MIP) solves the NP-Hard problems of real-world trading.

Portfolio Construction
Tax Management
Arbitrage
Integer Optimization in Finance Infographic
Click to view full screen
Integer Optimization in Finance Infographic
Click to view full screen

The "Dust" Problem

Traditional Mean-Variance Optimization assumes assets are infinitely divisible. This creates "dust"—negligible positions (e.g., 0.0001%) that are:

  • Costly to trade (fixed fees)
  • Operational nightmares
  • Impossible to hedge
  • Illiquid odd-lots

The MIP Solution

We introduce a binary vector z where z_i \in \{0, 1\}.

// If z[i] is 0, weight w[i] MUST be 0

l_i z_i \leq w_i \leq u_i z_i

Mathematical Architectures

Defining the feasible region is an art form. We move beyond simple linear bounds to capture the discrete nature of trading mechanics and solver performance.

Structural Constraints

Logical Constraints

Encodes "If-Then" rules. Example: "If we hold Shell, we must not hold BP."
z_{shell} + z_{bp} \leq 1

Cardinality (K)

Limits the total number of assets in the portfolio to exactly K.
\sum_{i=1}^N z_i = K

Minimum Buy-In

Disallows small trades. Position must be 0 or > $100k.
w_i = 0 \lor w_i \geq 0.05

Round Lots

Forces trades to be multiples of a lot size (e.g., 100 shares).
x_i = L \cdot n_i, n_i \in \mathbb{Z}

Advanced Techniques

Perspective Cut

Advanced conic reformulation. Replaces quadratic terms to tighten the "relaxation gap."
w_i^2 \rightarrow w_i^2 / z_i

Indicator Constraints

Modern solver feature. Avoids "Big-M" numerical issues by handling logic natively.
z=1 \implies \sum w_i \le \alpha

SOS Type 2

Special Ordered Sets. Essential for modeling piecewise linear costs (e.g., tiered commissions).
\lambda_i, \lambda_{i+1} \neq 0

Turnover Control

Linearizing absolute value differences for rebalancing limits.
|w_{new} - w_{old}| \leq T

Research Note: The "Big-M" Pitfall

When linking binary (z) and continuous (w) variables via w \le M \cdot z, choosing a generic "large M" (e.g., 10,000) causes numerical instability in solvers. A "Tight M" (equal to the asset's upper bound) is critical for convergence.

The Quant Workflow

1. Data Ingestion & Signal Generation

Constructing the inputs for the optimizer.

Python / Pandas
Expected Returns (\mu)
Alpha model output. Vector of size N.
Covariance Matrix (\Sigma)
Risk model (e.g., Barra). Matrix of size N \times N.

2. Problem Formulation (CVXPY)

Translating business logic into standard form.

MIP Modeling
import cvxpy as cp
# Define Variables
w = cp.Variable(n) # Weights
z = cp.Variable(n, boolean=True) # Selection
# Objective: Max Return - Risk penalty
objective = cp.Maximize(mu @ w - gamma * cp.quad_form(w, Sigma))
# Constraints
constraints = [
cp.sum(w) == 1, # Fully invested
cp.sum(z) <= 50, # Cardinality limit
w <= z # Big-M linking
]

3. The Solver Engine

Branch-and-Bound search space exploration.

GurobiMosek
Root Node
Relaxed LP
Branching
Split z_i \in \{0, 1\}
Pruning
Bounds Check

4. Order Slicing & Execution

Transforming optimal weights into market orders.

FIX Protocol
  • Round to nearest Lot (100)
  • Split large parents (VWAP)
  • Route to Dark Pools
  • TCA Analysis

Sparse Index Tracking

The L_0 Norm Challenge

The goal is to replicate a benchmark (e.g., S&P 500) using only a subset of assets (e.g., K=50). This minimizes transaction costs and simplifies management.

MIP vs. Lasso (Regularization)

  • Lasso (L_1): Shrinks weights towards zero. Bias creates systematic underperformance.
  • MIP (L_0): Selects the best subset without shrinking weights. Provides an unbiased estimator.
Optimization Model
Objective
Minimize Tracking Error Squared
\min \sum (R_{port} - R_{bench})^2
Cardinality Constraint
Strict limit on number of assets
\sum_{i=1}^N z_i \leq K

Tax-Loss Harvesting

Maximizing After-Tax Alpha

Systematically realizing losses to offset capital gains, while maintaining risk exposure. The complexity lies in the Wash Sale Rule: you cannot buy a "substantially identical" security 30 days before or after a sale.

1
Scan Inventory: Identify lots with P_{current} < P_{cost}.
2
Substitute: Map Loser (e.g., Coke) to Substitute (e.g., Pepsi).
3
Optimize: Solve for max realized loss s.t. tracking error limits.

The Logic Gate (MIP Formulation)

Wash Sale Constraint
# Cannot Buy if Sold recently
x_{buy, i} \leq M \cdot (1 - y_{wash, i})
# Mutually Exclusive Actions
z_{sell, i} + z_{buy, i} \leq 1
Inventory Management

Tracks specific tax lots (date, price) rather than average cost.

FIFOLIFOHIFO

Pairs Trading & Cointegration

Graph Theory Formulation

We treat the market as a graph G=(V,E) where vertices are stocks and edges represent cointegration strength. The goal is to find a matching that maximizes total strength while ensuring diversification.

Nodes (V)
Universe of liquid stocks (e.g., Russell 3000).
Edges (E)
Engle-Granger cointegration p-values.

The Clique Partitioning Problem

Partitioning the universe into disjoint clusters of cointegrated assets. An NP-Hard problem solvable via MIP.

Constraint Model
\text{Maximize } \sum_{(i,j) \in E} w_{ij} x_{ij}
Maximize sum of edge weights (cointegration scores)
\sum_{j} x_{ij} \leq 1 \quad \forall i \in V
Degree Constraint: Each stock is in at most 1 pair
\beta_{port} = \sum (w_i \beta_i) \approx 0
Market Neutrality Constraint

The Modern Quant Stack

Modeling
CVXPY
Python DSL for convex optimization. The industry standard.
JuMP
Julia-based modeling. Extremely fast for large-scale problems.
Engines
Gurobi
Pro
Best-in-class performance for MIPs. Expensive licensing.
HiGHS
OSS
High-performance open-source linear solver (C++).
Data
kdb+ / q
Time-series database for high-frequency tick data.
Snowflake
Cloud data warehouse for factor data and reference data.
Infra
Kubernetes
Orchestrating distributed solver jobs across a cluster.
Airflow
Workflow management for daily rebalancing DAGs.

Future Frontiers

Next-generation computing paradigms for combinatorial finance.

Post-SiliconAdiabatic

Quantum Annealing

Classical solvers struggle with non-convex landscapes, often getting stuck in local minima. Quantum Annealers exploit quantum tunneling to traverse energy barriers, finding global optima for combinatorial problems.

The Mapping: QUBO

Financial MIPs must be reformulated into Quadratic Unconstrained Binary Optimization problems.

E(\mathbf{z}) = \mathbf{z}^T Q \mathbf{z} + \mathbf{c}^T \mathbf{z}
D-Wave Advantage
Fujitsu Digital Annealer

Portfolio Embedding

1. Logical VariablesQubits
2. CorrelationsCouplers (J)
3. Returns/RiskBias (h)
4. ConstraintsPenalty Terms
Input:Bipartite Graph (Vars ↔ Cons)
Model:Graph Convolutional Net (GCN)
Output:Branching Score (Probability)
Machine LearningGNN

Neural Branching

The bottleneck of any MIP solver is the Branch-and-Bound tree. Choosing which variable to branch on determines if the solver finishes in seconds or centuries.

We train Graph Neural Networks (GNNs) via Imitation Learning to mimic expert (but slow) branching rules like Strong Branching, but execute them in milliseconds on a GPU.

100x
Inference Speedup
30%
Tree Size Reduction

Continue Learning