Free lesson · Differential calculus
Chain rule workshop: nested functions and backpropagation
Open interactive lessonPractice calculationsExplore labs
Start with the idea
- Work backward through a chain of calculations. At each step, multiply by how quickly that step’s output changes. A scalar is just one number rather than a list of numbers.
Symbols, units & horizon
- x: dimensionless input
- u: inner value
- v: model output
- y: fixed dimensionless target
- L: squared-error loss
- dL/dx: local loss sensitivity
- all values are at one evaluation point, with no time horizon
When and why to use this
Use the chain rule to differentiate a calibration loss through a pricing model or a neural forecast. Check a hand-computable toy case and several finite-difference steps before trusting a full gradient.
Start here · the same idea in everyday words
| Technical term | Everyday meaning | Concrete example |
|---|---|---|
| Composite function | A calculation that uses another calculation’s answer. | First double a number and add one; then square the answer. |
| Sensitivity | How much the answer changes for a very small input change. | A slope of 12 means a small input increase of .01 predicts about .12 extra output. |
| Backpropagation | Working backward through the calculation to find each input’s effect on the final answer. | Start with the final loss and multiply the local slopes backward. |
Unpack a technical sentence
Technical wording: Reverse accumulation propagates sensitivities through a scalar composition.
Read it as: Work backward through a chain of calculations. At each step, multiply by how quickly that step’s output changes. A scalar is just one number rather than a list of numbers.
A slower worked example · one step at a time
- Start with x=1. The first calculation doubles x and adds one, giving u=3. The second calculation squares u, giving an output of 9. All values in this example are dimensionless.
- The first calculation has slope 2: increasing x by .01 increases u by .02.
- At u=3, the squaring calculation has slope 6. Combine the slopes: 6 times 2 gives 12 output units per input unit.
- A small input increase of .01 therefore predicts an output increase of 12 times .01, or .12. The actual output at x=1.01 is 3.02 squared, or 9.1204.
- The prediction gives 9.12 rather than 9.1204 because a derivative describes a tiny change. The remaining .0004 comes from curvature. In the larger loss example below, there is one more step: translate the model output’s change into the loss change.
Self-assessed: Why do we multiply by 2 as well as 6?
Because the first calculation makes the intermediate value change twice as quickly as the original input. Using 6 alone would measure output change per unit of the intermediate value, not per unit of the original input.
Study loop: predict the result, work through the arithmetic, run the Python, then explain which assumption would make the result unreliable.
- Name every intermediate value before differentiating: x feeds u, u feeds v, and v feeds a loss L. Work forward to get values, then backward to propagate sensitivities.
- For a scalar chain, reverse accumulation starts at the loss with sensitivity one. At a branching node, contributions add because the total differential is linear. This is the calculus behind backpropagation and reverse-mode automatic differentiation.
- Here x, u, v and L are dimensionless synthetic calibration quantities. Automatic differentiation applies exact chain rules to the implemented operations, subject to floating-point arithmetic; finite differences approximate a derivative by evaluating nearby inputs. Neither method checks whether the economic model is correct.
Before reading the working, evaluate 6*256*6. Give the result in loss units per input unit.
At x=1 the loss slope is 9216 loss units per input unit. A small negative step initially lowers the loss; this local statement does not choose a safe optimiser step.
Chain rule workshop: nested functions and backpropagation
- Forward pass at x=1 and y=250: u=3×1²+1=4; v=4⁴=256; residual v−y=6; L=6²/2=18.
- Backward pass: dL/dv=v−y=6; dv/du=4u³=256; du/dx=6x=6.
- Multiply 6×256×6=9216. Omitting the inner slope would produce 1536, a different derivative.
At x=1 the loss slope is 9216 loss units per input unit. A small negative step initially lowers the loss; this local statement does not choose a safe optimiser step.
An analogy to remember
A gear train multiplies rotation ratios along each connected path. A branching drive adds the contributions that reach the same output.
How this becomes a building block
A calibration routine can return both its loss and gradient. Passing the gradient to an optimiser saves repeated model evaluations, but the step size still needs its own control.
Python · run and reuse
Architecture pseudocode
# Python 3.10+; standard library only unless NumPy is imported.
# Synthetic teaching inputs; no historical performance claim.
def loss_and_gradient(x, target):
# All inputs/outputs dimensionless; target held fixed.
u = 3*x*x + 1
v = u**4
residual = v-target
return 0.5*residual**2, residual*4*u**3*6*x
def check_gradient(x, target, h=1e-6):
if h <= 0: raise ValueError("h must be positive")
return (loss_and_gradient(x+h,target)[0]-loss_and_gradient(x-h,target)[0])/(2*h)
print(loss_and_gradient(1,250), check_gradient(1,250))
# 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 {
"start": (2*1+1)**2,
"slope": 2*(2*1+1)*2,
"prediction": 9+12*.01,
"actual": (2*1.01+1)**2,
}
print(plain_language_example())Self-assessed: explain the calculation, its output units, and one condition under which it fails.
Use the chain rule to differentiate a calibration loss through a pricing model or a neural forecast. Check a hand-computable toy case and several finite-difference steps before trusting a full gradient. All component derivatives must exist at the evaluation point. Kinks, discrete execution decisions and unstable intermediate values can invalidate a smooth gradient interpretation.
Research checkpoint · reviewed 13 October 2026
Noguer I Alonso, Derivative-Informed Operator Learning for Finance, arXiv working paper submitted 4 June 2026. Abstract-only review: reported model experiments use Black–Scholes, Heston and Bates derivatives; historical market instruments and observation dates are not established by the abstract. It motivates checking sensitivities separately from prices. We adopt no reported error reduction as a trading result; derivative consistency does not by itself ensure economic constraints or profitable hedging.
Further reading: Primary working paper · arXiv:2606.05900 ↗
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.
def loss_and_gradient(x, target):
# All inputs/outputs dimensionless; target held fixed.
u = 3*x*x + 1
v = u**4
residual = v-target
return 0.5*residual**2, residual*4*u**3*6*x
def check_gradient(x, target, h=1e-6):
if h <= 0: raise ValueError("h must be positive")
return (loss_and_gradient(x+h,target)[0]-loss_and_gradient(x-h,target)[0])/(2*h)
print(loss_and_gradient(1,250), check_gradient(1,250))
# 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 {
"start": (2*1+1)**2,
"slope": 2*(2*1+1)*2,
"prediction": 9+12*.01,
"actual": (2*1.01+1)**2,
}
print(plain_language_example())Continue learning
Differential Calculus: Limits & Derivatives — all lessons- Start with a straight line: input, output and slope
- Functions, limits and continuity
- The derivative: from an average slope to an instantaneous rate
- Core derivative rules: constants, powers and sums
- Derivative rules: powers, products, quotients and compositions
- Chain rule workshop: nested functions and backpropagation
- Second derivatives, Taylor expansions and numerical error
- Stationary points, optimisation and Newton’s method
- Implicit and inverse differentiation: sensitivities of solved parameters
- Logarithmic differentiation and elasticities
- L’Hôpital’s rule: resolve indeterminate ratios carefully
Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations