Trading Dev AcademyFree quant education

Free lesson · Optimization

Numerical residuals and independent solution checks

Open interactive lessonPractice calculationsExplore labs

Start with the idea

A solver’s success message is weaker evidence than checking the defining equations yourself.

Symbols, units & horizon
  • μ: expected holding-period return vector
  • A: positive-definite penalty matrix in the objective μᵀw−wᵀAw/2
  • w: candidate dimensionless weights
  • e: largest absolute component of first-order residual, in return-objective units per weight
  • infinity norm: maximum absolute entry

When and why to use this

Add stationarity and feasibility checks to research notebooks before interpreting an allocation.

A solver’s success message is weaker evidence than checking the defining equations yourself.

For an unconstrained positive-definite quadratic, the first-order residual measures how far the returned weights are from satisfying stationarity. For constrained problems, also inspect primal feasibility, dual signs and complementarity. A small objective difference alone may conceal an unacceptable constraint breach.

Repeat the example using a closed form or a dense one-dimensional grid, and perturb inputs. Separate numerical conditioning from statistical uncertainty: a perfectly solved wrong covariance matrix remains a wrong risk model.

e=‖μ−Aw‖∞
Numerical optimality diagnostic for the specified unconstrained model

Numerical residuals and independent solution checks

  1. Differentiate the unconstrained objective to obtain μ−Aw.
  2. Evaluate the vector at the returned candidate.
  3. Take the largest absolute entry; compare to a declared tolerance and separately inspect model assumptions.
Work it by hand

μ=[.02,.03], A=diag(.1,.2), w=[.2,.15] gives zero residual. If the second weight is .14, its residual is .002.

Apply it in a strategy

  • Freeze inputs at the stated decision time and record their units.
  • Add stationarity and feasibility checks to research notebooks before interpreting an allocation.
  • Recompute the example, then change the material assumption and explain the difference.

Research deliverable

Numerical residuals and independent solution checks: produce the worked calculation, a timestamped input record and a written decision addressing this limitation: Zero residual establishes a mathematical condition for the specified problem, not forecast validity or net profitability.

These are synthetic mechanics examples, not historical performance or paper replications. Module evidence and research boundaries record the 12 September 2026 review.

Evidence and boundaries · reviewed 12 September 2026

The records below distinguish research status, access depth and data dates. Abstract-only review identifies research questions; it does not establish a replicated empirical claim.

Further reading: Bongiorno, Manolakis & Mantegna: End-to-End Large Portfolio Optimization for Variance Minimization with Neural Networks through Covariance Cleaning ↗

Journal of Finance and Data Science 12 (2026), 100179; journal reference verified on author manuscript record. Version: v3, 21 April 2026. Review: 2026-09-12; Abstract and version/publication metadata only. Markets: US equities. Data dates: Abstract reports out-of-sample January 2000–December 2024; training and point-in-time data details not inspected. Limitation: Motivates comparing covariance estimators under common constraints. Architecture, execution assumptions and claimed rankings were not reproduced; this module teaches transparent baseline calculations.

Further reading: Boyd & Vandenberghe: Convex Optimization ↗

Foundational textbook, Cambridge University Press 2004. Version: Author-hosted book landing page. Review: 2026-09-12; Book description and educational resource links. Markets: General mathematical optimization. Data dates: No financial observation sample. Limitation: Foundational exposition, not recent investment evidence; the examples below have independently stated domains and constraints.

Research sources, review dates and limitations

Connect the ideas: Constraints and survival

Retrieve: A desired position must fit available capital and explicit limits.

Check the change: Portfolio weights, venue collateral, working orders and redemption obligations impose different constraints.

Risk → Portfolio construction → Arbitrage → Crypto derivatives → Execution & microstructure → Fund operations & capstone

Explain it yourself: Can an offsetting terminal payoff remove a margin problem today?

Self-assessed. Write your explanation before opening this comparison.

No. Cash may be required before the hedge pays, or in another account. Check the path, collateral location and feasible transfer times.

Python implementation

Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.

# Python 3.10+; standard library and NumPy only.
# Synthetic teaching inputs; conventions and units are defined in the notation above.
import numpy as np

def stationarity_error(mean,penalty,weights):
    mu=np.asarray(mean,float); a=np.asarray(penalty,float); w=np.asarray(weights,float)
    if a.shape!=(len(mu),len(mu)) or w.shape!=mu.shape: raise ValueError('Incompatible shapes')
    return float(np.max(np.abs(mu-a@w)))

assert abs(stationarity_error([.02,.03],[[.1,0],[0,.2]],[.2,.14])-.002)<1e-12
print(stationarity_error([.02,.03],[[.1,0],[0,.2]],[.2,.14]))

Continue learning

Optimization: Feasibility, Costs & Robust Decisions — all lessons
  1. Exposure constraints before optimization
  2. Curvature and a bounded quadratic decision
  3. Derive the fully invested minimum-variance portfolio
  4. Project a desired allocation onto the long-only simplex
  5. Trading costs and a no-trade decision
  6. An uncertainty bound becomes a position penalty
  7. Read a binding constraint through its shadow price
  8. Numerical residuals and independent solution checks

Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations