Integration
An integral adds up a rate. Read as the area under a density, it says how often a −5% day should happen; 0050 says otherwise.
| Mastery | After this module you should be able to: |
|---|---|
| 1interpret a definite integral as accumulated change and as signed area, and approximate it with left, right and midpoint Riemann sums | |
| 2evaluate definite integrals with the fundamental theorem of calculus, and differentiate integrals whose limits depend on a variable | |
| 3apply substitution and integration by parts to the integrals that recur in finance, including the standardization of a normal probability | |
| 4determine whether an improper integral converges, derive the Gaussian integral, and explain how a heavy tail makes a variance or kurtosis infinite | |
| 5calculate the present value and duration of a continuous cash-flow stream under continuous discounting | |
| 6calculate probabilities and expectations as integrals of a density, and compare a normal model's tail probabilities with the observed frequencies of 0050's daily returns | |
7implement the trapezoidal and Simpson rules, state their error orders, and verify them numerically and with scipy.integrate |
1Introduction
An integral adds up a quantity that changes continuously: interest accruing under a moving rate, cash arriving as a stream, probability spread along the return axis. Each is a rate multiplied by a small width and summed, and each is the area under a curve. This module builds the integral from such sums, evaluates it with the fundamental theorem of calculus, extends it to infinite intervals and computes it numerically when no formula exists. One risk question runs through all of it.
Take 0050's 2,902 daily total returns from 3 November 2014 to 8 October 2026. Their mean is 0.0871% and their standard deviation 1.2385%. A risk model that treats daily returns as normal with these two numbers draws a bell curve. The probability of a day at or below −5% is the area under that curve to the left of −5%.
That area is . Over 2,902 days the model expects 0.058 such days, or one every 206 years.
The data contain nine (Exhibit 1). Five of them fell between April 2024 and July 2026. On 7 April 2025 0050 closed down 10.000%, the exchange's daily limit; under the fitted model a day that bad comes once in years.
Was the area computed wrongly, is the model wrong, or was the market unlucky? The area has no formula, because the bell curve has no elementary antiderivative. By Section 8 you will compute it four ways, compare it with the data threshold by threshold, and see where the model's tail runs out.
| Date | Daily total return | Normal model: probability of a day this bad | Normal model: one such day every … years | |
|---|---|---|---|---|
| 2018-10-11 | −7.027% | −5.744 | ||
| 2020-01-30 | −5.681% | −4.657 | 2,600 | |
| 2020-03-19 | −5.838% | −4.784 | 4,800 | |
| 2022-10-11 | −5.179% | −4.252 | 390 | |
| 2024-04-19 | −5.064% | −4.160 | 260 | |
| 2024-08-02 | −5.054% | −4.151 | 250 | |
| 2024-08-05 | −9.130% | −7.442 | ||
| 2025-04-07 | −10.000% | −8.145 | ||
| 2026-07-17 | −5.874% | −4.813 | 5,500 | |
| Any day at or below −5% | 9 days actual | −4.1074 | 206 (0.058 days expected) |
TaiwanStockPrice and TaiwanStockDividendResult, retrieved 10 October 2026; daily total returns, adjusted for the 4-for-1 split of 18 June 2025, on the trading days common to 0050 and 00631L (LM3). These merge 0050's five sessions of 25–31 March 2026, when 00631L was halted for its split, into one return of −2.755%; 0050's own 2,906 days give the same counts in Exhibit 6 but move the band counts of Example 3 by one or two. The model uses and the population standard deviation ; , and the return period years, with the 2,902 days' , come from the unrounded return, and . Computations: data/lm05_numbers.py and LM05_lab.ipynb.Sections 2 and 3 define the integral as a limit of sums and evaluate it with antiderivatives; Section 4 adds substitution and integration by parts. Section 5 extends integrals to infinite intervals and shows how heavy tails make moments infinite. Section 6 values continuous cash flows, Section 7 resolves the case with densities, and Sections 8 and 9 compute integrals numerically, by hand and in Python.
As in LM3, is a generic function (this module has no exposures) and an antiderivative, ; and are further generic functions, a generic coordinate, and and the ends of an interval (this module has no bets). A variable of integration (, , ) has a meaning only inside its integral. A density is also an ; is the standard normal density, its distribution function, a standardized value and a probability. is a generic random quantity with density , instantiated per example (the Pareto ratio , the log growth ), and a standard normal one; says that probabilities of are areas under the normal density with mean and standard deviation (LM14 defines random variables).
is a continuously compounded rate per year, the instantaneous rate at time and a horizon in years. and are the sample mean and population standard deviation of 0050's daily returns; the counts are returns and panels of width or , and are summation indices, and is a moment's order. Local symbols: the threshold ; the accumulation function ; the sums , , , , (left, right, midpoint, trapezoid, Simpson), distinct from the return and the horizon , and a panel's midpoint ; constants , ; the normal tail beyond ; the cash-flow rate ; the tail index , power and Student degrees of freedom ; the mean and variance of log growth.
2Accumulation and Area
Rate times time, added up
A deposit earning a constant continuously compounded rate for a time accumulates of log growth (LM1). If the rate moves during the year, no single product works. Split the year into short pieces on which the rate is nearly constant, multiply each piece's rate by its length, and add. The finer the split, the closer the sum comes to one number: the accumulated rate.
Draw the rate as a curve over the time axis. Each product is a thin rectangle, the sum is the area of a staircase, and the limit is the area under the curve. Accumulation and area are one idea.
For defined on , choose a partition with widths and a sample point in each piece. The Riemann sum is . The function is integrable on if these sums approach one number as the widest piece shrinks to zero, whatever the sample points. That number is the definite integral
Every continuous function on a closed interval is integrable. So is a bounded function with finitely many jumps, such as a policy rate that changes on announcement dates (stated without proof; Stewart, Clegg and Watson 2021). The letter is a dummy: .
Where is negative the products are negative, so the integral is a signed area: area above the axis minus area below. A P&L rate that is positive in the morning and negative in the afternoon integrates to the day's net P&L, not its gross. Three properties follow at once from the same properties of finite sums:
- Linearity: for constants , .
- Additivity: for ; we set .
- Monotonicity: if on then ; in particular when .
Left, right and midpoint sums
With equal panels of width and grid points , three choices of sample point have names:
For an increasing the left value of each panel is its minimum and the right value its maximum, so . The gap telescopes:
So for a monotone function each one-sided sum lies within of the integral. The error is : halving the panel width halves the error bound. The midpoint sum does much better, with an error of order ; Section 8 shows why.
A one-year floating-rate deposit is expected to pay the continuously compounded rate , with in years (an illustrative path, not a forecast). The rate starts at 1.5% and approaches 2.0%. Approximate the accumulated rate with left, right and midpoint sums for , 12 and 365, and value NT$1,000,000 deposited for the year.
For , and the rate at is 1.50000%, 1.69673%, 1.81606%, 1.88843% and 1.93233%. The left sum is ; the right sum drops the first rate and adds the last, giving 1.8334%. The exact value, , comes from Section 3 in one line. Exhibit 2 draws both staircases.
| Panels | Left | Right | Midpoint |
|---|---|---|---|
| 4 | 1.7253% (−5.85 bp) | 1.8334% (+4.96 bp) | 1.7861% (+0.224 bp) |
| 12 | 1.7653% (−1.85 bp) | 1.8013% (+1.75 bp) | 1.7841% (+0.0250 bp) |
| 365 | 1.7832% (−0.0593 bp) | 1.7844% (+0.0592 bp) | 1.7838% (+0.00003 bp) |
Errors, sum minus exact value, computed before rounding, are in brackets. Moving from 4 to 12 panels makes three times smaller: the one-sided errors shrink about threefold, as predicts, and the midpoint error about ninefold, as predicts. At both one-sided errors respect the bound bp.
In money: the exact accumulation factor is , so NT$1,000,000 grows to NT$1,017,998. The quarterly left sum predicts NT$1,017,403, NT$596 short (computed before rounding), and the quarterly midpoint sum NT$1,018,021. Daily accrual, , is itself a Riemann sum, and its left-sum error is under 0.06 bp.
An integral of a rate is only meaningful when is measured in the unit of the rate's denominator. A 2% annual rate held for 30 calendar days accrues of log growth, not . Convert the time axis, not the answer, and decide whether a year means 365 calendar days or trading days, as in the case's sample (LM1).
速率乘以時間就是累積量:利率乘以期間得到利息,機率密度乘以區間寬度得到機率。速率會變動時,就把區間切細,每一小段用「當時的速率 × 寬度」近似,再全部加總,這就是黎曼和;切到無限細的極限就是定積分,也就是曲線下的有號面積。左端點與右端點近似的誤差與格寬 成正比,中點近似的誤差與 成正比,所以中點法收斂快得多。銀行的「每日計息」本身就是一個 的黎曼和。
A rate path falls steadily (monotonically) from 2.0% to 1.5% over one year. Does the left sum overestimate or underestimate ? Bound its error using only the two endpoint rates.
Answer
For a decreasing function each panel's left value is its maximum, so overestimates and underestimates. The telescoping argument gives bp.
3The Fundamental Theorem of Calculus
Riemann sums define the integral but are a slow way to compute it. The fundamental theorem of calculus connects integrals with the derivatives of LM2: accumulating a rate and differentiating an accumulated amount undo each other.
Define the accumulation function . Increase by a small : gains a thin strip of width whose height is close to , so . The rate at which accumulated area grows is the height of the curve.
Let be continuous on .
- The accumulation function is differentiable on , with .
- If is any function with on , an antiderivative of , then
Proof. (1) For let and be the minimum and maximum of on . Additivity and monotonicity give ; divide by . As , continuity squeezes and to , so the difference quotient tends to ; the case is symmetric.
(2) By part 1, has zero derivative on , so it is constant there by the mean value theorem (LM2), and by continuity on . Since , , and gives (5.2).
Part 2 is the computing tool: find any antiderivative and subtract. Two antiderivatives differ by a constant, which cancels. The family of all antiderivatives is the indefinite integral, written . Every derivative rule of LM2 read backwards is an antiderivative; Exhibit 3 lists the ones this book uses.
| Antiderivative | Condition | Where used | |
|---|---|---|---|
| moments, power tails (Section 5) | |||
| divergence of | |||
| discounting, annuities (Section 6) | |||
| — | normal tail means (Sections 4, 7) | ||
| duration (Sections 4, 6) | |||
| none in elementary functions | — | normal probabilities (Sections 7, 8) |
Accumulation with a moving rate
The theorem finishes Example 1 exactly. An antiderivative of is , so .
More generally, money compounding at a moving rate satisfies : it grows at the rate per unit of wealth. By the chain rule , so is an antiderivative of , and (5.2) gives
is the discount factor for time . With a constant rate, (5.3) is the of LM1; with a moving rate, the integral replaces . The average rate is the continuously compounded zero yield, and is the forward rate of LM2, as Section 4 confirms.
Limits that move
Part 1 combined with the chain rule differentiates integrals whose limits depend on a variable. If and are differentiable and is continuous on an interval containing their values,
The case that matters most here is the normal distribution function , the area to the left of under the standard normal density. Section 5 shows that this area is finite. Writing and applying part 1 gives .
Under a normal model with mean and standard deviation , the probability of a day at or below is with ; Section 4 derives this. For the case, , and ; at full precision (Example 3) they give , where and (Section 7 computes , Section 8 ). Find the elasticity , and compare its linear prediction for a 10% higher with the exact change.
The chain rule and give with . The elasticity is therefore . A 1% error in moves the tail probability by about 18%.
For 10% higher, 1.3624%, the linear prediction is . Exactly, becomes and , 4.71 times the original: . The linear rule ignores compounding: an elasticity converts small percentage changes, and over a 10% move they compound.
Even in logs, , a factor of 5.44, overshoots, because the elasticity falls to 14.83 at the new . Under a normal model a 10% error in is almost a factor-of-five error in the probability of a −5% day.
Applied blindly, (5.2) gives : a negative area for a positive function. The integrand is unbounded at 0, so the integral is improper (Section 5); each half diverges, and the integral does not exist. Check that is continuous on the closed interval before subtracting antiderivative values.
把速率從 累積到 得到累積函數 ;再對 微分,就回到原本的速率 。所以算定積分不必真的加總無限多個長方形,只要找到任何一個導數等於 的函數 ,計算 即可。利率會變動時,財富是 ,積分取代了 。同一個定理也說常態分配函數的導數就是密度,;由此可知尾端機率對波動度極為敏感:在 −5% 的門檻, 錯 10%,機率就差將近 5 倍。
LM2 defined the instantaneous forward rate as . Show that this definition agrees with (5.3).
Answer
From (5.3), . By part 1 of the theorem, : the forward rate of LM2 is exactly the integrand of (5.3). A rate curve and its discount curve carry the same information; differentiation and integration convert one into the other.
4Techniques: Substitution and Integration by Parts
Most antiderivatives in finance come from two rules, each a derivative rule of LM2 read backwards. The chain rule becomes substitution; the product rule becomes integration by parts.
Substitution
If , the chain rule gives . Integrating both sides with (5.2) gives the rule.
If has a continuous derivative on and is continuous on an interval containing , then
In practice: name the inner function , replace by , and move the limits with the variable. The bookkeeping “” is the chain rule.
Standardizing. The substitution that matters most here is linear. The normal density with mean and standard deviation is . With we have , and (5.4) gives
Every normal probability is a difference of two values of one function, . The factor is not decoration: stretching the horizontal axis by must shrink the height by , or the area would change. Letting , which Section 5 justifies, gives .
Under the case's normal model, express and through , and compare the second with the data.
For the tail, with and carried to full precision, , so : a −5% day is a “4.1-sigma” day for 0050. The sample standard deviation with divisor , 1.23873%, gives and a probability 0.3% higher, which changes none of the conclusions.
For the centre, the limits standardize to and . So . In the data, 2,029 of the 2,902 days, 69.92%, fell in that band.
The normal model puts too little probability near zero as well as in the far tails. It compensates in the shoulders: between −3% and −1% () it expects 533 days against 352 observed, and between +1% and +3% () it expects 642 against 434.
A non-linear substitution. With and ,
This identity gives the normal model's tail means in Section 7 and the polar-coordinates proof in Section 5.
Integration by parts
The product rule , integrated with (5.2), trades one integral for another.
If and have continuous derivatives on , then
The trade pays when becomes simpler on differentiation, such as a power of , while is easy to integrate, such as an exponential.
Time-weighted discounting. Take and , so :
The integrand weights each instant's discount factor by its date; Section 6 turns the integral into a duration. The Deep Dive of LM3 used the same rule to derive the integral form of Taylor's remainder.
LM2 differentiated the illustrative zero-yield curve and obtained the forward rate . Written as a function of , the forward curve is . Integrate it from 0 to , show that the result equals , and compute the discount factors for , 5 and 10.
Split the integral: . The first integral is . For the second, (5.6) with and gives .
Collecting terms, and cancel, leaving .
| 1 | 0.401624 | 0.0142677 | 1.42677% | 0.985834 |
| 5 | 4.466986 | 0.0924450 | 1.84890% | 0.911699 |
| 10 | 7.608714 | 0.1971461 | 1.97146% | 0.821071 |
The yields match LM2's table. Differentiating took LM2 one product rule; undoing it takes one integration by parts. The yield is the average forward rate, as (5.3) says.
Drop the in (5.5) and the “probability” of the whole real line becomes , 0.012 for 0050. Substitute but keep the old limit , and you compute instead of . In a definite integral the limits are values of the integration variable, so they change with it.
變數變換是連鎖律倒過來:把內層函數叫做 , 換成 ,上下限也要跟著換成 的值。最重要的例子是標準化 :任何常態機率都變成同一個函數 的差,而 這個因子確保面積不變。分部積分是乘積律倒過來,適合「一個因子微分後變簡單、另一個因子容易積分」的情形,例如 。把 LM2 的遠期利率曲線用分部積分積回去,就得到原本的殖利率曲線:殖利率就是遠期利率的平均。
Show that under the normal model , and evaluate it for with the case's parameters.
Answer
. Because is symmetric, the area right of equals the area left of . Once Section 5 shows that the total area is 1, this gives . With , : 0.106 expected days, against 6 in the data (Practice Problem 15).
5Improper Integrals and the Gaussian Integral
Tail probabilities, perpetuities and moments integrate over unbounded intervals. Definition (5.1) needs a bounded interval and a bounded integrand, so we extend it with a limit.
If is integrable on for every , then . The integral converges if the limit exists and is finite, and diverges otherwise; is defined in the same way. If is unbounded near , then . A two-sided integral converges if and both converge, and its value is their sum.
Power functions are the benchmark.
converges if and only if , and then equals . converges if and only if .
Proof. For , , which tends to if and to if . For the integral is . The second statement follows in the same way from as .
So is the dividing line: , but , although both integrands go to zero. Exponentials decay faster than any power. For , , the value of a perpetuity paying 1 a year (Section 6).
If for and converges, then converges. If diverges, so does .
The reason: never decreases as grows and never exceeds . A non-decreasing bounded function has a finite limit, a property of the real numbers that we state without proof.
The Gaussian integral
The bell curve has no elementary antiderivative, yet its total area is known exactly. It is finite: gives , so , whose integral over each half-line converges.
Deep DiveProof of the Gaussian integral with polar coordinatesoptional · click to expand
Here are Cartesian coordinates and polar ones, a point's distance from the origin and its angle. Let ; we need .
Step 1 (from a square to a double integral). . A double integral is the limit of Riemann sums over small rectangles. For a continuous function on a rectangle it equals either iterated integral (Fubini's theorem, stated without proof; Stewart, Clegg and Watson 2021). Here the integrand factorizes as , so the iterated integral is the product of the two one-dimensional integrals.
Step 2 (polar coordinates on a disc). The region between radii and and angles and is nearly a rectangle with sides and . Its area is therefore , with an error of order that vanishes in the limit. The integrand depends on only, through . On the disc of radius , using the substitution of Section 4,
Step 3 (squeeze). The disc of radius lies inside the square , which lies inside the disc of radius . The integrand is positive, so
The factor in the polar area element is what makes the problem solvable: has an elementary antiderivative, while does not.
Two consequences carry the rest of the module. First, has total area 1, so ; by symmetry and . Second, by (5.5) every normal density has total area 1.
Moments of the normal. For every the function is bounded, because exponentials beat powers. So is at most a constant times , and every moment converges by comparison. Odd moments vanish by symmetry. For the second moment, (5.6) with and , so that by Section 4, gives
So has mean 0 and variance 1. By (5.5), the density has mean and variance , which is why fitting a normal means matching the sample mean and standard deviation.
Tails that make moments infinite
The normal tail falls like , faster than any power, so every moment is finite. A density whose tail falls only like a power behaves differently. The Pareto density with tail index ,
integrates to 1 by the power test. Its -th moment is , which by the power test converges if and only if , with value . By comparison, any density whose tail behaves like a constant times obeys the same rule. The Student-t density with degrees of freedom, proportional to , has tails like , so its moments exist only below order .
| Density, up to a constant | Tail falls like | Mean | Variance | Kurtosis |
|---|---|---|---|---|
| Normal, | finite | finite | finite (3) | |
| Laplace, | finite | finite | finite (6) | |
| Student-t, | finite | finite | finite (9) | |
| Student-t, | finite | finite | infinite | |
| Pareto, | finite | finite | infinite | |
| Pareto, | finite | infinite | does not exist (infinite variance) | |
| Cauchy (Student-t, ) | does not exist | does not exist | does not exist |
Exhibit 4 lists which moments converge, and empirical work places market returns in its middle rows. Mandelbrot (1963) modelled cotton price changes with stable distributions, whose variance is infinite; Cont (2001) instead puts the tail index of most return series between 2 and 5. Gopikrishnan et al. (1999) estimate for index returns, and Gabaix et al. (2003) propose a mechanism. With the variance is finite, the fourth moment is infinite and the third sits on the borderline.
Suppose that on days at or below a threshold the ratio follows a Pareto law with : density for . Here is an illustrative assumption taken from the studies above.
Compute , and the variance. Show that and are infinite through their integrals up to , 100 and 1,000. Then compare the implied mean return beyond with 0050's data and with the normal model.
, and .
For , : 6.908, 13.816 and 20.723 for , 100 and 1,000. The integral diverges, slowly. For , : 27, 297 and 2,997. It diverges fast.
The model's mean return on days beyond is , or −4.50% for . On 0050 the 37 days at or below −3% averaged −4.42%, while the normal model's value from (5.11) in Section 7 is −3.40%. At this threshold the power tail describes the data far better than the normal.
At the Pareto value, −7.50%, is deeper than the data's −6.54%. Nine days are a small sample, and the daily price limit caps moves at 10%. The Taiwan Stock Exchange raised that limit from 7% to 10% on 1 June 2015.
Excess kurtosis is kurtosis minus 3, zero for the normal; the sample version uses and (LM19). 0050's sample excess kurtosis over the 2,902 days is 8.12. Without the single day of 7 April 2025 it is 7.05; without the four largest moves, two down and two up, it is 3.85. On the eve of 7 April 2025 the estimate stood at 5.84, and that one day lifted it to 7.63.
The ten largest of the 2,902 terms supply 62.8% of but only 14.1% of . If the tail index is near 3, the population fourth moment is a divergent integral and no sample is long enough for its estimate to settle. Quote a kurtosis together with its sample period, and prefer tail measures that need fewer moments (LM15, LM37).
積分區間延伸到無窮遠時用極限來定義,極限存在而且有限才叫收斂。判斷的基準是冪函數: 只有在 時有限,而指數函數衰減得比任何冪函數都快。常態分配的尾巴是 ,所以各階動差都存在;尾巴若只像 那樣以冪次衰減(厚尾),就只有低於 階的動差存在。文獻估計指數報酬的 :變異數存在,四階動差(峰態)卻是無窮大,樣本峰態因此永遠穩定不下來。0050 光是 2025/4/7 一天,就讓樣本超額峰態從 5.84 跳到 7.63。
A Student-t density with is symmetric about 0. Which of its mean, variance, third moment and kurtosis exist? Is its third moment zero by symmetry?
Answer
Moments exist below order 3, so the mean (0) and the variance exist and the kurtosis is infinite. The third moment does not exist: diverges like . That for every does not help. The two half-line integrals are and , and a two-sided integral exists only if both halves converge.
6Continuous Discounting and Continuous Cash Flows
Section 3's accumulation formula has a mirror image: discounting a stream of cash flows. Discrete payments form geometric series, which LM6 sums. Here payments arrive continuously, or so often that a continuous stream is the simpler model.
A stream pays at the rate NT$ per year. Over a short interval it pays about , worth today at a continuously compounded rate . Summing over a partition of gives a Riemann sum, and in the limit
With a moving rate, replace by the discount factor of (5.3).
| Stream on | Present value | Condition |
|---|---|---|
| lump sum of 1 paid at | — | |
| level, per year | ||
| level forever | ||
| growing, | ; if | |
| growing forever | ; diverges if | |
| any , moving rate | , from (5.3) | — |
A property pays NT$30,000 a month for 20 years. Discount at 2% a year, continuously compounded (an illustrative rate). Value the rent (a) paid at the end of each month, (b) paid at the start of each month, (c) paid in mid-month, and (d) modelled as a continuous stream of NT$360,000 a year.
(d) By Exhibit 5, NT$5,934,239.
(a)–(c) are sums of 240 terms over the payment dates , geometric series that LM6 sums in closed form. Payment in arrears is worth NT$5,929,295, in advance NT$5,939,186 and in mid-month NT$5,934,238.
Each discrete stream is a Riemann sum of the integral (5.8) with . Payment in arrears is the right-endpoint rule, in advance the left-endpoint rule and mid-month the midpoint rule. The one-sided sums miss the integral by −NT$4,944 and +NT$4,947 (sum minus integral), about , the leading error. The mid-month stream falls short by less than NT$1 (NT$0.69), an error.
A continuous stream approximates frequent payments well only if you know where the payments sit. Rent paid in advance is worth 0.167% more than rent paid in arrears.
Duration of a stream
The present-value-weighted average date of a stream is its Macaulay duration,
For a level stream the numerator is times Section 4's time-weighted integral, so
As , : a perpetuity discounted at 2.5% has a duration of 40 years. Differentiating under the integral sign gives , so . This step is permitted because the integrand and its derivative in are continuous on (stated without proof). Under continuous compounding, modified and Macaulay duration coincide; with annual compounding they differ by the factor of LM2.
The formulas of Exhibit 5 need a continuously compounded rate. Convert an effective annual rate first (LM1): an effective 2% is a continuously compounded . Plugging 2% straight in values Example 6's stream at NT$5,934,239 instead of NT$5,945,187. The NT$10,948 error exceeds the whole gap, about NT$9,900, between rent in advance and rent in arrears.
每一小段時間 收到 ,折現後加總就是黎曼和,取極限就是 。反過來看,每月付款的年金就是這個積分的黎曼和:月底付(後付)是右端點法,月初付(預付)是左端點法,誤差都約是 ;月中付是中點法,誤差只有 ,20 年的租金差不到新台幣 1 元。存續期間是以現值加權的平均時間,連續複利下它剛好等於 ,所以修正存續期間與麥考利存續期間相同。成長型永續年金收斂的條件 ,就是瑕積分收斂的條件。
Compute the duration of the continuous stream in Example 6 (, ). Why is it below 10 years?
Answer
years. An undiscounted level stream would have its average date at the midpoint, 10 years; discounting gives early payments more weight and pulls the average forward.
7Densities and Expectations
A risk model assigns probabilities to ranges of returns. When a return can take any value in a range, each single value has probability zero. Probability is then spread along the axis with a density, as interest was spread along the time axis in Section 2: probabilities become areas, and averages become integrals. This section defines only what the case needs; LM13 and LM14 build probability theory properly.
A probability density is a function with . A quantity has density if for all . Its distribution function is , and a median of is a value with . For a function with , the expectation of is
By the fundamental theorem, wherever is continuous: the density is the rate at which probability accumulates. Definition (5.9) is the limit of the probability-weighted averages , which are Riemann sums. Linearity of the integral makes expectation linear, . When the integral in (5.9) diverges, the expectation does not exist, as for the heavy tails of Section 5.
The case's normal model is , with density , mean and variance (Section 5). Fitting it to 0050 sets and , the sample mean and population standard deviation; LM20 shows that this is the maximum-likelihood choice.
Bracketing a normal tail by parts
has no formula, but integration by parts brackets it. For let , which equals by symmetry. Write and apply (5.6) with and , using :
The remaining integral is positive, so . The same step applied to that integral, with , gives . Together,
The two bounds differ by the relative amount , so for large the tail is , with a relative error below . Gordon (1941) sharpened the lower bound to . The ratio is called Mills' ratio. The normal tail shrinks like , so each extra standard deviation divides it by a factor that itself keeps growing.
Use (5.10) to bracket under the case's normal model and compare the bracket with the exact value. Convert the probability into an expected number of days in the sample and a return period in years.
From Example 3, with . The density there is . Dividing by gives the upper bound ; multiplying that by gives the lower bound . The exact value, computed in Section 8, is : the upper bound is 5.4% high and the lower bound 0.9% low.
Over days the model expects days. At trading days a year it predicts one such day every years. The data contain 9, one every 1.33 years: 155 times the model's count. The integral is right; the density is wrong.
Exhibit 6 repeats the comparison at every whole-percent threshold, and Exhibit 7 draws it on a logarithmic axis.
| Threshold | Normal | Normal: expected days | Actual days | Actual ÷ expected | Student-t, : expected days | |
|---|---|---|---|---|---|---|
| −2% | −1.685 | 133.4 | 104 | 0.78 | 89.3 | |
| −3% | −2.493 | 18.4 | 37 | 2.01 | 33.2 | |
| −4% | −3.300 | 1.40 | 18 | 12.8 | 15.4 | |
| −5% | −4.107 | 0.058 | 9 | 155 | 8.3 | |
| −6% | −4.915 | 0.0013 | 3 | 2,327 | 4.9 | |
| −7% | −5.722 | 3 | 3.2 | |||
| −8% | −6.530 | 2 | 2.2 | |||
| −9% | −7.337 | 2 | 1.5 | |||
| −10% | −8.145 | 1 | 1.1 |
Three features stand out. First, the gap grows explosively with the threshold: the data exceed the model 2.0 times at −3%, 12.8 times at −4% and 155 times at −5%. At −7% three actual days face an expectation of 0.000015.
Second, the model over-predicts moderate losses: 133 days at or below −2% against 104. With Example 3, this gives the data more mass near zero and in the far tails, and less in the shoulders. That is the shape of high kurtosis (Section 5).
Third, a density with a power tail tracks the data. The Student-t with and the same standard deviation expects 89.3, 33.2, 15.4 and 8.3 days at −2% to −5%, against 104, 37, 18 and 9. Choosing after seeing the data is illustration, not estimation: LM15 fits tail models and LM20 estimates .
Derive the normal model's mean return on days at or below a threshold , , and evaluate it at for 0050. Compare it with the nine actual days.
Substitute (Section 4), with : . Section 4's antiderivative makes the last integral , since vanishes at . Dividing by :
The nine actual days averaged −6.54%. The normal model misses both how often the tail is reached and how deep the market goes once it is there. The quantity (5.11) is the normal model's conditional tail mean; with set at the value-at-risk level, its negative is the expected shortfall of LM37.
Suppose the annual log growth is normal with mean and variance , so that the growth factor is lognormal. Show that and that the median of is . Evaluate both with 0050's annualized daily log-return moments, and .
By (5.9), . Complete the square in the exponent:
Annualizing the daily log-return mean and variance with gives and . The median is then , or +21.30%, and the mean , or +23.58%. The median matches 0050's realized compound growth of 21.30% a year, because the mean daily log return times is the annualized log growth (LM1). The mean exceeds the median by 2.28 points.
In LM3 the volatility drag was a second-order approximation; for a lognormal the factor between mean and median is exact. The annualization assumes independent daily returns with a constant , which this section has just questioned. LM29 derives the same result for geometric Brownian motion.
“A 4-sigma day” means a probability of only under a normal model: about once in 130 years of 243.1 trading days. In August 2007 Goldman Sachs's finance chief said: “We were seeing things that were 25-standard deviation moves, several days in a row” (Financial Times, 13 August 2007; quoted by Dowd et al. 2008). Under normality a 25-sigma day has a probability of about . When an “impossible” day recurs, the lesson is that the model's tail is wrong, not that the market was unlucky.
To make the normal model expect 9 days at or below −5%, must rise to 1.859% a day, 29.0% a year. The same model then expects 379 days at or below −2% (actual 104) and 140 at or below −3% (actual 37). A one-parameter fix moves the whole bell; the data need a different shape. Part of that shape comes from volatility that changes over time (LM26): two of the nine days fell in early 2020, and three in under four months of 2024.
機率密度是「機率沿著報酬軸分布的速率」,區間機率是面積,期望值是加權積分。用 0050 的平均數與標準差配一條常態曲線,−5% 以下的面積只有 :12 年預期 0.058 天,約 206 年一次;實際上有 9 天,是模型的 155 倍,而且這幾天平均跌 6.54%,模型只預期 5.27%。問題不在積分算錯,而在密度的形狀:常態尾巴以 衰減,真實報酬的尾巴比較像冪次衰減,中間也更尖、肩部更少。把 調大救不了:讓 −5% 符合 9 天,−2% 以下就會多估成 379 天。「幾個標準差」的說法只在常態模型下有意義,尾端需要自己的模型(LM15)。
In Example 2, rose 10% to 1.3624%. How many days at or below −5% would that normal model expect in 2,902 days? Does the change close the gap?
Answer
and , so days: 4.7 times more than before, but still 33 times short of the 9 observed days. The fragility of Example 2 is real, yet no plausible error in explains the data.
8Numerical Integration
scipy.integrateLiouville's theorem rules out a formula for , and integrands defined by data or by other models rarely have one either. A numerical rule replaces the integral by a weighted sum of function values. Its quality lies in its error order: how fast the error falls as the grid is refined.
Three rules
On panels of width , with :
- Midpoint: , the height at each panel's midpoint .
- Trapezoid: , the area under each panel's chord.
- Simpson ( even): , a parabola through each pair of panels.
Error orders from Taylor expansions
Take one panel with midpoint , from to , and expand about (LM3): . Integrating over the panel, the odd powers of cancel:
The midpoint rule takes , so its panel error, exact minus rule, is . The trapezoid rule takes , so its panel error is . Summed over the panels, is a midpoint sum for , so for with continuous derivatives up to order four on
with neglected terms of order . Both rules are : halving divides the error by 4. For with a continuous second derivative on , the exact statement for some is stated without proof (Burden, Faires and Burden 2016, chapter 4).
The two errors in (5.13) have opposite signs and a 2 : 1 ratio, so cancels the term. That combination is Simpson's rule on the half-panels: since , . Removing a known leading error term in this way is called Richardson extrapolation. What remains is fourth order: for with a continuous fourth derivative on ,
stated without proof (Burden, Faires and Burden 2016); the Deep Dive derives its leading term. Simpson's rule is therefore : halving divides the error by 16, and the rule is exact for cubic polynomials. Orders bound the worst case. Over the whole real line the trapezoid rule for overshoots by only at , because all its endpoint derivatives vanish at .
Deep DiveThe leading error term of Simpson's ruleoptional · click to expand
Take a double panel and expand about its midpoint to fourth order. Integrating over the double panel kills the odd powers of :
Compute numerically for the case's . Truncate the lower limit at −12 and bound the truncation error with (5.10). Then apply the trapezoid and Simpson rules with panels and measure the error ratios.
By (5.10) the part below −12 is ; its actual value, , is negligible. Exhibit 8 lists the errors against the exact value .
The scale on which changes near −4.1 is about . Once is small against it, the trapezoid ratios settle at 4.00 and Simpson's at 16.0: the and of (5.13) and (5.14). At , . With and , (5.13) predicts (rule minus exact, as in Exhibit 8), against observed.
With 256 panels the trapezoid rule is still 0.14% high, while Simpson's rule is within a relative . On coarse grids neither order is visible: with 16 panels the trapezoid rule is 34% high. As a check on Richardson extrapolation, .
| Panels | Width | Trapezoid error | Ratio | Simpson error | Ratio |
|---|---|---|---|---|---|
| 8 | 0.9866 | + | — | + | — |
| 16 | 0.4933 | + | 3.46 | + | 7.88 |
| 32 | 0.2466 | + | 3.84 | + | 12.99 |
| 64 | 0.1233 | + | 3.96 | + | 15.19 |
| 128 | 0.0617 | + | 3.99 | + | 15.80 |
| 256 | 0.0308 | + | 4.00 | + | 15.95 |
| 512 | 0.0154 | + | 4.00 | + | 15.99 |
| 1,024 | 0.0077 | + | 4.00 | + | 16.00 |
Adaptive quadrature
Production code adapts the grid to the integrand. scipy.integrate.quad uses the QUADPACK algorithms (Piessens et al. 1983). On a finite interval it applies a 21-point Gauss–Kronrod rule within subintervals and subdivides adaptively; an infinite range is first mapped onto a finite interval (SciPy documentation). With the case's unrounded , quad(phi, -inf, z) returns with an error estimate of , within a relative of the value obtained from the complementary error function.
At the observed ratios in Exhibit 8 are 3.46 and 7.88, not 4 and 16. The orders describe the limit , and they appear only once the grid resolves the integrand. Always check by halving : the ratio of successive errors estimates the order and the size of the remaining error, and without an exact value successive differences do the same. A tail integral on a coarse grid can be wrong by a third without any warning.
常態密度函數沒有初等的反導函數,所以 沒有公式,尾端機率一定要用數值方法計算。梯形法用弦取代曲線,中點法取每格中點的高度,兩者誤差都是 ,而且符號相反、大小比 2:1,所以 會把 項消掉,得到 的辛普森法,這就是理查森外插。檢查方法很簡單:格寬每減半一次,梯形法誤差應縮小 4 倍、辛普森法 16 倍;比例不對,代表格子還太粗、尚未進入漸近區。實務上可以直接用 scipy.integrate.quad 的自適應積分。
Simpson's rule with has an error of on a smooth integrand, and the grid is already in the asymptotic regime. Estimate the error with , and the number of panels needed for an error of .
Answer
Two halvings divide the error by : about at . Reaching needs a further factor of 125, so and ; take , since Simpson's rule needs an even number of panels.
9Integration in Python
scipy.integrateThree habits make numerical integrals trustworthy. Compute a known case alongside the unknown one, halve the step and watch the ratio, and keep data and model in separate, testable functions. quad also integrates (5.8) directly when or has no closed form; the lab values Example 6's stream that way.
import math
import numpy as np
from scipy import integrate, special
def trapezoid(f, a, b, N): # N panels; error O(dx^2), eq. (5.13)
x = np.linspace(a, b, N + 1); y = f(x); dx = (b - a) / N
return dx * (y.sum() - 0.5 * (y[0] + y[-1]))
def simpson(f, a, b, N): # N even; error O(dx^4), eq. (5.14)
x = np.linspace(a, b, N + 1); y = f(x); dx = (b - a) / N
return dx / 3 * (y[0] + y[-1] + 4 * y[1:-1:2].sum() + 2 * y[2:-1:2].sum())
phi = lambda t: np.exp(-0.5 * t * t) / math.sqrt(2 * math.pi)
z = -4.1074386 # (kappa - mu_hat) / s at -5%
exact = 0.5 * special.erfc(-z / math.sqrt(2)) # Phi(z) = 2.000355e-05
for N in (64, 128, 256):
print(N, f"{trapezoid(phi, -12, z, N) - exact:.2e}",
f"{simpson(phi, -12, z, N) - exact:.2e}")
# 64 4.49e-07 6.23e-09 / 128 1.13e-07 3.94e-10 / 256 2.82e-08 2.47e-11
print("%.6e %.1e" % integrate.quad(phi, -np.inf, z)) # 2.000355e-05 2.2e-10
The data side takes a few lines of Polars, run in labs/LM05_lab. The fitted normal and the count of actual days come from the same series, so Exhibit 6 cannot drift out of sync.
import polars as pl
from scipy import stats
px = pl.read_csv("data/0050_daily_raw.csv")
dv = pl.read_csv("data/0050_dividends.csv").select("date", D="cash_dividend")
days = pl.read_csv("data/00631L_daily_raw.csv").select("date")
c, d = pl.col("close"), pl.col("D").fill_null(0.0)
split = pl.when(pl.col("date") == pl.lit("2025-06-18")).then(4.0).otherwise(1.0)
ret = (px.join(days, on="date", how="semi").join(dv, on="date", how="left")
.sort("date").with_columns(R=(c + d) / (c.shift(1) / split) - 1)
.drop_nulls("R"))
mu, s, n = ret["R"].mean(), ret["R"].std(ddof=0), ret.height # n = 2,902
for kappa in (-0.03, -0.04, -0.05):
model = n * stats.norm.cdf((kappa - mu) / s)
# Two-decimal prices make limit moves and round returns exact ties.
hits = ret.filter(pl.col("R") <= kappa + 1e-12).height # float guard
print(f"{kappa:+.0%} normal {model:.3f} actual {hits}")
# -3% normal 18.400 actual 37 / -4% normal 1.403 actual 18
# -5% normal 0.058 actual 9
The notebook LM05_lab.ipynb rebuilds the module's computations from the verified FinMind price files. It measures the error orders of Riemann, trapezoid and Simpson sums (Example 1, Exhibit 8). It fits the normal model against 0050's tails (Exhibit 1, Exhibit 6, Exhibit 7), computes the tail means, the lognormal mean and the rent of Example 6, and solves the computational practice problems. It is Polars-first and checks 115 printed numbers.
The notebook reads FinMind files that you download once with your own token. From the repository root, run uv run python data/fetch_finmind.py, then uv run python data/make_lab_data.py. FinMind's licence does not allow the book to redistribute the data. After that, the notebook runs offline.
Summary
- A definite integral (5.1) is the limit of Riemann sums: accumulated rate times width, or signed area. For monotone integrands the left and right sums err by at most ; the midpoint sum's error is .
- The fundamental theorem of calculus (5.2) evaluates integrals with antiderivatives and gives . Money at a moving rate grows by . Because , 0050's −5% tail probability moves about 18% per 1% change in .
- Substitution (5.4) reduces every normal probability to through ; integration by parts (5.6) handles , recovers a yield curve from its forward curve, and brackets the normal tail (5.10).
- Improper integrals are limits. converges only for ; (5.7). A power tail of index keeps only the moments below order . With kurtosis is infinite, and its sample estimate never settles.
- A continuous stream is worth (5.8). Payments in arrears, in advance and mid-period are right, left and midpoint Riemann sums of that integral. Under continuous compounding, duration equals .
- Probabilities and expectations are integrals of a density (5.9). For 0050 the fitted normal gives , 0.058 expected days against 9 actual, and a tail mean of −5.27% against −6.54%. The lognormal mean is exactly (5.12).
- The trapezoid and midpoint rules are , Simpson's rule (5.13–5.14). Halving the step and checking the error ratio is the practical test; adaptive quadrature in
scipy.integrate.quadhandles infinite ranges.
Practice Problems
-
The present value of a continuous stream paying 1 a year for 10 years, discounted at a continuously compounded 3%, is closest to:
- A.8.51
- B.8.64
- C.10.00
-
Compute the left and right sums and for , the exact value and both errors (sum minus exact). Check the bound , and compare the average of and with (5.13).
-
equals:
- A.
- B.
- C.
-
Use a substitution to evaluate and .
-
Show that the Macaulay duration of a continuous perpetuity discounted at is , and evaluate it at .
-
Which integral converges?
- A.
- B.
- C.
-
A loss multiple has the Pareto density . Compute , and , and state which higher moments are infinite.
-
A model treats daily returns as normal with and . Use (5.10) to bracket and compare the bracket with the exact value. Then use the exact value to compute the expected number of such days per year (243.1 trading days) and the return period in years.
-
Under a normal model, the probability of a day at least four standard deviations below the mean is closest to:
- A.0.0032%
- B.0.0063%
- C.5.9%
-
A continuous cash flow starts at 1 a year and grows at ; discount at , both continuously compounded. Compute its 30-year present value, the value of the same stream forever, and the share of the perpetuity's value received in the first 30 years.
-
Approximate with , and , and report the errors (rule minus exact) against the exact value . Show that .
-
For a smooth integrand in the asymptotic regime, halving the panel width of Simpson's rule divides its error by a factor closest to:
- A.4
- B.8
- C.16
-
Annual log growth is normal with mean 8% and standard deviation 20%. Compute the mean and the median of the growth factor , and .
-
Use (5.11) to find for a standard normal .
-
(Python) With the lab data, count 0050's days with , list their dates, and compare the count with the normal model's expectation.
-
(Python) Keeping , find the for which the normal model expects exactly 9 days at or below −5%. How many days at or below −2% and −3% does that model then expect?
Solutions
-
B is correct. . A, 8.5104, pays 1 at each year-end and discounts at the same continuous rate. It is the right-endpoint Riemann sum of the stream, low by about with . C ignores discounting.
-
With : (error, sum minus exact, ), (error ), exact . Both errors are below in size. The average errs by , close to the overshoot that (5.13) predicts: . Averaging the one-sided sums turns an error into an one.
-
A is correct. By part 1 of the theorem and the chain rule, the derivative is . B forgets the chain rule; C substitutes the wrong argument.
-
With : . As the upper limit grows, , so .
-
Letting in Section 4's result gives , and the perpetuity's value is . Hence : 40 years at 2.5%.
-
C is correct. By the power test, . A has at infinity; B has near zero. Both diverge.
-
With : , and . Moments of order are infinite, so the third moment, skewness (its standardized form, LM19) and kurtosis do not exist.
-
and . Then , the upper bound is and the lower bound . The exact value, , lies inside: the upper bound is 5.6% high and the lower bound 0.9% low. Per year the model expects days, one every 150 years.
-
A is correct: . B is the two-sided probability of a move of four standard deviations in either direction. C is the one-sided Chebyshev (Cantelli) bound of LM14, which holds for every distribution with a finite variance and is far larger.
-
; forever, . The first 30 years deliver of the perpetuity's value; LM6 finds almost the same share, 45%, for a discrete perpetuity at a 2% discount rate.
-
The integrand values are , , , and at . (error, rule minus exact, ), (error , a ratio of 4.03) and (error ). Simpson's weights with equal times the weights minus times the weights , so identically.
-
C is correct. By (5.14) the error is proportional to , and . A is the trapezoid and midpoint factor.
-
Mean ; median ; .
-
With , and , (5.11) gives . The large- approximation overstates the depth by 5%: at the bracket (5.10) is still wide, since .
-
Six days: 2020-03-20 (+7.95%), 2022-11-11 (+5.31%), 2024-08-06 (+5.51%), 2025-04-10 (+9.99%), 2026-04-08 (+5.18%) and 2026-07-31 (+10.00%). The normal model expects days, so the data hold 57 times as many. The normal model fails in the upper tail too.
-
The model needs , so and . It then expects 379 days at or below −2% against 104 actual, and 140 at or below −3% against 37.
Glossary
| Term | 中文 | Meaning |
|---|---|---|
| Riemann sum | 黎曼和 | over a partition; its limit is the integral, (5.1). |
| Definite integral | 定積分 | Limit of Riemann sums; accumulated change or signed area. |
| Antiderivative | 反導函數 | A function with . |
| Fundamental theorem of calculus | 微積分基本定理 | and , (5.2). |
| Substitution | 變數變換 | The chain rule read backwards, (5.4). |
| Integration by parts | 分部積分 | The product rule read backwards, (5.6). |
| Improper integral | 瑕積分(廣義積分) | A limit of integrals, for an unbounded interval or integrand. |
| Gaussian integral | 高斯積分 | , (5.7). |
| Tail index | 尾部指數 | in a power tail ; moments exist below order . |
| Kurtosis | 峰態 | : 3 for the normal, infinite if (undefined if ); excess kurtosis (超額峰態) subtracts 3. |
| Continuous annuity | 連續年金 | Level stream; present value . |
| Duration | 存續期間 | Present-value-weighted average date; under continuous compounding. |
| Probability density | 機率密度函數 | with total area 1; probabilities are areas under it. |
| Distribution function | 累積分配函數 | ; . |
| Expectation | 期望值 | , (5.9). |
| Mills' ratio | 米爾斯比率 | ; bounds in (5.10). |
| Conditional tail mean | 條件尾端平均 | , (5.11); with at the value-at-risk level, minus the expected shortfall (預期短缺) of LM37. |
| Lognormal | 對數常態 | , normal; mean , median , (5.12). |
| Trapezoidal rule | 梯形法 | Chords on each panel; error , (5.13). |
| Simpson's rule | 辛普森法 | Parabolas through panel pairs; error , (5.14). |
| Richardson extrapolation | 理查森外插 | Combining two step sizes to cancel a known leading error term. |
| Adaptive quadrature | 自適應數值積分 | Refining the grid where the estimated error is largest. |
References
- Stewart, J., D. K. Clegg and S. Watson (2021). Calculus: Early Transcendentals, 9th ed. Cengage. Chapters on integrals, techniques of integration, improper integrals and multiple integrals.
- Burden, R. L., J. D. Faires and A. M. Burden (2016). Numerical Analysis, 10th ed. Boston: Cengage Learning. Chapter 4, numerical integration.
- Rosenlicht, M. (1972). “Integration in Finite Terms.” American Mathematical Monthly 79 (9): 963–972.
- Gordon, R. D. (1941). “Values of Mills' Ratio of Area to Bounding Ordinate and of the Normal Probability Integral for Large Values of the Argument.” Annals of Mathematical Statistics 12 (3): 364–366.
- Mandelbrot, B. (1963). “The Variation of Certain Speculative Prices.” Journal of Business 36 (4): 394–419.
- Gopikrishnan, P., V. Plerou, L. A. N. Amaral, M. Meyer and H. E. Stanley (1999). “Scaling of the Distribution of Fluctuations of Financial Market Indices.” Physical Review E 60 (5): 5305–5316.
- Gabaix, X., P. Gopikrishnan, V. Plerou and H. E. Stanley (2003). “A Theory of Power-Law Distributions in Financial Market Fluctuations.” Nature 423 (6937): 267–270.
- Cont, R. (2001). “Empirical Properties of Asset Returns: Stylized Facts and Statistical Issues.” Quantitative Finance 1 (2): 223–236.
- Dowd, K., J. Cotter, C. Humphrey and M. Woods (2008). “How Unlucky Is 25-Sigma?” Journal of Portfolio Management 34 (4): 76–80.
- NIST/SEMATECH. e-Handbook of Statistical Methods, gallery of distributions, section 1.3.6.6: normal, t and double exponential (Laplace) kurtosis. Accessed 11 October 2026.
- Piessens, R., E. de Doncker-Kapenga, C. W. Überhuber and D. K. Kahaner (1983). QUADPACK: A Subroutine Package for Automatic Integration. Springer-Verlag.
- Virtanen, P., et al. (2020). “SciPy 1.0: Fundamental Algorithms for Scientific Computing in Python.” Nature Methods 17 (3): 261–272. Documentation of
scipy.integrate.quad, version 1.18. - Taiwan Stock Exchange. Company history: “Jun 1, 2015: The daily price fluctuation limit is raised from 7% to 10%.” Accessed 10 October 2026.
- FinMind open data:
TaiwanStockPriceandTaiwanStockDividendResult(0050), retrieved 10 October 2026.