Quant Memo
Advanced

Calculus of Variations and the Euler-Lagrange Equation

A branch of calculus for finding the best whole function or path — not just the best single number — by turning 'which function minimizes this quantity' into a differential equation that any optimal function must satisfy.

Prerequisites: The Fundamental Theorem of Calculus

Ordinary calculus finds the single number that minimizes a function — set the derivative to zero, solve. But some problems ask for the best entire function: what consumption path over a lifetime maximizes total satisfaction, what trading trajectory minimizes market impact while liquidating a position, what shape minimizes travel time. There the unknown isn't a number, it's a whole curve, and the tool for finding it is the calculus of variations — its central result, the Euler-Lagrange equation, converts "which function is best" into an ordinary differential equation that any optimal function must obey.

An analogy: rippling a string to find its rest shape

Imagine a stretched elastic string under tension, free to sag under gravity between two fixed endpoints. Physically, the string settles into whatever shape minimizes its total potential energy. You could, in principle, compare every conceivable curve connecting the two endpoints and check which has lowest energy — an impossible search over infinitely many candidate shapes. Instead, physics says: nudge the true resting shape by any tiny perturbation, and the energy shouldn't change to first order, because it's already sitting at a minimum. Turning that "no first-order change under any nudge" condition into equations gives you a differential equation the true shape must satisfy, pinning down the winning curve without ever comparing it to its infinitely many rivals directly.

The equation, one symbol at a time

Consider minimizing a quantity expressed as an integral over a candidate function y(x)y(x) between fixed endpoints:

J[y]=abL(x,y(x),y(x))dx,J[y] = \int_{a}^{b} L\big(x, y(x), y'(x)\big)\,dx,

where LL, called the Lagrangian, is some known expression combining xx, the function's value yy, and its slope yy' at each point — J[y]J[y] is a single number (the "cost" or "energy") that depends on the entire shape of yy, not just one point. The function yy that minimizes JJ must satisfy the Euler-Lagrange equation:

Lyddx(Ly)=0.\frac{\partial L}{\partial y} - \frac{d}{dx}\left(\frac{\partial L}{\partial y'}\right) = 0.

In plain English: at the optimal function, the direct sensitivity of the cost to nudging yy up or down at a point must exactly balance the rate of change, along the curve, of the cost's sensitivity to the slope at that point — a local balance condition that, applied at every xx, pins down the whole optimal curve as the solution to a differential equation.

Worked example 1: the shortest path is a straight line

Minimize arc length between two points, L=1+(y)2L = \sqrt{1 + (y')^2} (this is what "minimize length" looks like as an integral). Since LL doesn't depend on yy directly, L/y=0\partial L/\partial y = 0, so the Euler-Lagrange equation reduces to ddx(Ly)=0\frac{d}{dx}\left(\frac{\partial L}{\partial y'}\right) = 0, meaning L/y=y1+(y)2\partial L/\partial y' = \frac{y'}{\sqrt{1+(y')^2}} is constant along the optimal path. A fraction with this form staying constant forces yy' itself to be constant — the slope never changes. A curve with constant slope is a straight line. The calculus of variations recovers, from pure symbol manipulation, the geometrically obvious fact that the shortest path between two points is a straight line — reassuring on a simple case, and the same machinery generalizes to problems with no obvious answer.

Worked example 2: a minimal-impact trading trajectory

Suppose an idealized cost of trading at rate y(t)y'(t) (shares per unit time) is L=(y(t))2L = (y'(t))^2 — a standard simplification where trading impact cost grows with the square of trading speed, penalizing fast trading disproportionately. Since LL doesn't depend on yy directly here either, the same logic applies: L/y=2y\partial L/\partial y' = 2y' must be constant, forcing yy' constant — the cost-minimizing strategy trades at a constant rate throughout the period, never speeding up or slowing down. This is the textbook justification for a simple time-weighted-average-price (TWAP) execution schedule under a quadratic impact assumption: the calculus of variations shows constant-rate trading isn't just a convenient default, it's the actual minimizer of total impact cost under that cost model.

dashed curves: candidates with higher J[y]; solid: the Euler-Lagrange minimizer
Among all curves joining two fixed points, the Euler-Lagrange equation singles out the one true minimizer of the cost functional — here, for arc length, that curve is the straight line.
time constant rate (optimal) front-loaded (higher cost)
Under quadratic impact cost, the Euler-Lagrange equation shows a constant trading rate minimizes total cost — front-loading or back-loading the trade both cost strictly more.

What this means in practice

Calculus of variations underlies optimal execution models (from the simple constant-rate result above to more elaborate models like Almgren-Chriss, which balance impact cost against price-risk over time), consumption-investment problems in lifetime portfolio theory, and interest-rate curve fitting where the fitted curve is chosen to minimize a smoothness-penalized fit to market data. Wherever a problem asks for a best function of time rather than a best number, this machinery is the standard route to a solvable equation.

The Euler-Lagrange equation, L/yddx(L/y)=0\partial L/\partial y - \frac{d}{dx}(\partial L/\partial y') = 0, is the condition any function that minimizes an integral cost J[y]=L(x,y,y)dxJ[y] = \int L(x,y,y')\,dx must satisfy — it converts "find the best function" into an ordinary differential equation for that function.

Solving the Euler-Lagrange equation gives a function where the cost is stationary — unchanged to first order under small nudges — which is necessary for a minimum but not automatically sufficient; the resulting curve could in principle be a maximum or a saddle in function-space. In practice, for the well-behaved convex cost functions common in finance (like the quadratic impact cost above), the stationary solution is indeed the minimizer, but that convexity should be checked, not assumed, before trusting the result as optimal rather than merely stationary.

Related concepts

Practice in interviews

Further reading

  • Gelfand & Fomin, Calculus of Variations
  • Kirk, Optimal Control Theory: An Introduction
ShareTwitterLinkedIn