Trading Dev AcademyFree quant education

Free lesson · Integral calculus

Substitution: reverse the chain rule without losing the bounds

Open interactive lessonPractice calculationsExplore labs

Start with the idea

  • When changing the variable, also change the little interval widths and the start and end values. Otherwise you are adding up the wrong pieces.
Symbols, units & horizon
  • x: original dimensionless integration variable
  • u: transformed variable x²
  • dx,du: corresponding integration measures
  • e: exponential base
  • bounds 0 and 1 transform to 0² and 1²
  • no time horizon

When and why to use this

Use substitution to simplify continuous expectations and integration measures. Test transformed and original integrands against the same numerical benchmark.

Start here · the same idea in everyday words

Technical termEveryday meaningConcrete example
SubstitutionReplacing an expression with a new variable to simplify a calculation.Call x squared u, then rewrite the rest using u.
DifferentialThe part of integral notation that tracks a very small change in the chosen variable.If u=x squared, du=2x dx tells us how interval widths change.
BoundsThe starting and ending values used for a definite integral.Original endpoints must be converted to the new variable too.

Unpack a technical sentence

Technical wording: Transform the integration measure and endpoints consistently.

Read it as: When changing the variable, also change the little interval widths and the start and end values. Otherwise you are adding up the wrong pieces.

A slower worked example · one step at a time

  1. Integrate the dimensionless expression 2x times exp(x squared) from x=0 to x=2.
  2. Set u=x squared. Its differential is du=2x dx, which replaces the entire 2x dx factor.
  3. The starting x=0 becomes u=0. The ending x=2 becomes u=4, not u=2.
  4. The new problem adds exp(u) from u=0 to u=4. Its antiderivative is exp(u), so the result is exp(4) minus exp(0), about 53.59815.
  5. Using the old ending bound 2 would give exp(2) minus 1, about 6.38906. That large difference is a bounds error, not a rounding error.
Self-assessed: If x ends at 2 and u=x squared, where must u end?

At 4. Bounds describe values in the current variable, so you must evaluate the substitution at the original endpoints.

Study loop: predict the result, work through the arithmetic, run the Python, then explain which assumption would make the result unreliable.

  • Look for a nested expression whose derivative also appears as a factor. Set that expression equal to a new variable and explicitly compute its differential.
  • For a definite integral, either transform both bounds into the new variable or return to the old variable before evaluating. Mixing the two gives an incorrect result.
  • This example uses dimensionless variables. In pricing, a change from price to log-price also transforms the integration measure; forgetting its Jacobian changes the expectation.
Before reading the working, evaluate exp(1)-1. Give the result in dimensionless area.

The integral is e−1≈1.718281828. A numerical midpoint sum should approach that exact calculus result as the number of intervals increases.

∫012xex2dx=∫01eudu=e−1,u=x2,du=2xdx
Calculus: derivation and arithmetic

Substitution: reverse the chain rule without losing the bounds

  1. Choose u=x² so du=2x dx. The entire factor 2x dx becomes du.
  2. Transform the endpoints: x=0 gives u=0, and x=1 gives u=1.
  3. The antiderivative of exp(u) is exp(u). Evaluate exp(1)−exp(0)=e−1≈1.718281828.
Work it by hand

The integral is e−1≈1.718281828. A numerical midpoint sum should approach that exact calculus result as the number of intervals increases.

An analogy to remember

Changing the markings on a ruler changes the width assigned to each small interval. The differential keeps the accumulated quantity consistent.

How this becomes a building block

A pricing integral in log-price coordinates needs both a transformed payoff and the correct transformed measure.

Python · run and reuse

Architecture pseudocode

# Python 3.10+; standard library only unless NumPy is imported.
# Synthetic teaching inputs; no historical performance claim.
from math import exp

def substitution_example(n=1000):
    if not isinstance(n,int) or n < 1: raise ValueError("Positive integer n required")
    h = 1/n
    estimate = sum(2*((i+0.5)*h)*exp(((i+0.5)*h)**2)*h for i in range(n))
    return exp(1)-1, estimate

print(substitution_example())

# Replay the slower, synthetic example above. Units are stated in its steps.
def plain_language_example():
    from math import exp, e  # Standard library; no extra dependency.
    return {
        "correct": exp(4)-1,
        "wrong_bounds": exp(2)-1,
    }

print(plain_language_example())
Self-assessed: explain the calculation, its output units, and one condition under which it fails.

Use substitution to simplify continuous expectations and integration measures. Test transformed and original integrands against the same numerical benchmark. A noninvertible substitution can require splitting the domain into monotone branches. Changing a variable without its differential or bounds changes the problem.

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 only unless NumPy is imported.
# Synthetic teaching inputs; no historical performance claim.
from math import exp

def substitution_example(n=1000):
    if not isinstance(n,int) or n < 1: raise ValueError("Positive integer n required")
    h = 1/n
    estimate = sum(2*((i+0.5)*h)*exp(((i+0.5)*h)**2)*h for i in range(n))
    return exp(1)-1, estimate

print(substitution_example())

# Replay the slower, synthetic example above. Units are stated in its steps.
def plain_language_example():
    from math import exp, e  # Standard library; no extra dependency.
    return {
        "correct": exp(4)-1,
        "wrong_bounds": exp(2)-1,
    }

print(plain_language_example())

Continue learning

Integral Calculus: Accumulation & Area — all lessons
  1. Start with rectangles: rate × time = amount
  2. Definite integrals: adding many small contributions
  3. Core integral rules: undo a derivative, then check
  4. Antiderivatives and the fundamental theorem
  5. Integration techniques: substitution and integration by parts
  6. Improper integrals, densities and continuous expectations
  7. Numerical integration and a continuous cash-flow building block
  8. Substitution: reverse the chain rule without losing the bounds
  9. Integration by parts: transfer a derivative

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