Trading Dev AcademyFree quant education

Free lesson · Integral calculus

Improper integrals, densities and continuous expectations

Open interactive lessonPractice calculationsExplore labs

Start with the idea

  • A density assigns probability per unit of the outcome variable.
  • Integrating it over a region gives probability; weighting it by an outcome before integrating gives an expectation.
  • This is the continuous version of a probability-weighted sum.
Symbols, units & horizon
  • X: nonnegative continuous random variable
  • x: a possible value of X
  • p(x): density in inverse x-units
  • λ: positive rate in inverse x-units
  • E[X]: mean in x-units
  • ∞: infinite upper bound interpreted as a limit
  • b: finite temporary upper bound
  • e: exponential base
  • P(X>b): probability of exceeding b

When and why to use this

Use density integrals to compute continuous probabilities and expected quantities. Check support, normalisation and moment existence before applying a mean-based model.

  • A continuous density is nonnegative and integrates to one.
  • Its height is not itself a probability and may exceed one when its units permit it.
  • A single point has probability zero under a continuous density, but an interval can have positive probability.
  • An improper integral has an infinite bound or a singularity and is defined by a limit.
  • Convergence must be checked.
  • A normalised density can still have an infinite mean or variance, so valid probabilities do not guarantee finite moments.
p(x)=λe−λx (x≥0),∫0∞p(x)dx=1,𝔼[X]=∫0∞xp(x)dx=1λ
Calculus: derivation and arithmetic

Improper integrals, densities and continuous expectations

  1. Integrate to a finite bound first: ∫0bλe−λxdx=[−e−λx]0b=1−e−λb. For λ>0, this tends to 1 as b→∞.
  2. For the first moment choose u=x, dv=λe−λxdx. Then du=dx and v=−e−λx.
  3. Integration by parts gives ∫0bxλe−λxdx=−be−λb+1−e−λbλ. Both exponential boundary terms vanish in the limit, leaving E[X]=1λ.
  4. The tail is the complementary probability: P(X>b)=1−(1−e−λb)=e−λb. At λ=2 per minute and b=1 minute, the mean is 0.5 minute and the tail is approximately 0.135335.
Work it by hand

If λ=2 per minute, mean waiting time is .5 minute. The probability of waiting longer than 1 minute is exp(−2)≈.135335. This is a distributional assumption, not a universal waiting-time law.

An analogy to remember

Density is like the thickness of material along a strip. Height at one location is not total mass; area under the thickness curve over an interval is.

How this becomes a building block

Expectations, tail losses and risk-neutral payoff prices are weighted integrals. A waiting-time model can be a component of a toy arrival or execution model. The Poisson/exponential assumptions would need empirical checking before describing actual orders.

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.

from math import exp, expm1

def exponential_model(rate,threshold):
    if rate<=0 or threshold<0: raise ValueError("Positive rate, nonnegative threshold required")
    return {"density":rate*exp(-rate*threshold),
            "cdf":-expm1(-rate*threshold),"tail":exp(-rate*threshold),"mean":1/rate}

print(exponential_model(2,1))

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

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