量化金融 · 第 18 册 · 职业发展

Interviews I: Maths, Probability and Speed

本书暂未推出简体中文版。现有版本:English, Français。

Interviews I: Maths, Probability and Speed · 职业发展

20Calculus and Optimisation

Calculating with a clear head: integrals by symmetry, Lagrange multipliers, convexity, gradient and Newton steps, Stirling’s formula, and the places where floating-point arithmetic gives wrong answers. The questions want a short route, and a check that the result is the right size.

Question 20.1 ★ QR, QT, Trader, Analyst • any • junior

Where does xxx^x reach its minimum for x>0x > 0, and what is the minimum? Without a calculator, which is larger: eπe^\pi or πe\pi^e? Prove it with a single function.

Answer

Answer to Question 20.1.

The minimum is at x=1/ex = 1/e, with value e−1/e≈0.692e^{-1/e} \approx 0.692, and eπe^\pi is the larger.

Write xx=exln⁡xx^x = e^{x\ln x}. The derivative of xln⁡xx\ln x is ln⁡x+1\ln x + 1, which vanishes at x=1/ex = 1/e. As x→0x \to 0 the function tends to 1, and it rises again beyond 1/e1/e, so this point is the minimum.

For the comparison, use g(x)=ln⁡x/xg(x) = \ln x / x. Its derivative (1−ln⁡x)/x2(1 - \ln x)/x^2 is positive below ee and negative above, so gg peaks at ee. Hence ln⁡π/π<1/e\ln\pi/\pi < 1/e, which rearranges to eln⁡π<πe\ln\pi < \pi, that is, πe<eπ\pi^e < e^\pi. The values are about 22.4622.46 and 23.1423.14, close, which is why a guess is unsafe.

Classic wrong answer. Comparing the two with rough decimals in the head. The gap is only 3%, so a rough estimate can go either way. The peak of ln⁡x/x\ln x / x settles it with no arithmetic.

Follow-up. Which is larger: 9910099^{100} or 10099100^{99}? 9910099^{100}. Past ee the function ln⁡x/x\ln x / x falls, so ln⁡99/99>ln⁡100/100\ln 99/99 > \ln 100/100, which rearranges to 100ln⁡99>99ln⁡100100\ln 99 > 99\ln 100.

Why it matters. Whether a one-line function can replace a computation. Reducing a comparison of powers to one function’s shape is the habit being checked.

Question 20.2 ★ QR, QT, DS, QD • any • junior

Compute ∫−∞∞e−x2 dx\int_{-\infty}^{\infty} e^{-x^2}\,dx by squaring it and using polar coordinates. Use the result to find the normal density’s constant, and the mean of ∣Z∣|Z| for a standard normal ZZ.

Answer

Answer to Question 20.2.

The integral is π\sqrt{\pi}, the normal density’s constant is 1/2π1/\sqrt{2\pi}, and E∣Z∣=2/π≈0.798\mathbb{E}|Z| = \sqrt{2/\pi} \approx 0.798.

Let II be the integral. Then

I2=∬e−x2−y2 dx dy=∫02π ⁣ ⁣∫0∞e−r2r dr dθ=2π⋅12=π.I^2 = \iint e^{-x^2 - y^2}\,dx\,dy = \int_0^{2\pi}\!\!\int_0^\infty e^{-r^2} r\,dr\,d\theta = 2\pi \cdot \tfrac12 = \pi.

The factor rr from the change of coordinates is what makes the inner integral exact.

Substituting x=t/2x = t/\sqrt{2} gives ∫e−t2/2 dt=2π\int e^{-t^2/2}\,dt = \sqrt{2\pi}, so the density needs the constant 1/2π1/\sqrt{2\pi}.

Finally, by symmetry,

E∣Z∣=22π∫0∞ze−z2/2 dz=22π=2π.\mathbb{E}|Z| = \frac{2}{\sqrt{2\pi}}\int_0^\infty z e^{-z^2/2}\,dz = \frac{2}{\sqrt{2\pi}} = \sqrt{\frac{2}{\pi}}.

That is below 1, as it must be, since E∣Z∣≤EZ2=1\mathbb{E}|Z| \le \sqrt{\mathbb{E}Z^2} = 1.

Classic wrong answer. Forgetting the factor rr, which leaves an integral with no closed form. Or giving E∣Z∣=1\mathbb{E}|Z| = 1, which confuses the mean absolute value with the standard deviation.

Follow-up. What is ∫0∞x2e−x2 dx\int_0^\infty x^2 e^{-x^2}\,dx? π/4\sqrt{\pi}/4. Integrate by parts with u=xu = x, which leaves half of ∫0∞e−x2 dx=π/2\int_0^\infty e^{-x^2}\,dx = \sqrt{\pi}/2.

Why it matters. Everyone quotes the constant; few can produce it. The ratio 2/π\sqrt{2/\pi} is also a working number, linking the mean absolute deviation and the volatility.

Question 20.3 ★ QR, QT, QD, Dev • any • junior

Use Newton’s method on f(x)=x2−2f(x) = x^2 - 2, starting from x0=1x_0 = 1. Write the update as a simple formula, and give the first three iterates as fractions. How many correct digits does each step add?

Answer

Answer to Question 20.3.

The update is xn+1=12(xn+2/xn)x_{n+1} = \frac12(x_n + 2/x_n), the iterates are 3/23/2, 17/1217/12 and 577/408577/408, and the number of correct digits about doubles at each step.

Newton’s method gives x−(x2−2)/(2x)x - (x^2 - 2)/(2x), which simplifies to the average of xx and 2/x2/x. That is the old idea of averaging a guess that is too high with one that is too low.

From 1: 12(1+2)=3/2\frac12(1 + 2) = 3/2; then 12(3/2+4/3)=17/12\frac12(3/2 + 4/3) = 17/12; then 12(17/12+24/17)=577/408\frac12(17/12 + 24/17) = 577/408.

The errors are about 0.0860.086, 0.00250.0025 and 0.000 0020.000\,002. Each error is about e2/(2x)e^2/(2x), where ee is the one before, so the error is squared at each step, up to a constant of about 0.350.35.

Classic wrong answer. Saying that each step adds a fixed number of digits. That describes bisection and other linear methods. Here the count of correct digits doubles.

Follow-up. How can a machine with no division compute 1/a1/a? Apply Newton to 1/x−a1/x - a, which gives xn+1=xn(2−axn)x_{n+1} = x_n(2 - ax_n), with no division. For a=3a = 3 from 0.30.3, it gives 0.330.33, then 0.33330.3333. The digits double here too.

Why it matters. Whether the iteration has been run by hand once. The doubling of digits is the property worth quoting, and the same argument gives division in hardware.

Question 20.4 ★ QR, QT, Trader, Analyst • any • junior

Estimate ln⁡1.1\ln 1.1, e0.1e^{0.1} and 1.04\sqrt{1.04} to three decimals using only two or three terms of a Taylor series. A zero-coupon bond, paying 1 in 10 years, is priced at e−10ye^{-10y}, where yy is its yield. Using a first-order and a second-order approximation, what is the percentage change in price when the yield rises by one percentage point?

Answer

Answer to Question 20.4.

ln⁡1.1≈0.095\ln 1.1 \approx 0.095, e0.1≈1.105e^{0.1} \approx 1.105, 1.04≈1.020\sqrt{1.04} \approx 1.020, and the bond falls by 10% to first order and 9.5%9.5\% to second order; the exact fall is 9.52%9.52\%.

The three series are ln⁡(1+x)=x−x2/2+x3/3\ln(1 + x) = x - x^2/2 + x^3/3, giving 0.1−0.005+0.000 33=0.09530.1 - 0.005 + 0.000\,33 = 0.0953; ex=1+x+x2/2e^x = 1 + x + x^2/2, giving 1.1051.105; and 1+x=1+x/2−x2/8\sqrt{1 + x} = 1 + x/2 - x^2/8, giving 1+0.02−0.0002=1.01981 + 0.02 - 0.0002 = 1.0198.

Whatever the starting yield yy, the bond’s relative change is e−10 Δy−1≈−10 Δy+12(10 Δy)2e^{-10\,\Delta y} - 1 \approx -10\,\Delta y + \frac12(10\,\Delta y)^2. With Δy=0.01\Delta y = 0.01, the terms are −10%-10\% and +0.5%+0.5\%. The first is the duration and the second the convexity. The convexity term is positive whichever way rates move, which is why a large move always leaves the holder better off than the duration estimate says.

Classic wrong answer. Dropping the convexity term and calling −10%-10\% exact. It is half a percent off at this size. For a two-point move the gap quadruples to two percent.

Follow-up. Why does the rule of 72 use 72, when ln⁡2=0.693\ln 2 = 0.693 suggests 69? Since ln⁡(1+r)≈r−r2/2\ln(1 + r) \approx r - r^2/2 is below rr, the true number rises with the rate, and 72 fits near 8%, where doubling takes 9.019.01 years. It also divides easily.

Why it matters. Taylor series to two terms is a daily tool of the desk. A candidate who can carry it out quickly can also check any pricer.

Question 20.5 ★★ QR, QT, Trader • any • junior

Compute ∫0π/2sin⁡nxsin⁡nx+cos⁡nx dx\int_0^{\pi/2} \frac{\sin^n x}{\sin^n x + \cos^n x}\,dx for any positive nn. Then compute ∫01ln⁡(1+x)1+x2 dx\int_0^1 \frac{\ln(1 + x)}{1 + x^2}\,dx, using a similar trick after the substitution x=tan⁡θx = \tan\theta.

Answer

Answer to Question 20.5.

The first integral is π/4\pi/4 for every nn, and the second is π8ln⁡2≈0.272\frac{\pi}{8}\ln 2 \approx 0.272.

For the first, substitute x→π/2−xx \to \pi/2 - x, which swaps sine and cosine. Adding the two forms of the integral, the integrand becomes 1, so 2I=π/22I = \pi/2. The exponent plays no part, and that is the point.

For the second, x=tan⁡θx = \tan\theta cancels the denominator and gives

I=∫0π/4ln⁡(1+tan⁡θ) dθ.I = \int_0^{\pi/4}\ln(1 + \tan\theta)\,d\theta.

Now substitute θ→π/4−θ\theta \to \pi/4 - \theta. The tangent subtraction formula gives 1+tan⁡(π/4−θ)=2/(1+tan⁡θ)1 + \tan(\pi/4 - \theta) = 2/(1 + \tan\theta). So

I=∫0π/4(ln⁡2−ln⁡(1+tan⁡θ)) dθ=π4ln⁡2−I,I = \int_0^{\pi/4}\bigl(\ln 2 - \ln(1 + \tan\theta)\bigr)\,d\theta = \frac{\pi}{4}\ln 2 - I,

which gives I=π8ln⁡2I = \frac{\pi}{8}\ln 2.

A size check: the integrand rises from 0 to 12ln⁡2≈0.35\frac12\ln 2 \approx 0.35 across an interval of length 1, so a value near 0.270.27 is plausible.

Classic wrong answer. Trying to find an antiderivative. Neither integral has a useful one. The substitution that maps the interval to itself is the only short route.

Follow-up. Compute ∫0πxsin⁡x1+cos⁡2x dx\int_0^\pi \frac{x\sin x}{1 + \cos^2 x}\,dx. π2/4\pi^2/4. Substituting x→π−xx \to \pi - x replaces xx with π/2\pi/2 on average, and what remains is π2∫0πsin⁡x1+cos⁡2x dx=π2⋅π2\frac{\pi}{2}\int_0^\pi \frac{\sin x}{1 + \cos^2 x}\,dx = \frac{\pi}{2}\cdot\frac{\pi}{2}.

Why it matters. Reflection is a trick worth having ready, and an interviewer learns from how long the candidate fights with an antiderivative before looking for it.

Question 20.6 ★★ QR, QT, DS, QD • any • junior

Derive Stirling’s formula for n!n! from n!=∫0∞xne−x dxn! = \int_0^\infty x^n e^{-x}\,dx, by expanding around the peak of the integrand. Use it to approximate (10050)\binom{100}{50}. What is the chance of exactly 50 heads in 100 flips?

Answer

Answer to Question 20.6.

n!≈2πn (n/e)nn! \approx \sqrt{2\pi n}\,(n/e)^n, so (10050)≈1.011×1029\binom{100}{50} \approx 1.011 \times 10^{29}, and the chance of exactly 50 heads is about 0.080.08.

Write the integrand as eh(x)e^{h(x)} with h(x)=nln⁡x−xh(x) = n\ln x - x. The peak is at x=nx = n, where h′′=−n/x2=−1/nh^{\prime\prime} = -n/x^2 = -1/n. Expanding to second order,

n!≈enln⁡n−n∫−∞∞e−(x−n)2/(2n) dx=nne−n2πn,n! \approx e^{n\ln n - n}\int_{-\infty}^{\infty} e^{-(x - n)^2/(2n)}\,dx = n^n e^{-n}\sqrt{2\pi n},

which is the Stirling formula. Extending the range to the whole line costs almost nothing, as the mass sits within a few n\sqrt{n} of nn. The relative error is about 1/(12n)1/(12n), so at n=10n = 10 the formula is already within 1%.

For the middle binomial coefficient, the powers cancel:

(2mm)≈4mπm.\binom{2m}{m} \approx \frac{4^m}{\sqrt{\pi m}}.

With m=50m = 50 this gives 1.011×10291.011 \times 10^{29}, against the true 1.009×10291.009 \times 10^{29}. Dividing by 21002^{100} gives 1/50π=0.07981/\sqrt{50\pi} = 0.0798, against the exact 0.07960.0796.

Classic wrong answer. Forgetting the factor 2πn\sqrt{2\pi n} and using (n/e)n(n/e)^n alone. It is off by a factor of 25 at n=100n = 100, though it is fine for the leading growth rate.

Follow-up. In 1000 flips, what is the chance of an exact tie? 1/500π≈0.0251/\sqrt{500\pi} \approx 0.025. Ten times as many flips reduce the chance of a tie by a factor of 10\sqrt{10}, which many people find surprisingly slow.

Why it matters. The derivation is the template for Laplace’s method, which is the source of many large-deviation and saddle-point estimates.

Question 20.7 ★★ QR, QT, QD • any • junior

Let In=∫0π/2sin⁡nx dxI_n = \int_0^{\pi/2} \sin^n x\,dx. Derive a recursion using integration by parts, and compute I10I_{10} exactly. How close is the large-nn approximation π/(2n)\sqrt{\pi/(2n)}?

Answer

Answer to Question 20.7.

The recursion is In=n−1nIn−2I_n = \frac{n - 1}{n}I_{n - 2}, and I10=63π/512≈0.3866I_{10} = 63\pi/512 \approx 0.3866. The approximation gives 0.39630.3963, 2.5% high.

Integrating by parts with sin⁡n−1x\sin^{n - 1}x and sin⁡x\sin x, the boundary term vanishes and

In=(n−1)∫0π/2sin⁡n−2xcos⁡2x dx=(n−1)(In−2−In).I_n = (n - 1)\int_0^{\pi/2}\sin^{n - 2}x\cos^2 x\,dx = (n - 1)(I_{n - 2} - I_n).

Solving gives the recursion. Starting from I0=π/2I_0 = \pi/2,

I10=π2⋅12⋅34⋅56⋅78⋅910=π2⋅63256.I_{10} = \frac{\pi}{2}\cdot\frac12\cdot\frac34\cdot\frac56\cdot\frac78\cdot\frac{9}{10} = \frac{\pi}{2}\cdot\frac{63}{256}.

For the large-nn form, the recursion shows that nInIn−1nI_nI_{n - 1} does not change with nn, and at n=1n = 1 it equals π/2\pi/2. As In≈In−1I_n \approx I_{n - 1} for large nn, this gives In≈π/(2n)I_n \approx \sqrt{\pi/(2n)}. The gap at n=10n = 10 shrinks to almost nothing if 2n2n is replaced by 2n+12n + 1, which gives π/21=0.3868\sqrt{\pi/21} = 0.3868.

Classic wrong answer. Using the recursion with n/(n−1)n/(n - 1), the wrong way up. That makes the integrals grow, though sin⁡nx\sin^n x falls with nn.

Follow-up. What is the mean of sin⁡10x\sin^{10}x over a full circle, and what else equals it? 63/25663/256, which is 2πI10\frac{2}{\pi}I_{10}. It is also the chance of exactly five heads in ten flips, (105)/210\binom{10}{5}/2^{10}, which is no accident: expanding sin⁡x\sin x in complex exponentials gives that coefficient.

Why it matters. This is the standard reduction formula, and the Wallis limit and the constant in Stirling’s formula both follow from it.

Question 20.8 ★★ QR, QT, Analyst, DS • any • junior

Maximise xyzxyz subject to x+y+z=1x + y + z = 1 with positive variables, by Lagrange multipliers and by another route. Then maximise x+y\sqrt{x} + \sqrt{y} subject to x+y=Bx + y = B. Show for B=2B = 2 that the multiplier equals the change in the best value per unit of BB, and say what this means.

Answer

Answer to Question 20.8.

The first maximum is 1/271/27 at x=y=z=1/3x = y = z = 1/3, and the second is 2B\sqrt{2B} at x=y=B/2x = y = B/2. At B=2B = 2, the multiplier is 12\frac12, which is the marginal value of the budget.

For the first, set the gradient of xyzxyz proportional to that of the constraint: yz=xz=xy=λyz = xz = xy = \lambda. Positive variables then give x=y=zx = y = z. The other route is the inequality of arithmetic and geometric means: (xyz)1/3≤(x+y+z)/3=1/3(xyz)^{1/3} \le (x + y + z)/3 = 1/3, with equality when all are equal.

For the second, 1/(2x)=1/(2y)=λ1/(2\sqrt{x}) = 1/(2\sqrt{y}) = \lambda, so x=y=B/2x = y = B/2, and the value is V(B)=2BV(B) = \sqrt{2B}. At B=2B = 2: x=y=1x = y = 1, V=2V = 2 and λ=12\lambda = \frac12. Separately, V′(B)=1/2B=12V'(B) = 1/\sqrt{2B} = \frac12. The two agree.

That is the general meaning of the multiplier: the rate at which the best value rises with the constraint, or shadow price. It is what the last unit of budget is worth, and so what it makes sense to pay for one more.

Classic wrong answer. Treating the multiplier as a by-product with no meaning. Or stopping at the critical point with no check; here the corner (B,0)(B, 0) gives 2\sqrt{2}, below 2.

Follow-up. The budget rises from 2 to 2.12.1. Estimate the new best value with no re-solving. 2+0.1×0.5=2.052 + 0.1 \times 0.5 = 2.05. The exact value is 4.2=2.0494\sqrt{4.2} = 2.0494. The estimate is slightly high, because VV is concave.

Why it matters. Pricing a constraint is the purpose of the multiplier in practice, from the risk limit to the capital allocation.

Question 20.9 ★★ QR, QT, DS, Analyst • any • junior

Which of these are convex: −ln⁡x-\ln x, x2x^2, ∣x∣|x|, x\sqrt{x}, max⁡(x,y)\max(x, y), xyxy? Give a one-line reason for each. Use Jensen’s inequality to explain why a normal annual return with mean 10% and volatility 20% compounds at a rate below 10%, and estimate that rate.

Answer

Answer to Question 20.9.

Convex: −ln⁡x-\ln x, x2x^2, ∣x∣|x|, max⁡(x,y)\max(x, y). Not convex: x\sqrt{x}, which is concave, and xyxy, which is neither. The compound rate is about 8%8\%.

The reasons, in order. −ln⁡x-\ln x has second derivative 1/x2>01/x^2 > 0. So does x2x^2, with second derivative 2. ∣x∣|x| satisfies the triangle inequality. x\sqrt{x} has a negative second derivative. A maximum of linear functions is always convex. xyxy has Hessian eigenvalues ±1\pm 1, so it curves up along x=yx = y and down along x=−yx = -y.

Now for the return. Compounding takes logs, and ln⁡\ln is concave, so Jensen’s inequality gives Eln⁡(1+R)≤ln⁡(1+ER)\mathbb{E}\ln(1 + R) \le \ln(1 + \mathbb{E}R). Expanding around the mean,

Eln⁡(1+R)≈ln⁡1.1−σ22(1.1)2=0.0953−0.0165=0.079.\mathbb{E}\ln(1 + R) \approx \ln 1.1 - \frac{\sigma^2}{2(1.1)^2} = 0.0953 - 0.0165 = 0.079.

So the log growth is about 7.9%7.9\% to this order. A numerical integral, and a simulation of the normal, give 0.0780.078, which is 8.1%8.1\% a year as a simple rate. The common shortcut μ−σ2/2=8%\mu - \sigma^2/2 = 8\% lands in the same place. With no volatility the formula gives back exactly 10%. A normal return can in principle fall below −100%-100\%, where the log is undefined, but that is 5.55.5 standard deviations away and does not affect the size.

Classic wrong answer. Calling xyxy convex because each variable alone is linear. Being separately linear says nothing about the joint shape, as the saddle shows.

Follow-up. With mean excess return 10% and volatility 20%, what leverage maximises the growth Lμ−L2σ2/2L\mu - L^2\sigma^2/2? L=μ/σ2=2.5L = \mu/\sigma^2 = 2.5, which gives growth of 0.1250.125. At twice this leverage the growth falls to zero.

Why it matters. Volatility drag is a direct cost in any compounding strategy, and the concavity of the log is the entire explanation.

Question 20.10 ★★ QR, DS, QD • any • junior

Gradient descent minimises 12x⊤Ax\frac12 x^\top Ax with AA having eigenvalues 1 and 100. What step sizes converge, and what is the best one? How many steps does it take to reduce the error by a factor of 10610^6? What does Newton’s method do on this function, and what does heavy-ball momentum do?

Answer

Answer to Question 20.10.

Converging steps are 0<α<0.020 < \alpha < 0.02; the best is α=2/101\alpha = 2/101; it needs about 691 steps; Newton finishes in one; and heavy-ball momentum needs about 93.

In the eigenbasis the coordinates decouple, and each is multiplied by 1−αλ1 - \alpha\lambda per step. To converge, every factor must be below 1 in size, and the largest eigenvalue gives α<2/100\alpha < 2/100.

The best step balances the two factors: 1−α=−(1−100α)1 - \alpha = -(1 - 100\alpha), so α=2/101\alpha = 2/101. Both factors then have size 99/101=0.980299/101 = 0.9802. To reduce the error by 10610^6 takes ln⁡106/(−ln⁡0.9802)≈691\ln 10^6 / (-\ln 0.9802) \approx 691 steps, confirmed by running it. A step just over 0.020.02 makes the second coordinate grow without limit.

The number that matters is the condition number κ=100\kappa = 100; the step count is about κ2ln⁡106\frac{\kappa}{2}\ln 10^6.

Newton multiplies the gradient by A−1A^{-1}, which lands on the minimum at once for any quadratic. Heavy-ball momentum, tuned with α=4/121\alpha = 4/121 and β=(9/11)2\beta = (9/11)^2, has rate (κ−1)/(κ+1)=9/11(\sqrt{\kappa} - 1)/(\sqrt{\kappa} + 1) = 9/11. That rate suggests 69 steps, but the tuned recursion has a repeated root, which adds a factor growing with the step count, and a run takes 93.

Classic wrong answer. Choosing α\alpha from the smallest eigenvalue, say α=1\alpha = 1. That is excellent for the flat direction, and it diverges at once in the steep one.

Follow-up. What does conjugate gradient do on this function? It finishes in two steps, one for each distinct eigenvalue, in exact arithmetic. A direct run confirms it, with no tuning needed and only matrix products required.

Why it matters. Why learning rates must be tuned, and why ill conditioning rather than the dimension sets the cost, are the first lessons of optimisation.

Question 20.11 ★★ QR, QD, Dev, QT • any • junior

Give an example in which Newton’s method on a root moves away from the root at each step, whatever the start. For f(x)=arctan⁡xf(x) = \arctan x, for what starting values does it fail? Why does solving for implied volatility need care, and how do you make a Newton iteration safe?

Answer

Answer to Question 20.11.

f(x)=sign⁡(x)∣x∣1/3f(x) = \operatorname{sign}(x)|x|^{1/3} gives x↦−2xx \mapsto -2x, which moves away from the root at every step. arctan⁡\arctan fails when ∣x0∣>1.392|x_0| > 1.392, and implied volatility is safe only with a good start or a bracket.

For the cube root, the update is x−x1/3/(13x−2/3)=x−3x=−2xx - x^{1/3}/\bigl(\frac13 x^{-2/3}\bigr) = x - 3x = -2x. The derivative is infinite at the root, so the tangent line always overshoots.

For the arctangent, the update is x−(1+x2)arctan⁡xx - (1 + x^2)\arctan x. A start far out has a nearly flat tangent, which throws the next point further away. The boundary is the two-point cycle, x→−xx \to -x, which solves arctan⁡x=2x/(1+x2)\arctan x = 2x/(1 + x^2), at x≈1.392x \approx 1.392. Runs from 1.31.3 and from 1.51.5 converge and diverge as predicted.

Implied volatility has the same shape: the option price is flat at low volatility for a far out-of-the-money option, which means a tiny vega, and then the step blows up. With F=1F = 1, K=1.5K = 1.5, T=1T = 1 and a true volatility of 0.20.2, a start at 0.050.05 jumps past 100 in one step. The price is convex in volatility up to an inflection point, here at 2ln⁡1.5=0.90\sqrt{2\ln 1.5} = 0.90, and concave beyond. A run started at the inflection falls steadily to the answer.

A safe general method keeps a bracket on the root and takes the Newton step only if it stays inside. Otherwise, it bisects.

Classic wrong answer. Assuming that a monotonic function makes Newton safe. Both functions above are monotonic.

Follow-up. Bisecting from 0.01 to 5, how many steps reach a precision of 0.00010.0001? 16, since log⁡2(4.99/0.0001)≈15.6\log_2(4.99/0.0001) \approx 15.6. That is slow but sure, and the bound does not depend on the option.

Why it matters. Solvers that fail on rare inputs are what cause production incidents. The candidate is expected to know when Newton is not safe and to have a fallback ready.

Question 20.12 ★★ QR, QD, Dev, LLE • any • junior

In double precision, the smaller root of x2−108x+1=0x^2 - 10^8x + 1 = 0 from the usual formula comes out wrong. What does it give, what is the true value, and how do you fix it? Why does 1−cos⁡x1 - \cos x fail for small xx, and what do you use instead? Why does the plain formula for variance fail on large offset values, and what is a better method?

Answer

Answer to Question 20.12.

The formula returns about 7.45×10−97.45 \times 10^{-9} for a true 10−810^{-8}; use c/xlargec/x_{\text{large}}. Use 2sin⁡2(x/2)2\sin^2(x/2) for 1−cos⁡x1 - \cos x. Use a running update such as Welford’s for the variance.

In the formula, 1016−4\sqrt{10^{16} - 4} is very close to 10810^8, and spacing between doubles there is about 1.5×10−81.5 \times 10^{-8}. The subtraction therefore returns a small multiple of that spacing, and half of one spacing is the printed 7.45×10−97.45 \times 10^{-9}: 25% wrong. This is cancellation: the subtraction itself is exact, but it exposes the error already in its inputs.

The fix uses the fact that the product of the roots is 1. Compute the large root, where the two terms add, and divide: xsmall=1/xlargex_{\text{small}} = 1/x_{\text{large}}, which gives 10−810^{-8} to full accuracy.

For x=10−8x = 10^{-8}, cos⁡x\cos x rounds to exactly 1, so 1−cos⁡x1 - \cos x returns 0, where the truth is 5×10−175 \times 10^{-17}. The half-angle form involves no subtraction. Library functions such as expm1 and log1p solve the same problem for their own cases.

For the variance, ∑x2−(∑x)2/n\sum x^2 - (\sum x)^2/n subtracts two huge, nearly equal numbers. With values 1015+410^{15} + 4, +7+7, +13+13, +16+16, the true variance is 30, and the plain formula is off by more than 1. Welford’s update tracks the distance from the running mean and returns 30.

Classic wrong answer. Blaming the rounding of the last operation. The subtraction is exact. The fault is that the operands already carried errors, and the leading digits cancelled.

Follow-up. Why does summing 101610^{16}, 1, 1, −1016-10^{16} in order give 0, and what returns 2? Each 1 is exactly half the spacing at 101610^{16}, and the tie rounds back to the even neighbour, so it is lost. Kahan’s compensated summation carries the lost part into the next term and returns 2.

Why it matters. Numerical bugs give plausible numbers and pass most tests. The ability to find the operation that loses accuracy is what the question measures.

Question 20.13 ★★ QR, QD, Dev • any • junior

You estimate a derivative with a forward difference in double precision. What step size is best, and what accuracy do you reach? How do both change for a central difference? Is there a way to reach almost full accuracy for an analytic function?

Answer

Answer to Question 20.13.

Forward difference: h≈10−8h \approx 10^{-8}, accuracy about 10−810^{-8}. Central difference: h≈6×10−6h \approx 6 \times 10^{-6}, accuracy about 10−1110^{-11}. A complex step reaches almost full accuracy.

The forward difference has two errors. Truncation is about h∣f′′∣/2h|f^{\prime\prime}|/2, which shrinks with hh. Rounding is about ε∣f∣/h\varepsilon|f|/h, with ε≈2.2×10−16\varepsilon \approx 2.2 \times 10^{-16}, which grows as hh shrinks. Balancing the two gives h∼ε=1.5×10−8h \sim \sqrt{\varepsilon} = 1.5 \times 10^{-8} and an error of about the same size, for a function and derivatives of order 1. So half the digits are lost, and they cannot be recovered by smaller steps. Too small a step makes things worse.

The central difference has truncation h2∣f′′′∣/6h^2|f^{\prime\prime\prime}|/6. Balancing with rounding ε/h\varepsilon/h gives h∼ε1/3≈6×10−6h \sim \varepsilon^{1/3} \approx 6 \times 10^{-6} and an error around ε2/3≈4×10−11\varepsilon^{2/3} \approx 4 \times 10^{-11}. A sweep on exe^x at x=1x = 1 shows both minima where predicted.

For an analytic function, f(x+ih)=f(x)+ihf′(x)+O(h2)f(x + ih) = f(x) + ihf'(x) + O(h^2), so Im⁡f(x+ih)/h\operatorname{Im} f(x + ih)/h gives the derivative with no subtraction, and hence no cancellation. A step of 10−3010^{-30} is allowed, and the result is correct to about 15 digits. Automatic differentiation goes further and needs no analytic extension.

Classic wrong answer. Saying that the smaller the step, the better. With h=10−15h = 10^{-15} the forward difference is mostly rounding noise.

Follow-up. What are the best step and the accuracy for the central second difference? Here the rounding error is about ε/h2\varepsilon/h^2, and truncation is h2h^2. So h∼ε1/4≈10−4h \sim \varepsilon^{1/4} \approx 10^{-4}, with an accuracy of about 10−810^{-8}. Half the digits are lost again.

Why it matters. Every Greek computed by bumping has this trade-off. A candidate who bumps by 10−1210^{-12} has never looked at the result.

Question 20.14 ★★★ QR, QT • hedge fund, market maker • junior, experienced

Compute ∫0π/2ln⁡sin⁡x dx\int_0^{\pi/2} \ln \sin x\,dx with no series, using only symmetries of the sine and the double-angle formula.

Answer

Answer to Question 20.14.

The integral is −π2ln⁡2≈−1.0888-\frac{\pi}{2}\ln 2 \approx -1.0888.

Call it II. The integrand diverges at 0 only like ln⁡x\ln x, which is integrable, so II is finite.

The reflection x→π/2−xx \to \pi/2 - x shows that ∫0π/2ln⁡cos⁡x dx=I\int_0^{\pi/2}\ln\cos x\,dx = I. Adding the two,

2I=∫0π/2ln⁡(sin⁡xcos⁡x) dx=∫0π/2ln⁡sin⁡2x2 dx=∫0π/2ln⁡sin⁡2x dx−π2ln⁡2.2I = \int_0^{\pi/2}\ln(\sin x\cos x)\,dx = \int_0^{\pi/2}\ln\frac{\sin 2x}{2}\,dx = \int_0^{\pi/2}\ln\sin 2x\,dx - \frac{\pi}{2}\ln 2.

Substitute u=2xu = 2x in the remaining integral:

∫0π/2ln⁡sin⁡2x dx=12∫0πln⁡sin⁡u du.\int_0^{\pi/2}\ln\sin 2x\,dx = \frac12\int_0^{\pi}\ln\sin u\,du.

The sine is symmetric about π/2\pi/2, so the integral on [0,π][0, \pi] is 2I2I, and the whole term is II. So 2I=I−π2ln⁡22I = I - \frac{\pi}{2}\ln 2, which gives the result.

Two checks. The sign is right, because ln⁡sin⁡x≤0\ln\sin x \le 0 on the interval. And dividing by the length π/2\pi/2 shows that the mean of ln⁡sin⁡x\ln\sin x is −ln⁡2-\ln 2, so the geometric mean of the sine is exactly 12\frac12. That lies below the arithmetic mean, 2/π=0.6372/\pi = 0.637, as it must. Numerical integration gives the same number.

Classic wrong answer. Stopping at the term ∫ln⁡sin⁡2x dx\int\ln\sin 2x\,dx with no recognition that it is II again. The self-reference is the whole trick. A second common error is forgetting the 12\frac12 from the substitution, which gives the wrong multiple.

Follow-up. Compute ∫0π/2xcot⁡x dx\int_0^{\pi/2} x\cot x\,dx. π2ln⁡2\frac{\pi}{2}\ln 2. Integrate by parts: the boundary term xln⁡sin⁡xx\ln\sin x vanishes at both ends, and what remains is −∫ln⁡sin⁡x dx=π2ln⁡2-\int\ln\sin x\,dx = \frac{\pi}{2}\ln 2.

Why it matters. Reducing an integral to itself with a different coefficient is a recurring technique. The candidate must also be willing to carry out a substitution that seems to go nowhere.

Question 20.15 ★★★ QR, QT • hedge fund • junior, experienced

Compute ∫0∞sin⁡xx dx\int_0^\infty \frac{\sin x}{x}\,dx by introducing a parameter: define I(t)=∫0∞e−txsin⁡xx dxI(t) = \int_0^\infty e^{-tx}\frac{\sin x}{x}\,dx, differentiate under the integral, and solve. What is I(1)I(1)? Why does the original integral converge, though not absolutely?

Answer

Answer to Question 20.15.

The integral is π/2\pi/2, with I(t)=π/2−arctan⁡tI(t) = \pi/2 - \arctan t and I(1)=π/4I(1) = \pi/4.

Differentiating under the integral removes the awkward 1/x1/x:

I′(t)=−∫0∞e−txsin⁡x dx=−11+t2,I'(t) = -\int_0^\infty e^{-tx}\sin x\,dx = -\frac{1}{1 + t^2},

where the last step is the imaginary part of a complex exponential integral. So I(t)=c−arctan⁡tI(t) = c - \arctan t. As t→∞t \to \infty, I(t)→0I(t) \to 0, which fixes c=π/2c = \pi/2. Letting t→0t \to 0 gives π/2\pi/2. At t=1t = 1, the value is π/2−π/4=π/4\pi/2 - \pi/4 = \pi/4, and numerical integration at t=12,1,2t = \frac12, 1, 2 agrees.

Convergence comes from cancellation. The arcs of sin⁡x/x\sin x/x alternate in sign with falling size, so the partial integrals approach the limit with an error of about 1/R1/R. Absolutely, it diverges: over the kk-th arc, ∫∣sin⁡x∣/x dx\int|\sin x|/x\,dx is about 2/(kπ)2/(k\pi), a harmonic series growing like 2πln⁡R\frac{2}{\pi}\ln R.

Passing to t=0t = 0 needs justifying because the integral is not absolutely convergent. The second mean value theorem applies, since e−tx/xe^{-tx}/x falls with xx: the tail beyond RR is at most 2/R2/R for every t≥0t \ge 0. The convergence is therefore uniform in tt, and II is continuous at 0.

Classic wrong answer. Using dominated convergence directly at t=0t = 0. There is no integrable dominating function, because ∣sin⁡x∣/x|\sin x|/x is not integrable. The uniform tail bound replaces it.

Follow-up. What is ∫0∞(sin⁡x/x)2 dx\int_0^\infty (\sin x/x)^2\,dx? Also π/2\pi/2. Integrating by parts turns it into ∫0∞sin⁡2x/x dx\int_0^\infty \sin 2x / x\,dx, which is the integral above after a rescaling. This time the convergence is absolute.

Why it matters. Feynman’s parameter trick is common in quant interviews because it rewards seeing a way in. The care about the limit at 0 separates the prepared candidates from the careful ones.

Question 20.16 ★★★ QR, QT, DS • hedge fund • junior, experienced

Let AA be a symmetric positive definite nn by nn matrix. Compute ∫Rne−12x⊤Ax dx\int_{\mathbb{R}^n} e^{-\frac12 x^\top Ax}\,dx. Deduce the covariance of the corresponding normal. Evaluate both for AA with rows (2,1)(2, 1) and (1,2)(1, 2). What is the sign of the correlation, and why?

Answer

Answer to Question 20.16.

The integral is (2π)n/2/det⁡A(2\pi)^{n/2}/\sqrt{\det A}, and the covariance is A−1A^{-1}. For the example, the integral is 2π/3≈3.6282\pi/\sqrt{3} \approx 3.628, the covariance is 13\frac13 times rows (2,−1)(2, -1), (−1,2)(-1, 2), and the correlation is −12-\frac12.

Diagonalise A=QΛQ⊤A = Q\Lambda Q^\top and substitute x=Qyx = Qy. Since QQ is orthogonal, the Jacobian is 1, and the exponent becomes −12∑iλiyi2-\frac12\sum_i\lambda_iy_i^2. The integral factorises:

∏i2πλi=(2π)n/2det⁡A.\prod_i\sqrt{\frac{2\pi}{\lambda_i}} = \frac{(2\pi)^{n/2}}{\sqrt{\det A}}.

In the yy coordinates, yiy_i is normal with variance 1/λi1/\lambda_i, independently. So the covariance of xx is QΛ−1Q⊤=A−1Q\Lambda^{-1}Q^\top = A^{-1}.

For the example, det⁡A=3\det A = 3, which gives 2π/32\pi/\sqrt{3}; direct quadrature agrees. The inverse is the covariance stated, with variance 23\frac23 and covariance −13-\frac13, so the correlation is −12-\frac12.

The sign is the point to explain. The exponent contains the term −xy-xy, with a positive entry in AA. That term penalises xx and yy having the same sign and rewards opposite signs, so a positive entry in the precision matrix means a negative correlation. In general, the partial correlation of two variables is −Aij/AiiAjj-A_{ij}/\sqrt{A_{ii}A_{jj}}, and a simulation of the normal confirms −12-\frac12.

Classic wrong answer. Reading the covariance off AA directly and saying that the correlation is +12+\frac12. AA is the inverse of the covariance, and for two variables the inversion flips the sign of the off-diagonal.

Follow-up. Given x2=1x_2 = 1, what are the mean and variance of x1x_1? Mean −12-\frac12 and variance 12\frac12. The conditional variance is 1/A111/A_{11}, read straight off the precision matrix, and the mean is −A12/A11-A_{12}/A_{11} times the given value.

Why it matters. Gaussian integrals are behind every likelihood and every Bayesian update. The distinction between covariance and precision is often the one where a good candidate’s intuition goes wrong.

Question 20.17 ★★★ QR, QT, DS, Risk • hedge fund • junior, experienced

You allocate one unit of capital across three strategies, with amounts xi≥0x_i \ge 0, to maximise ∑iln⁡(1+xi/ni)\sum_i \ln(1 + x_i/n_i), with n=(0.2,0.5,1)n = (0.2, 0.5, 1). Write the optimality conditions, with the sign constraints, and solve. Why is the last strategy unfunded? How does the answer change if the capital is 3 units?

Answer

Answer to Question 20.17.

The solution is x=(0.65,0.35,0)x = (0.65, 0.35, 0) with common level L=0.85L = 0.85. With 3 units, all three are funded, with x≈(1.37,1.07,0.57)x \approx (1.37, 1.07, 0.57) and L=4.7/3≈1.57L = 4.7/3 \approx 1.57.

The derivative of ln⁡(1+xi/ni)=ln⁡(ni+xi)−ln⁡ni\ln(1 + x_i/n_i) = \ln(n_i + x_i) - \ln n_i is 1/(ni+xi)1/(n_i + x_i). With a multiplier ν\nu on the budget and non-negativity constraints, the optimality conditions are

1ni+xi≤ν,xi≥0,xi(ν−1ni+xi)=0,∑ixi=1.\frac{1}{n_i + x_i} \le \nu, \qquad x_i \ge 0, \qquad x_i\left(\nu - \frac{1}{n_i + x_i}\right) = 0, \qquad \sum_i x_i = 1.

So every funded line has the same ni+xi=L=1/νn_i + x_i = L = 1/\nu, and xi=max⁡(L−ni,0)x_i = \max(L - n_i, 0). This is called water-filling: capital is poured over levels nin_i until the budget is used up.

Try funding all three: 3L−1.7=13L - 1.7 = 1 gives L=0.9<1L = 0.9 < 1, which makes x3x_3 negative. So fund two: 2L−0.7=12L - 0.7 = 1 gives L=0.85L = 0.85, and then x1=0.65x_1 = 0.65, x2=0.35x_2 = 0.35. The third is correctly unfunded, because its marginal value at zero, 1/11/1, is below ν=1/0.85\nu = 1/0.85. The last strategy is unfunded because even its first unit earns less than the current level on the others.

With 3 units, 3L−1.7=33L - 1.7 = 3 gives L=4.7/3L = 4.7/3, above 1, so all three now receive capital. A numerical optimiser returns the same allocation.

Classic wrong answer. Solving the equal-marginal system with no sign constraint and reporting a negative amount, or setting the bad line to zero with no re-solving for the others. The budget must be re-split once any line drops out.

Follow-up. At what capital does the third line start receiving money? At 1.31.3. It is funded once LL reaches 1, and at that level the first two lines hold 0.8+0.5=1.30.8 + 0.5 = 1.3. Below this, all capital goes to the first two.

Why it matters. Sign constraints in allocation problems arise constantly, and the KKT conditions are what make them tractable. The candidate who can check the unfunded line has understood what the multiplier means.

Question 20.18 ★★★ QR, QD, DS • any • junior, experienced

Prove that Newton’s method converges quadratically near a simple root. Show that convergence is only linear at a double root, by using f(x)=(x−1)2f(x) = (x - 1)^2, and find the rate. How would you fix the double-root case if you know the multiplicity?

Answer

Answer to Question 20.18.

Near a simple root, the error satisfies en+1≈f′′(r)2f′(r)en2e_{n + 1} \approx \frac{f^{\prime\prime}(r)}{2f'(r)}e_n^2. At the double root, it halves at each step, and using the step x−2f/f′x - 2f/f' restores fast convergence.

Let rr be the root and en=xn−re_n = x_n - r. Taylor’s formula at xnx_n, with a remainder, gives

0=f(r)=f(xn)−f′(xn)en+12f′′(ξ)en2.0 = f(r) = f(x_n) - f'(x_n)e_n + \tfrac12 f^{\prime\prime}(\xi)e_n^2.

Divide by f′(xn)f'(x_n) and rearrange. Since xn+1=xn−f(xn)/f′(xn)x_{n + 1} = x_n - f(x_n)/f'(x_n),

en+1=f′′(ξ)2f′(xn)en2.e_{n + 1} = \frac{f^{\prime\prime}(\xi)}{2f'(x_n)}e_n^2.

If ff is twice continuously differentiable and f′(r)≠0f'(r) \ne 0, the fraction is bounded by some MM on a neighbourhood of rr. Once M∣en∣<1M|e_n| < 1, the errors fall and ∣en+1∣≤Men2|e_{n + 1}| \le M e_n^2, which is quadratic convergence. On x2−2x^2 - 2 the ratio en+1/en2e_{n + 1}/e_n^2 tends to 1/(22)1/(2\sqrt{2}), as the formula predicts.

For a double root the proof fails, as f′(r)=0f'(r) = 0. With f=(x−1)2f = (x - 1)^2, the step gives x−(x−1)/2x - (x - 1)/2, so en+1=12ene_{n + 1} = \frac12 e_n: linear convergence with rate 12\frac12, one bit per step. A reduction of 10610^6 takes 20 steps instead of about 4. In general, for multiplicity mm, the rate is (m−1)/m(m - 1)/m.

If mm is known, take x−mf/f′x - mf/f'. On the example, that lands on the root in one step, and in general it restores quadratic convergence.

Classic wrong answer. Assuming that Newton is always quadratic. Or proving it with no assumption on f′(r)f'(r). The denominator is the entire condition.

Follow-up. What if the multiplicity is unknown, and how accurately can a double root be found in double precision? Apply Newton to u=f/f′u = f/f', which has a simple root at the same place. In double precision, ff itself is pure noise when ∣x−r∣|x - r| is around 10−810^{-8}, so only half the digits can be obtained.

Why it matters. This question distinguishes people who recall the slogan from those who can state its assumptions. A slow Newton iteration in practice is often a double root.

Question 20.19 ★★★★ QR, QT • hedge fund • experienced

Show that ∑k≥11/k2=π2/6\sum_{k \ge 1} 1/k^2 = \pi^2/6, by evaluating the double integral ∫01∫01dx dy1−xy\int_0^1\int_0^1 \frac{dx\,dy}{1 - xy} in two ways. Hint: expand as a geometric series for one route, and rotate the axes by 45 degrees for the other.

Answer

Answer to Question 20.19.

The geometric series gives ∑k≥11/k2\sum_{k \ge 1} 1/k^2, and the rotated integral gives π2/18+π2/9=π2/6\pi^2/18 + \pi^2/9 = \pi^2/6.

Series route. Expanding 1/(1−xy)=∑k≥0(xy)k1/(1 - xy) = \sum_{k \ge 0}(xy)^k, with non-negative terms so the sum and integral can be swapped, each term integrates to 1/(k+1)21/(k + 1)^2.

Rotation route. Put u=(x+y)/2u = (x + y)/2 and v=(y−x)/2v = (y - x)/2, so that x=u−vx = u - v, y=u+vy = u + v, the Jacobian is 2, and 1−xy=1−u2+v21 - xy = 1 - u^2 + v^2. The unit square becomes a diamond with ∣v∣≤u|v| \le u for u≤12u \le \frac12 and ∣v∣≤1−u|v| \le 1 - u for u≥12u \ge \frac12. By symmetry in vv, the integral is

4∫01/2 ⁣ ⁣∫0udv1−u2+v2 du+4∫1/21 ⁣ ⁣∫01−udv1−u2+v2 du.4\int_0^{1/2}\!\!\int_0^u \frac{dv}{1 - u^2 + v^2}\,du + 4\int_{1/2}^1\!\!\int_0^{1 - u}\frac{dv}{1 - u^2 + v^2}\,du.

With a=1−u2a = \sqrt{1 - u^2}, the inner integral is 1aarctan⁡(c/a)\frac1a\arctan(c/a), where cc is the upper limit.

In the first part, arctan⁡(u/1−u2)=arcsin⁡u\arctan(u/\sqrt{1 - u^2}) = \arcsin u, so the part equals

4∫01/2arcsin⁡u1−u2 du=2(arcsin⁡12)2=π218.4\int_0^{1/2}\frac{\arcsin u}{\sqrt{1 - u^2}}\,du = 2\left(\arcsin\tfrac12\right)^2 = \frac{\pi^2}{18}.

In the second, arctan⁡(1−u)/(1+u)=12arccos⁡u\arctan\sqrt{(1 - u)/(1 + u)} = \frac12\arccos u by the half-angle formula, so the part equals

2∫1/21arccos⁡u1−u2 du=(arccos⁡12)2=π29.2\int_{1/2}^1\frac{\arccos u}{\sqrt{1 - u^2}}\,du = \left(\arccos\tfrac12\right)^2 = \frac{\pi^2}{9}.

The two add to π2/6\pi^2/6, and a direct partial sum confirms 1.64491.6449.

Classic wrong answer. Swapping the sum and the integral with no reason, or missing the Jacobian. The factor of 2 from the change of variables is the usual cause of a wrong constant.

Follow-up. What is the sum of 1/k21/k^2 over odd kk, and what does 6/π26/\pi^2 count? π2/8\pi^2/8, because the even terms are a quarter of the whole. And 6/π2≈0.6086/\pi^2 \approx 0.608 is the limiting chance that two random integers are coprime; an exact count up to 1000 agrees to about two decimals.

Why it matters. This is a hard calculation done to a plan, and checks that the candidate can carry a change of variables on a non-trivial region to the end.

Question 20.20 ★★★★ QR, QT • hedge fund • experienced

Prove that n!∼Cn(n/e)nn! \sim C\sqrt{n}(n/e)^n for some constant CC, by showing a suitable sequence is monotone and bounded. Then find C=2πC = \sqrt{2\pi} exactly by using Wallis’s result, lim⁡n→∞I2n/I2n+1=1\lim_{n \to \infty} I_{2n}/I_{2n + 1} = 1, with In=∫0π/2sin⁡nx dxI_n = \int_0^{\pi/2} \sin^n x\,dx.

Answer

Answer to Question 20.20.

The sequence dn=ln⁡n!−(n+12)ln⁡n+nd_n = \ln n! - (n + \frac12)\ln n + n falls and is bounded below, which gives the limit, and Wallis then fixes C=2πC = \sqrt{2\pi}.

Monotone. From the definition, dn−dn+1=(n+12)ln⁡n+1n−1d_n - d_{n + 1} = (n + \frac12)\ln\frac{n + 1}{n} - 1. Put t=1/(2n+1)t = 1/(2n + 1), so (n+1)/n=(1+t)/(1−t)(n + 1)/n = (1 + t)/(1 - t) and n+12=1/(2t)n + \frac12 = 1/(2t). The series for ln⁡1+t1−t\ln\frac{1 + t}{1 - t} gives

dn−dn+1=∑k≥1t2k2k+1>0.d_n - d_{n + 1} = \sum_{k \ge 1}\frac{t^{2k}}{2k + 1} > 0.

Bounded. Replacing each 2k+12k + 1 by 3 gives an upper bound of 13⋅t2/(1−t2)=112n(n+1)\frac13\cdot t^2/(1 - t^2) = \frac{1}{12n(n + 1)}, which is 112n−112(n+1)\frac{1}{12n} - \frac{1}{12(n + 1)}. So dn−112nd_n - \frac{1}{12n} rises with nn. Since d1=1d_1 = 1, we get dn>1112d_n > \frac{11}{12} for all nn. A falling sequence bounded below converges, so n!/(n(n/e)n)→C=elim⁡dnn!/(\sqrt{n}(n/e)^n) \to C = e^{\lim d_n}.

The constant. The reduction formula gives

I2n=π2(2n)!22n(n!)2,I2n+1=22n(n!)2(2n+1)!.I_{2n} = \frac{\pi}{2}\frac{(2n)!}{2^{2n}(n!)^2}, \qquad I_{2n + 1} = \frac{2^{2n}(n!)^2}{(2n + 1)!}.

Their ratio tends to 1, since InI_n falls and I2n−1/I2n+1=(2n+1)/(2n)→1I_{2n - 1}/I_{2n + 1} = (2n + 1)/(2n) \to 1. Thus

π2⋅(2n+1) ((2n)!)224n(n!)4→1.\frac{\pi}{2}\cdot\frac{(2n + 1)\,((2n)!)^2}{2^{4n}(n!)^4} \to 1.

Now substitute n!∼Cn(n/e)nn! \sim C\sqrt{n}(n/e)^n. All the powers cancel, ((2n)!)2/(24n(n!)4)∼2/(C2n)((2n)!)^2/(2^{4n}(n!)^4) \sim 2/(C^2n), and the limit becomes 2π/C2=12\pi/C^2 = 1. So C=2πC = \sqrt{2\pi}.

Classic wrong answer. Using the sharper Stirling expansion to prove itself, or deriving the constant by Laplace’s method with no error control and calling this a proof. That is a good heuristic, but an interviewer who asks for monotonicity wants the argument above.

Follow-up. How accurate is the formula with the correction 1+1/(12n)1 + 1/(12n) at n=10n = 10? It gives 3 628 6853\,628\,685 against the true 3 628 8003\,628\,800, an error of 30 parts per million. The plain formula gives 3 598 6963\,598\,696, an error of 0.8%0.8\%. The 1/(12n)1/(12n) comes from the same bound.

Why it matters. The hardest level of the chapter. It tests whether the candidate can make a heuristic exact, and whether the classical limit can be applied with its assumptions in view.