Differential Calculus and Optimization Basics › Convexity

Michael BrenndoerferOctober 24, 202510 min read
Quantitative FinanceAll chapters
Part 1 of 15Mathematical Foundations
Chapter 6Differential Calculus and Optimization Basics › Convexity
Reading section 6 of 11 · Convexity · 10 minSection 6 of 11 · 10 min

Book contents

Section 6 of 11 · 10 min read

Differential Calculus and Optimization Basics › ConvexityOne section · Sections in this chapter6 / 11 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Convexity is a key structural property in optimization. When a function is convex, any local minimum is automatically a global minimum, dramatically simplifying the search for optimal solutions.

Convexity provides essential guarantees in optimization. A non-convex objective can have many valleys, and gradient-based methods can stop in any of them with no guarantee of finding the deepest one. For a convex objective over a convex feasible set, any local minimum is globally optimal. Convexity does not guarantee that a minimum is attained. Under standard finite-dimensional representations and regularity assumptions, this structure often makes global optimization algorithmically tractable. Actual computational cost still depends on the problem representation, dimension, oracle access, conditioning, constraints, and requested accuracy.

Definition and Intuition

The formal definition of convexity captures a simple geometric idea. A function is convex if the line segment connecting any two points on its graph lies above the graph itself. Alternatively, if you interpolate between two input points and evaluate the function at the interpolated point, you get a value no larger than if you had interpolated between the function values at the original points.

Convex Function

A function f:Rn→Rf: \mathbb{R}^n \to \mathbb{R} is convex if for any two points xx and yy and any θ∈[0,1]\theta \in [0, 1]:

f(θx+(1−θ)y)≤θf(x)+(1−θ)f(y)f(\theta x + (1 - \theta) y) \leq \theta f(x) + (1 - \theta) f(y)

where:

  • x,yx, y: any two points in the domain of ff
  • θ∈[0,1]\theta \in [0, 1]: a convex combination weight (interpolation parameter)
  • θx+(1−θ)y\theta x + (1 - \theta) y: a point on the line segment between xx and yy
  • θf(x)+(1−θ)f(y)\theta f(x) + (1 - \theta) f(y): the chord height at the interpolated input, between (x,f(x))(x,f(x)) and (y,f(y))(y,f(y))

Geometrically, this means the line segment connecting any two points on the graph lies above the graph itself.

The definition compares the graph and chord at the same interpolated input: a convex graph never rises above its chords. It can have flat portions or corners; convexity does not require strictly positive smooth curvature everywhere.

Imagine a convex bowl-shaped graph and a string connecting two points on it. The string stays above or on the graph along the segment. A nonconvex graph can instead rise above a chord somewhere along a segment, violating the inequality.

The parameter θ\theta can be thought of as a "mixing" proportion. When θ=0\theta = 0, we are entirely at point yy; when θ=1\theta = 1, we are entirely at point xx; and intermediate values of θ\theta give us intermediate points along the segment. The convexity inequality states that the function value at any such intermediate point is at most the correspondingly weighted average of the function values at the endpoints.

Out[29]:
Visualization
Plot of x^2 showing a chord between two points that lies above the curve.
Convex function: chord lies above the curve.
Plot of a non-convex function showing the curve above the chord between x equals 0 and x equals 1, violating the convexity inequality.
Non-convex function: the curve rises above the chord on part of the segment.

Testing for Convexity

For twice-differentiable functions on an open convex domain, convexity can be checked using the Hessian matrix.

A function ff on such a domain is convex if and only if its Hessian HH is positive semidefinite at every point. Checking eigenvalues at only one point establishes local curvature there, not global convexity.

Strict convexity means the chord inequality is strict for distinct inputs and 0<θ<10<\theta<1. A positive-definite Hessian everywhere on an open convex domain is sufficient, but not necessary: f(x)=x4f(x)=x^4 is strictly convex despite f′′(0)=0f''(0)=0. Strict convexity gives at most one minimizer on a convex feasible set, if a minimum is attained; it does not guarantee existence.

The Hessian captures how the gradient changes as we move through the space. Positive semidefiniteness everywhere means the function curves upward or remains flat in every direction, ruling out suboptimal local minima. It is not by itself an algorithmic convergence guarantee: for a differentiable convex function with an LL-Lipschitz gradient and an attained minimum, fixed-step gradient descent also needs an appropriate step such as 0<α<2/L0<\alpha<2/L.

For a function with continuous second derivatives near xx, a small vector change dd gives f(x+d)=f(x)+∇f(x)Td+12dTH(x)d+o(∥d∥2)f(x+d)=f(x)+\nabla f(x)^T d+\frac{1}{2}d^T H(x)d+o(\|d\|^2). Here H(x)H(x) is evaluated at the base point, and the remainder becomes small relative to the squared displacement. The quadratic term describes second-order directional curvature. If the Hessian is positive semidefinite everywhere on the open convex domain, restriction to each line segment establishes global convexity. A zero Hessian at one point does not make the nearby function constant.

For our quadratic portfolio variance function:

σp2=wTΣw\sigma_p^2 = w^T \Sigma w

where Σ\Sigma is the covariance matrix. The Hessian of this function is:

H=2ΣH = 2\Sigma

A valid covariance matrix is positive semidefinite because wTΣww^T\Sigma w is a variance and cannot be negative. Portfolio variance is therefore convex. Over the stated affine budget and target-return constraints, every feasible local minimum is global. This theorem applies to a verified solution under those constraints, not automatically to any array returned by a solver.

For the verified 8% target portfolio, no feasible allocation under those same constraints has lower variance. The budget-only minimum is a different problem, as is a different asset universe. Numerical confidence still depends on status, feasibility, tolerances, and an optimality check; convexity does not verify an unchecked computation or establish the accuracy of estimated inputs.

In[30]:
Code
import numpy as np

# Define covariance matrix (from earlier portfolio example)
sigma = np.array([0.20, 0.10])  # Standard deviations
rho = 0.3  # Correlation
cov_matrix = np.array(
    [
        [sigma[0] ** 2, rho * sigma[0] * sigma[1]],
        [rho * sigma[0] * sigma[1], sigma[1] ** 2],
    ]
)

# Verify convexity of portfolio variance
# Hessian is 2 * covariance matrix
H_portfolio = 2 * cov_matrix
eigenvalues_portfolio = np.linalg.eigvals(H_portfolio)
Out[31]:
Console
Covariance matrix:
[[0.04  0.006]
 [0.006 0.01 ]]

Hessian of variance function (2Σ):
[[0.08  0.012]
 [0.012 0.02 ]]

Eigenvalues of Hessian: [0.08231099 0.01768901]
All eigenvalues ≥ 0: True
Conclusion: Portfolio variance is convex

Why Convexity Matters in Finance

Convexity has significant practical implications in quantitative finance:

Portfolio optimization can be convex. With a positive-semidefinite covariance matrix and a convex feasible set such as linear equalities and inequalities, mean-variance minimization is a convex program. Every local minimum is then global, but a solver's returned point still requires success, feasibility, and numerical-tolerance checks.

Convexity removes suboptimal local-minimum traps from this formulation, but it does not guarantee that an arbitrary numerical run finds or accurately certifies a solution. Conditioning, tolerances, infeasibility, and implementation details still matter. Nonconvexity can introduce multiple basins and make global certification harder; its computational cost depends on the problem's structure rather than following a universal exponential search rule.

Convex risk measures reward mixing relative to an average benchmark. For a convex risk functional, the risk of a weighted combination cannot exceed the same weighted average of the component risks. Equality can occur, and the combination can still be riskier than one component; convexity does not promise a strict reduction in every comparison. Value-at-Risk is not convex in general.

If ρ(X)\rho(X) is a convex risk functional and we combine two portfolios XX and YY with weights θ\theta and 1−θ1-\theta, then ρ(θX+(1−θ)Y)≤θρ(X)+(1−θ)ρ(Y)\rho(\theta X + (1-\theta)Y) \leq \theta \rho(X) + (1-\theta) \rho(Y). The inequality supplies an upper bound relative to the weighted average. Whether the mixture is strictly safer than either component depends on the positions, dependence structure, weights, and risk functional.

Nonconvexity can make global certification harder. Multiple local minima may exist, and local gradient methods can stop in a nonglobal basin. Nontrivial integer choices, such as asset-selection decisions, can remove convexity guarantees and may require discrete or specialized methods. Difficulty depends on the structure and guarantee required; nonconvexity or integrality alone does not make every problem hard.

Examples of nonconvexity include a positive fixed fee charged for any nonzero trade but waived when there is no trade. An at-most-30-stock constraint is nonconvex when the asset universe permits feasible portfolios whose combined support exceeds 30; an already-small universe makes the restriction vacuous. Some loss distributions also make Value-at-Risk violate convexity. Depending on the structure and required guarantee, practitioners may use local methods, multi-start searches, relaxations, exact discrete algorithms, or global heuristics; heuristic methods do not by themselves certify a global optimum.

Out[32]:
Visualization
Convex objective with a single minimum and a gradient descent path converging to it.
This strictly convex quadratic has one global minimum; the path shows eight updates toward it.
Non-convex objective with multiple minima and gradient descent paths ending in different basins.
Non-convex: multiple local minima.