本书暂未推出简体中文版。现有版本: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 reach its minimum for , and what is the minimum? Without a calculator, which is larger: or ? Prove it with a single function.
Answer
Answer to Question 20.1.
The minimum is at , with value , and is the larger.
Write . The derivative of is , which vanishes at . As the function tends to 1, and it rises again beyond , so this point is the minimum.
For the comparison, use . Its derivative is positive below and negative above, so peaks at . Hence , which rearranges to , that is, . The values are about and , 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 settles it with no arithmetic.
Follow-up. Which is larger: or ? . Past the function falls, so , which rearranges to .
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 by squaring it and using polar coordinates. Use the result to find the normal density’s constant, and the mean of for a standard normal .
Answer
Answer to Question 20.2.
The integral is , the normal density’s constant is , and .
Let be the integral. Then
The factor from the change of coordinates is what makes the inner integral exact.
Substituting gives , so the density needs the constant .
Finally, by symmetry,
That is below 1, as it must be, since .
Classic wrong answer. Forgetting the factor , which leaves an integral with no closed form. Or giving , which confuses the mean absolute value with the standard deviation.
Follow-up. What is ? . Integrate by parts with , which leaves half of .
Why it matters. Everyone quotes the constant; few can produce it. The ratio 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 , starting from . 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 , the iterates are , and , and the number of correct digits about doubles at each step.
Newton’s method gives , which simplifies to the average of and . That is the old idea of averaging a guess that is too high with one that is too low.
From 1: ; then ; then .
The errors are about , and . Each error is about , where is the one before, so the error is squared at each step, up to a constant of about .
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 ? Apply Newton to , which gives , with no division. For from , it gives , then . 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 , and 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 , where 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.
, , , and the bond falls by 10% to first order and to second order; the exact fall is .
The three series are , giving ; , giving ; and , giving .
Whatever the starting yield , the bond’s relative change is . With , the terms are and . 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 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 suggests 69? Since is below , the true number rises with the rate, and 72 fits near 8%, where doubling takes 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 for any positive . Then compute , using a similar trick after the substitution .
Answer
Answer to Question 20.5.
The first integral is for every , and the second is .
For the first, substitute , which swaps sine and cosine. Adding the two forms of the integral, the integrand becomes 1, so . The exponent plays no part, and that is the point.
For the second, cancels the denominator and gives
Now substitute . The tangent subtraction formula gives . So
which gives .
A size check: the integrand rises from 0 to across an interval of length 1, so a value near 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 . . Substituting replaces with on average, and what remains is .
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 from , by expanding around the peak of the integrand. Use it to approximate . What is the chance of exactly 50 heads in 100 flips?
Answer
Answer to Question 20.6.
, so , and the chance of exactly 50 heads is about .
Write the integrand as with . The peak is at , where . Expanding to second order,
which is the Stirling formula. Extending the range to the whole line costs almost nothing, as the mass sits within a few of . The relative error is about , so at the formula is already within 1%.
For the middle binomial coefficient, the powers cancel:
With this gives , against the true . Dividing by gives , against the exact .
Classic wrong answer. Forgetting the factor and using alone. It is off by a factor of 25 at , though it is fine for the leading growth rate.
Follow-up. In 1000 flips, what is the chance of an exact tie? . Ten times as many flips reduce the chance of a tie by a factor of , 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 . Derive a recursion using integration by parts, and compute exactly. How close is the large- approximation ?
Answer
Answer to Question 20.7.
The recursion is , and . The approximation gives , 2.5% high.
Integrating by parts with and , the boundary term vanishes and
Solving gives the recursion. Starting from ,
For the large- form, the recursion shows that does not change with , and at it equals . As for large , this gives . The gap at shrinks to almost nothing if is replaced by , which gives .
Classic wrong answer. Using the recursion with , the wrong way up. That makes the integrals grow, though falls with .
Follow-up. What is the mean of over a full circle, and what else equals it? , which is . It is also the chance of exactly five heads in ten flips, , which is no accident: expanding 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 subject to with positive variables, by Lagrange multipliers and by another route. Then maximise subject to . Show for that the multiplier equals the change in the best value per unit of , and say what this means.
Answer
Answer to Question 20.8.
The first maximum is at , and the second is at . At , the multiplier is , which is the marginal value of the budget.
For the first, set the gradient of proportional to that of the constraint: . Positive variables then give . The other route is the inequality of arithmetic and geometric means: , with equality when all are equal.
For the second, , so , and the value is . At : , and . Separately, . 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 gives , below 2.
Follow-up. The budget rises from 2 to . Estimate the new best value with no re-solving. . The exact value is . The estimate is slightly high, because 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: , , , , , ? 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: , , , . Not convex: , which is concave, and , which is neither. The compound rate is about .
The reasons, in order. has second derivative . So does , with second derivative 2. satisfies the triangle inequality. has a negative second derivative. A maximum of linear functions is always convex. has Hessian eigenvalues , so it curves up along and down along .
Now for the return. Compounding takes logs, and is concave, so Jensen’s inequality gives . Expanding around the mean,
So the log growth is about to this order. A numerical integral, and a simulation of the normal, give , which is a year as a simple rate. The common shortcut lands in the same place. With no volatility the formula gives back exactly 10%. A normal return can in principle fall below , where the log is undefined, but that is standard deviations away and does not affect the size.
Classic wrong answer. Calling 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 ? , which gives growth of . 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 with 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 ? 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 ; the best is ; 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 per step. To converge, every factor must be below 1 in size, and the largest eigenvalue gives .
The best step balances the two factors: , so . Both factors then have size . To reduce the error by takes steps, confirmed by running it. A step just over makes the second coordinate grow without limit.
The number that matters is the condition number ; the step count is about .
Newton multiplies the gradient by , which lands on the minimum at once for any quadratic. Heavy-ball momentum, tuned with and , has rate . 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 from the smallest eigenvalue, say . 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 , 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.
gives , which moves away from the root at every step. fails when , and implied volatility is safe only with a good start or a bracket.
For the cube root, the update is . The derivative is infinite at the root, so the tangent line always overshoots.
For the arctangent, the update is . A start far out has a nearly flat tangent, which throws the next point further away. The boundary is the two-point cycle, , which solves , at . Runs from and from 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 , , and a true volatility of , a start at jumps past 100 in one step. The price is convex in volatility up to an inflection point, here at , 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 ? 16, since . 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 from the usual formula comes out wrong. What does it give, what is the true value, and how do you fix it? Why does fail for small , 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 for a true ; use . Use for . Use a running update such as Welford’s for the variance.
In the formula, is very close to , and spacing between doubles there is about . The subtraction therefore returns a small multiple of that spacing, and half of one spacing is the printed : 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: , which gives to full accuracy.
For , rounds to exactly 1, so returns 0, where the truth is . 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, subtracts two huge, nearly equal numbers. With values , , , , 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 , 1, 1, in order give 0, and what returns 2? Each 1 is exactly half the spacing at , 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: , accuracy about . Central difference: , accuracy about . A complex step reaches almost full accuracy.
The forward difference has two errors. Truncation is about , which shrinks with . Rounding is about , with , which grows as shrinks. Balancing the two gives 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 . Balancing with rounding gives and an error around . A sweep on at shows both minima where predicted.
For an analytic function, , so gives the derivative with no subtraction, and hence no cancellation. A step of 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 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 , and truncation is . So , with an accuracy of about . Half the digits are lost again.
Why it matters. Every Greek computed by bumping has this trade-off. A candidate who bumps by has never looked at the result.
Question 20.14 ★★★ QR, QT • hedge fund, market maker • junior, experienced
Compute with no series, using only symmetries of the sine and the double-angle formula.
Answer
Answer to Question 20.14.
The integral is .
Call it . The integrand diverges at 0 only like , which is integrable, so is finite.
The reflection shows that . Adding the two,
Substitute in the remaining integral:
The sine is symmetric about , so the integral on is , and the whole term is . So , which gives the result.
Two checks. The sign is right, because on the interval. And dividing by the length shows that the mean of is , so the geometric mean of the sine is exactly . That lies below the arithmetic mean, , as it must. Numerical integration gives the same number.
Classic wrong answer. Stopping at the term with no recognition that it is again. The self-reference is the whole trick. A second common error is forgetting the from the substitution, which gives the wrong multiple.
Follow-up. Compute . . Integrate by parts: the boundary term vanishes at both ends, and what remains is .
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 by introducing a parameter: define , differentiate under the integral, and solve. What is ? Why does the original integral converge, though not absolutely?
Answer
Answer to Question 20.15.
The integral is , with and .
Differentiating under the integral removes the awkward :
where the last step is the imaginary part of a complex exponential integral. So . As , , which fixes . Letting gives . At , the value is , and numerical integration at agrees.
Convergence comes from cancellation. The arcs of alternate in sign with falling size, so the partial integrals approach the limit with an error of about . Absolutely, it diverges: over the -th arc, is about , a harmonic series growing like .
Passing to needs justifying because the integral is not absolutely convergent. The second mean value theorem applies, since falls with : the tail beyond is at most for every . The convergence is therefore uniform in , and is continuous at 0.
Classic wrong answer. Using dominated convergence directly at . There is no integrable dominating function, because is not integrable. The uniform tail bound replaces it.
Follow-up. What is ? Also . Integrating by parts turns it into , 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 be a symmetric positive definite by matrix. Compute . Deduce the covariance of the corresponding normal. Evaluate both for with rows and . What is the sign of the correlation, and why?
Answer
Answer to Question 20.16.
The integral is , and the covariance is . For the example, the integral is , the covariance is times rows , , and the correlation is .
Diagonalise and substitute . Since is orthogonal, the Jacobian is 1, and the exponent becomes . The integral factorises:
In the coordinates, is normal with variance , independently. So the covariance of is .
For the example, , which gives ; direct quadrature agrees. The inverse is the covariance stated, with variance and covariance , so the correlation is .
The sign is the point to explain. The exponent contains the term , with a positive entry in . That term penalises and 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 , and a simulation of the normal confirms .
Classic wrong answer. Reading the covariance off directly and saying that the correlation is . is the inverse of the covariance, and for two variables the inversion flips the sign of the off-diagonal.
Follow-up. Given , what are the mean and variance of ? Mean and variance . The conditional variance is , read straight off the precision matrix, and the mean is 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 , to maximise , with . 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 with common level . With 3 units, all three are funded, with and .
The derivative of is . With a multiplier on the budget and non-negativity constraints, the optimality conditions are
So every funded line has the same , and . This is called water-filling: capital is poured over levels until the budget is used up.
Try funding all three: gives , which makes negative. So fund two: gives , and then , . The third is correctly unfunded, because its marginal value at zero, , is below . The last strategy is unfunded because even its first unit earns less than the current level on the others.
With 3 units, gives , 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 . It is funded once reaches 1, and at that level the first two lines hold . 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 , 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 . At the double root, it halves at each step, and using the step restores fast convergence.
Let be the root and . Taylor’s formula at , with a remainder, gives
Divide by and rearrange. Since ,
If is twice continuously differentiable and , the fraction is bounded by some on a neighbourhood of . Once , the errors fall and , which is quadratic convergence. On the ratio tends to , as the formula predicts.
For a double root the proof fails, as . With , the step gives , so : linear convergence with rate , one bit per step. A reduction of takes 20 steps instead of about 4. In general, for multiplicity , the rate is .
If is known, take . 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 . 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 , which has a simple root at the same place. In double precision, itself is pure noise when is around , 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 , by evaluating the double integral 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 , and the rotated integral gives .
Series route. Expanding , with non-negative terms so the sum and integral can be swapped, each term integrates to .
Rotation route. Put and , so that , , the Jacobian is 2, and . The unit square becomes a diamond with for and for . By symmetry in , the integral is
With , the inner integral is , where is the upper limit.
In the first part, , so the part equals
In the second, by the half-angle formula, so the part equals
The two add to , and a direct partial sum confirms .
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 over odd , and what does count? , because the even terms are a quarter of the whole. And 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 for some constant , by showing a suitable sequence is monotone and bounded. Then find exactly by using Wallis’s result, , with .
Answer
Answer to Question 20.20.
The sequence falls and is bounded below, which gives the limit, and Wallis then fixes .
Monotone. From the definition, . Put , so and . The series for gives
Bounded. Replacing each by 3 gives an upper bound of , which is . So rises with . Since , we get for all . A falling sequence bounded below converges, so .
The constant. The reduction formula gives
Their ratio tends to 1, since falls and . Thus
Now substitute . All the powers cancel, , and the limit becomes . So .
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 at ? It gives against the true , an error of 30 parts per million. The plain formula gives , an error of . The 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.