Trading Dev AcademyFree quant education

Free lesson · Integral calculus

Definite integrals: adding many small contributions

Open interactive lessonPractice calculationsExplore labs

Start with the idea

  • An integral accumulates a quantity continuously.
  • Start with a finite sum of rate times interval width, then imagine refining the intervals.
  • Signed area is one useful picture, but the physical meaning comes from the units.
Symbols, units & horizon
  • ∫: integral or continuous accumulation
  • a,b: start and end of the integration interval
  • x: variable of integration
  • dx: infinitesimal input width in the integral notation
  • n: number of equal subintervals
  • Δx: their finite width
  • xᵢ*: chosen sample point in subinterval i
  • Σ: sum all interval contributions
  • lim n→∞: limit as the equal partition is refined

When and why to use this

Use a definite integral when a quantity is naturally expressed as contributions over time, distance or another continuous variable. The accumulation lab compares rectangles with an exact total.

  • If water flows at q(t) litres per minute, q(t) times a short duration approximates the litres added in that interval.
  • Adding over intervals approximates the total volume.
  • The integral is the limiting total when the function is integrable and the partition is refined.
  • A region below the horizontal axis contributes negatively to the signed integral.
  • Total geometric area instead integrates the absolute value.
  • Reversing the integration bounds reverses the sign.
∫abf(x)dx=limn→∞⁡∑i=1nf(xi∗)Δx,Δx=b−an
Calculus: derivation and arithmetic

Definite integrals: adding many small contributions

  1. For f(x)=2x on [0,1], divide the interval into n equal pieces: Δx=1n, with right endpoints xi=in.
  2. The right-endpoint sum is Sn=∑i=1nf(xi)Δx=2n2∑i=1ni. Substitute ∑i=1ni=n(n+1)2 to obtain Sn=(n+1)n.
  3. Take the limit: limn→∞⁡(1+1n)=1. Left endpoints give (n−1)n, whose limit is also 1. The finite sums approximate the area; their common limit gives the integral.
Work it by hand

With four right-end rectangles the heights are .5,1,1.5,2 and width .25. Total=1.25. With four left rectangles the total is .75. The exact integral is 1.

Architecture pseudocode

def riemann(function,a,b,n,side="right"):
    if not isinstance(n,int) or n<1: raise ValueError("Positive integer n required")
    if side not in ("left","right","midpoint"): raise ValueError("Unknown sample convention")
    offset={"left":0,"right":1,"midpoint":.5}[side]
    dx=(b-a)/n
    return sum(function(a+(i+offset)*dx)*dx for i in range(n))

print(riemann(lambda x:2*x,0,1,4),riemann(lambda x:2*x,0,1,4,"left"))

An analogy to remember

Adding the water collected in many short time intervals reconstructs how much passed through a pipe. A finer measuring schedule better tracks a changing flow.

How this becomes a building block

An integral can be the entire quantity of interest, such as total flow. Within finance it can accumulate a funding rate, a deterministic execution-cost rate or discounted continuous income. Specify whether the integrand is currency/time, probability density or something else before interpreting its integral.

Further reading: OpenStax Calculus, Volume 1 — definitions and standard theorems ↗

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.

def riemann(function,a,b,n,side="right"):
    if not isinstance(n,int) or n<1: raise ValueError("Positive integer n required")
    if side not in ("left","right","midpoint"): raise ValueError("Unknown sample convention")
    offset={"left":0,"right":1,"midpoint":.5}[side]
    dx=(b-a)/n
    return sum(function(a+(i+offset)*dx)*dx for i in range(n))

print(riemann(lambda x:2*x,0,1,4),riemann(lambda x:2*x,0,1,4,"left"))

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