Sie sind auf Seite 1von 96

.....

Chapter 1 General Principles


Let us begin this book by exploring five general principles that will be extremely helpful
in your interview process. From my experience on both sides of the interview table,
these general guidelines will better prepare you for job interviews and will likely make
you a successful candidate.

1. Build a broad knowledge base


The length and the sryle of quant interviews differ from firm to finn. Landing a quant
job may mean enduring hours of bombardment with brain teaser, calculus, Ji near algebra ,
probability theory, statistics, derivative pricing, or programming problems. To be a
successful candidate, you need to have broad knowledge in mathematics, finance and
programming.
Will all these topics be relevant for your future quant job? Probably not. Each specific
quant position often requires only limited knowledge in these domains. General problem
solving sk ills may make more difference than specific knowledge. Then why are
quantitative interviews so comprehensive? There arc at least two reasons for this:
Tbe first reason is that interviewers oficn have diverse backgrounds. Each interviewer
has his or her own favorite topics that are often related to his or her own educational
background or work experience. As a result, the topics you will be tested on are likely to
be very broad. The second reason is more fundamental. Your probkm solving ski ll s- a
crucial requirement for any quant job-is often positively correlated to the breadth of
your knowledge. A basic understanding of a broad range of topics often helps you better
analyze problems, explore alternative approaches, and come up with enicicnt so lutions.
Besides, your responsibility may not be restricted to your own projects. You will be
expected to contribute as a member of a bigger team . Having broad knowledge will help
you contribute to the team's success as well.
The key here is "basic understanding." Interviewers do not expect you to b~ an expert on
a specitic subject- unless it happens to be your PhD thesis. The knowledge used in
interviews, although broad. covers mainly essential concepts. This is exactly the reason
why most of the books 1 refer to in the following chapters have the word " introduction"
or ''first' ~ in the title. lf I am aJiowed to give only one suggestion to a candidate, it will be
know the basics vcnr well .

2. Practice your interview skills


The interview process starts long before you step jnto an interview room. In a sense, the
success or failure of your interview is often determined before the first question is asked.
Your solutions to interview problems may fail to reflect your true intelligence and
General Principles

k.nowlcdg~ i~
you ~re unprepared. Although a complete revjew of quant interview
probl:ms tmposstble and unn~essary, practice does improve your interview skills.
IS,
Chapter 2 Brain Teasers
_Fu~~~c~,orc, _many of the behaviOral , technical and resume-related questions can be
:mtrcl~atcd. So prepare yourself for potential questions long before you enter an [n this chapter, we cover problems that only require common sense, logic, reasoning, and
mterv1ew room. basic-no more than high school level-math knowledge to so lve. In a sense, they are
£eal brain teasers_as opposed to mathematical problems in disguise. Although these brain
3. Listen carefully teasers do not require specific math knowledge, they are no less difficult than other
quantitati ve interview problems. Some of these problems test your analytical and general
~;;~r~hoy~~ ~eamnpatcttive Jist~nerhin interviews so that you Wlderstand the problems well problem-solving skills; some require you to think out of the box; while others ask you to
o answer t em If any aspect f bl . solve the problems using fundamental math techniques in a creative way. In this chapter,
politely ask for clarification. If the pr~blem is mo tho a pro !em IS not clea~ to you, we review some interview problems to explain the general themes of brain teasers that
the key words to help yo b re an a coup e of sentences, JOt down
interviewers often nive awauy resommem elr all tlhc infonnation. For complex problems, you are likely to encounter in quantitative interviews.
• eo e c ues w 1en they e 1 · h bl
assumptions they give may include some inf . xp am t e pro em. Even the
So listen carefuJly and make su ·e h onnatiOn a~ to how to approach the problem.
I you get t e necessary mformation. 2.1 Problem Simplification
If the original problem is so complex that you cannot come up with an immediate
4. Speak your mind solution, try to identify a simplified version of the problem and start with it. Usually you
When you analyze a problem and ex lore d·tJ . can start with the sj mplest sub-problem and gradually increase the complexity. You do
• erent ~ays to. solve tt, never do it si lently.
1
Clearly demonstrate your analysis p d not need to have a defined plan at the beginning. Just try to solve the simplest cases and
necessary. This conveys your intelran wnte down the Important steps involved if analyze your reasoning. More often than not, you will find a pattern that will guide you
methodical and thorough. In cas • th Itgence to the interviewer and shows that you are
. . , e a you go astray th · · through the whole problem.
mterv1ewer the opportunity to correvt h ' ' e. tnteractiOn will also give your
S . k. . t e course and provide you with some hints.
pea· mg your mmd does not mean ex PIammg
. . ev
obVIous to you. simplv state tile c
·
.· . ery t'my detall.
·
If some conclusions are Screwy pirates
. .. one1us1on with t tl · ·
not, tI1c mtcrviewcr uses a probl ou le tnv1al details. More often than Five pirates looted a chest fuJI of I00 gold coins. Being a bw-1ch of democratic pirates,
on demonstratmg . your understandiem to testf a specific1
concept/approach. You should focus they agree on the following method to divide the loot:
0
on less relevant details. ng the key concept/approach instead of dwell ing
ll1c most senior pirate will propose a distribution of the coins. All pirates. including the
most senior pirate, will then vote. If at least 50% of the pirates (3 pirates in this case)
5. Make reasonable assumptions accept the proposal, the gold is divided as proposed. If not: the most senior pirate will be
ln r~al job settings, you are unlikely t0 h fed to shark and the process starts over with the next most senior pirate ... The process is
~refer to have before you b ' ld ave all the necessary information or data you' d repeated until a plan is approved. You can assume that all pirates are perfectly rational:
mtervicwe rs may not g1ve . you allUi
th a model and make a deciston.
· · ln interviews, they want to stay alive first and to get as much gold as possible second. Finally, be ing
make rc· , hi
.• tsona c assumptions Th k e necessary assu · ·
mp1tons e•ther. So it is up to you to blood-thirsty pirates, they want to have fewer pirates on the boat if given a choice
nssumpu .
· · . ~ns to tht: mterviewer · so that
e eyword
, . here . ls
· reasonable. Explain your between otherwise equal outcomes.
qudantJt~tlv~ problems. it is crucial th· t ) ou wrU ~et Immediate feedback . To solve How will the gold coins be divided in the end?
an dcs1gn· · frameworks to a you can qUick1 Y rna ke reasonable assumptions
appropnatc
w, . . so1ve problen1s based on the assumptions.
Solution: If you have not studied game theory or dynamic programming, thi s strategy
c arc now ready to .· . problem may appear to be daunting. If the problem with 5 pirates seems wmplex, we
lmv • f1 I . rc\•tew basic concepts i . . .
c un so vmg real-world intervt'ew bl _n quanhtattve finance subicct areas and can always start with u simplified ,.·ersivn of the problem by reducing the number 0f
pro ems! J '
pirates. Since the solution to 1-piratc case is trivial. let '~ start with 2 pirates. The senior

2
Brain Teasers
-
A Practical Guide To Quantitative Finance Interviews

pirate (labeled as 2) can claim all the gold since he will always get 50% of the votes
from himself and pirate J is left with nothing. that jf it eats the sheep, it will tum to a sheep. Since there are 3 other tigers, it will be
eaten. So to guarantee the highest likelihood of survival, no tiger will eat the sheep.
Let's add a more senior pirate, 3. He knows that if his plan is voted down, pirate I will
Following the same logic, we can naturally show that if the number of tigers js even, the
get nothing. Rut if he offers private I nothing, pirate 1 wi ll be happy to kill him. So
sheep wil l not be eaten. If the nwnber js odd, the sheep will be eaten. For the case
pirate J will offer private 1 one coin and keep the remaining 99 coins, in which strategy
the piau will have 2 votes from pirate l and 3. n = l 00, the sheep will not be eaten.

If pirate 4 is added. he knows that if his plan is voted down, pirate 2 will get nothing. So
pi~ate 2 will settle for one coin if pirate 4 offers one. So pirate 4 should offer pirate 2 one 2.2 Logic Reasoning
com and keep the remaining 99 coins and his plan will be approved with 50% of the
votes from pirate 2 and 4. River crossing
~ow we final~y come t.o the 5-pir~te case. He knows that if his plan is voted down, both Four people, A) B, C and D need to get across a rive.r. The ~nly way to cross ~he river is
PI~atc 3 und p1rate I. will get nothmg. So he only needs to offer pirate I and pirate 3 one by an old bridge, which holds at most 2 people at a ume. Bemg d~rk, they cant cross the
com each to get thc1r votes i:lnd keep the remaining 98 cojns. If he divides the coins this brjdge without a torch, of which they only have one. So each patr can only walk .at the
way. he will have thrt::c out of the fi ve votes: from pirates 1 and 3 as well as himself. speed of the slower person. They need to get all of them across to the o the~ stde as
quickly as possible. A is the slowest and takes 10 minutes to cross; B takes 5 mmutes; C
On~c we start with a simplified version and add complexity to it, the answer becomes takes 2 minutes; and D takes l minute.
ohv10us~ A.ctually after the case 11 =5, a clear pattern has emerged and we do not need to
What is the minimum time to get all of them across to the other side?'
sto~ at .). Pirate~. For any 2n + 1 pirate case (n should be less than 99 though). the most
semor prrate "'1 11 offer pirates 1. 3... ·. and 2n-1 each one coin and keep the rest for Soiulion: The ke_y point is. to r::aJize tha!_the 10-minute pe~son ~ho~ld.
go ~ith the ~­
himself.
mi nute person and this should not happe~ j~ thenrst CE?SSmgL2{he~.~se one ?!}.!t:m
hi\ e to go back~ SoC and D should go across first (2 mm); then send D back (lmm); A
Tiger and sheep and B go across ( 10 min); send C back (2min); ('and D go acros~ ~gain (2 ml~).

One hundred tigers and one sh . . . It takes 17 minutes in total. Alternatively, we can send C back first and then D back in
eep
can eat grass but thev would rath are put
t ... on a mag1c Island that .on ly has grass.
. Ttgers the second round. which takes 17 minutes as weJI.
• .; er ea S~teep. Assume: A. Each tlme only one ttger can 1.~ Ld 11.. t , ~ j .:: h -, r r ,~f ~, ~~ h 'I
~at one sheep. and that tiger itself will become a sht:ep after it cats the sheep B All
ttgers arc smart ·md pcrfc tl · d · ·
t.:ate~? · ' c Y rauona1 an they want to survive. So will the sheep be Birthday problem

Solwion: I00 is a large numb r ,0


to Wt.lrry about b ·
.
y
emg eaten. How about ? t'1
either tiger probably , , ld d
o some
. 1 ~

'> s·
.
problem. If there is onI 1 ti ' ere · ~ agam et_ s .\·!arr wrth a simplified version oj the
g ( n- l ). surely It Will eat the sheep since it does not need
bo ·
· . - . gers ' mce th t1gers are perfectly rattona.
·
.

I
as to wh.at Wl'II h appen 1' t'.It eats t he sh eep.
dates:
Mar 4, Mar 5, Mar 8
/ f7
Jun 4• JL}.l.b ~
.' r'J\
You and you r co lleagues know that your

1
~"'~
tl
;i '
v
t
y/
bos~

J J':2 .
A' s birthday is one of the following 10

"7 "
t
t;. )
.
1
. if 1 thmkmg'
';L.
h • ther tiger is probablyltOU
thinkin • · L .~~
be eaten by the other t' > S g. eat the sheep, I Will become a sheep; and then I will · Sep 1. Sep
·'
_;
5 ......___
0 ,/
tiger will eat the sheep. Iger. to guarantee the highest likelihood of survival. neither Dec l. Dee-2. Dec 8 /
J'

If lhl!rc arc 3 tigers. the shee will be . . . . . . A told you only the mom~}>r his birthday. and told your ,colleag~e ~ <_?nl~. the d~. A~ter
changes to a sheep. there will ~e . eaten smc~ ea.ch t1gcr will reahzc that once 1t that, you fi rst said: "lOon 't know A's birthday: C doesn t k.now 1t e1the_r. · After heanng
2
that thi nks this through will t tb ~gers left and It Will not be eaten. So the first tiger
ea e s eep. lf there are 4 tigers, each tiger will understand 1
Hint: The key is to realize that A and 8 should get across the bridge together

5
Brain Teasers
A Practical Guide To Quantitative Finance Interviews

what you said, C replied: "I didn't know A's birthday, but now I know it. " You smiled red and black cards are discarded. As a result, the number of red cards left for you and
and said: "Now 1 know jt, too." After looking at the I 0 dates and hearing your comments, the number of black cards left for the dealer are always the same. The dealer always
your administrative assistant wrote down A's birthday without asking any questions. So wins! So we sho uld not pay anything to play the game.
what did the assistant write?

Solution: Don' t let the " he said, she said" part confuses you. Just interpret the logic Burning ropes
behind each individual's comments and try your best to derive useful infonnat ion from
these comments. You have two ropes, each of which takes I hour to bum. But either rope has different
densities at different points, so there's no guarantee of consistency in the time it takes
Let D be the day of the month of A's birthday, we have De {1,2, 4,5, 7,8}. [f the different sections within the rope to bum. How do you use these two ropes to measure 45
birthday is on a unique day, C will know the A's birthday immediately. Among possible minutes?
Ds, 2 and 7 are unique days. Considering that you are sure that C does not k.now A's
birthday. you must infer that the day the C was told of is not 2 or 7. Conclusion: the Solution: This is a classic brain teaser question. For a rope that takes x minutes to bum,
month is not June or December. (lf the month had been June, the day C was told of may if you light both ends of the rope si multaneously, it takes xI 2 minutes to burn. So we
have been 2; if the month had been December, the day C was told of may have been 7.) should li ght both ends of the first rope and light one end of the second rope. 30 minutes
later, the first rope will get completely burned, while that second rope now becomes a
Now C knows that the month must be either March or September. He immediately
30-min rope. At that moment, we can light the second rope at the other end (with the
figures out ~·s birthday, which means the day must be unique in the March and
first end still burning). and when it is burned out, the total time is exactly 45 minutes.
September ltst. It means A's birthday cannot be Mar 5, or Sep 5. Conclusion: the
birthday must be Mar 4, Mar 8 or Sep I.
Among these tJ1rce possibilities left. Mar 4 and Mar 8 have the same month. So if the Defective ball
mont~ y~u have is ,Ma~ch. you still cannot figure out A's birthday. Since you can figure You have 12 identical balls. One of the balls is heavier OR lighter than the rest (you
out A s btrthday, A s btrthday must be Sep 1. Hence, the assistant must have written Sep don't know which). Using just a balance tbat can only show you which side of the tray is
1. 3
heavier, how can you determine which ball is the defective one with 3 measurements?

Card game Solution: This weighing problem is another classic brain teaser and is still being asked
by many interviewers. The total number of balls often ranges from 8 to more than l 00.
A l:asino offers a card game us· g
" .
1d k ·
· m a norma ec of 52 cards. The rule 1s that you tum Here we use n =12 to show the fundamental approach. The key is to separate the
~' clr two cards ea~h tune. For ca~h p.air, if both are black, they go to the dealer· s pile; if original group (as well as any intem1ediate subgroups) into_tht=-ee sets instead of' two. Th-e
1 reason is that the comparison of the first two groups always gives information about the
ot arc. red. the) go .to your ptle; tf one black and one red they are discarded The
p~occss IS repeated unttl you two go throuah all 52 ca d rf ' h .. I • • I third group.
p1le, you win $ 100· otherwi. . . :- r s. . you ave more car us m) our
negotiate the price. ou wa~'ie (mcludmg ties) you get notlung. The casino allows you to Considering that the solution is wordy to explain, I draw a tree diugram in Figure 2. 1 to
pay to play this gat:C•r t to pay for the game. How much would you be willing to show the approach in detail. Luhel the halls 1 through 12 and separate them to three
groups with 4 balls each. Weigh balls 1. 2. 3. 4 against balls 5. 6. 7. 8. Then we go on to
Solwion: This surely is an insidious . . N explore two possible scenarios: two groups balance. as expressed using an h_,, sign, or l ,
and the dc·tlcr will al~ h h casmo. 0 matter how the cards arc arranged. you
\.'ach pair ~f dis<.:arded ~~·~d a~'e t e same number of cards in your piles. Why? Because
• ' <It s ave one black card and one red card, so equal number of

·' I lint: Try to npproach the problem usin ' s mme .


What does that tl!ll you as 10 lhe number ~f~l k tl)'. Each dtsc;:arded pair has one black and one red card.
3
Hint: First do 1t for 9 1dentical balls and use only 2 measurements. knowing that one is ht:avi~:r than the
ac and red cards m the rest two piles? rest.

7
Brain Tca.-;crs
A Practical Guide To Quantitative Finance Interviews

2, 3, 4 are lighter than 5, 6, 7, 8, as expressed using an "<" sign. There is no need to


lighter, you can identify the defective ball among up to 3" balls using no more than n
explain the scenario that 1, 2, 3, 4 are heavier than 5, 6, 7, 8. (Why?")
measurernents si nce each weighing reduces the problem size by 2/3. If you have no
If the two groups balance, this immediately tells us that the defective ball is in 9, 10, II infonnati~n as to whether the ~efe~tive ball is heavier or lig~et•, you c~n ideotjfy the-
and 12, and it is either li ghter (L) or heavier (H) than other balls. Then we take 9, I 0 and defective ball among up to (3" -3)/2 balls using no more than n measurements.
ll from group 3 and compare balls 9, I0 with 8, 11. Here we have already figured out -- - --- - --- - -- -- --
that 8 is a normal ball. If 9, I 0 are lighter, it must mean either 9 or I0 is Lor 11 is H. In
which case. we just compare 9 with I0. If 9 is lighter, 9 is the defective one and it is L; if Trailing zeros
9 and I0 balance, then II must be defective and H; If 9 is heavier, 10 is the defective
one and it i:; L If 9, I0 and 8, ll balance, 12 is the defective one. If 9, 10 is heavier, than How many trailing zeros are there in 100! (factorial of I 00)?
either 9 or I0 is H, or 11 is L.
Solution: This is an easy problem. We know that each pair of 2 and 5 will give a trailing
You can easily follow the tree in Figure 2.1 for further analysis and it is cJear from the zero. If we perform prime number decomposition on all the numbers in l 00! , it is
tree that all possible scenarios can be resolved in 3 measurements. obvious that the freq uency of 2 will far outnumber of the freq uency of 5. So the
frequency of 5 determines the number of trailing zeros. Among numbers 1, 2, · · ·, 99, and
100, 20 numbers are divisible by 5 ( 5, I0, · · ·, I 00 ). Among these 20 numbers, 4 are
divisible by 52 ( 25, 50, 75, 100 ). So the total frequency of S is 24 and there are 24
trailing zeros.

Horse race
There are 25 horses, each of which runs at a constant speed that is different from the
112'J/4 L or 5/6/7/S 111
9/lD/11/12 L or H other horses'. Since the track only bas 5 lanes, each race can have at most 5 horses. If
@) - GV GV - ~
you need to find the 3 fastest horses, what is the minimum number of races needed to
identify them?
/ "l ~ /
9/J OL or 1111
•l ~ Solution: This problem tests your basic analytical skills. To find the 3 fastest horses,
surely all horses need to be tested. So a natural first step is to divide the horses to 5
1 2Lo~ 12H 9/I OH or II L

®-@ (!) -@ 0-@ groups (with horses 1-5,6-10, 11 -15, 16-20, 21-25 ,j n each group). After 5 races, we will
have the order within each group, let's assume the order fol~ows the order of numbers

ll \ I \ /! \
Ql. 111-1 IUL l2H 121. 1011 Ill. 911
(e.g .• 6 is the fastest and 10 is the slo'vvcst in the 6- 10 group f. That means I. 6, 11 , 16
and 21 arc the tastest within each group.
Surely the last two horses with in each group arc eliminated. What else can we infer? We
Figure 2.1 Tree diagram to identify the defective ball in 12 balls know that \-Vithin each group, if the fastest horse ranks 5th or 4tlil among 25 horses, then
all horses in that group cannot be in top 3; if it ranks the Jrd, no other horse in that group
In general if you have the inf0 · can be in the top 3; if it ranks the 2nd, then one other horse in that group may be in top 3;
_ -
--
~ m1at10n as to whether the defectivt:! ball is heavier or
- if it ranks the first, then two other horses in that group may be in top 3.

I lk~rc is whc_rc the symmetry idea comes in. Nothin' . . - . .


J. 4 al'i! hc(lm.·r than 5 6 7 g l'et' , J. h g makes the I. 2, 3. 4 or:>. 6, 7. 8 labels spec1al. II I, 2.
., · • · • · s ust exc ange the label50 f th . 5
Such an assumption doe~ not affect the generality of the solution. If the order is not as described, just
0 f I • ... 3. 4 bc1ng light~r than 5, 6. ?, 8 _ esc two groups. Agatn we have the case
change the labels of the horses.

8
9
.........,..

Brain Teasers
A Prc~ctical Guide To QuantiJaJive Finance Interviews

So lei's r~ce horses I. 6, II , 16 and 2 l. Again without loss of generality, let's assume
fit in the 62 squares left, so you cannot find a way to fill in all 62 squares without
the order IS I, 6, II . 16 and 21. Then we immediately know that horses 4-5 8-1 0 12-15
overlapping or overreachi ng.
16-20 an~ 21-25. are eliminated. Sinc.e l is fastest among aJI the horses, 1 j~ in. We need
to detcrmmc wh1ch two among horses 2, 3, 6, 7 and II are in top 3, which only takes one Removed
extra race.
So all together we need 7 races (in 3 rounds) to identify the 3 fastest horses.

Infinite sequence
If x ~'~ x ~'~ x~'~ x~'~ x ··· ::-:2, where x Ay =xY, what is x?

Solut_ion: This problem appears to be difficult. but a simple analysis will gi ve an elegant Removed +--
solutiOn. What do we have fro m the original equation?
limx "x~'>x~'~ xAx · .. =2¢:.> lim x~'~x~'~xA A _ Figure 2.2 Chess board with alternative black and white squares
II-+"Y -~ - n--+:.c - - - - -I......!.:...:. - 2 . ln other words, as n -> co,
n- 1 1erms
adding or minus one x A should yield the same result. Just as any good trading strategy, if more and more people get to know it and replicate it,
SO X A X 1\ X A X A X ... =X 1\ (X 1\ X A X A X .. -) = X 1\ L :: 2 ::::::>X:: J2. the effectiveness of such a strategy will disappear. As the chess board problem becomes
popular, many interviewees simply commit it to memory (after all, it's easy to remember
the answer). So some ingeni ous interviewer came up with the newer version to test your
thinking process, or at least your ability to extend your knowledge to new problems.
2.3 Thinking Out of the Box
If we look at the total volume in this 30 problem, 53 bricks have a volume of2 12, which
Box packing
is smaller then the box's volume 216. Yet we can show it is impossible to pack all the
Can you pack 53 bricks of dimensions I x Ix 4 into a 6 x 6 x 6 box? bricks into the box using a similar approach as the chess board problem. Let's imagine
that the 6 x 6 x. 6 box is actually comprised of small 2 x 2 x 2 cubes. There should be 27
So!wion: This is a nice problem extended fro small cubes. Similar to the chess board (but in 30), imagine that we have black c~bes
problem vou have a 8 x 8 chess b d . h m a popular chess board problem. In that and white cubes alternates--it does take a little 30 visualization. So we have either 14
corners ;.;moved You have n1.a oba~ kWJt . two small squares at the opposite dia~onal black cubes & 13 ,,1lite c~bcs or 13 black cubes & 14 white cubes. For any_! xI x 4_ brick
. . . ny TIC ' S wuh dimens· l 2 C -.
Into the remaining 62 squares? (A 1 . JOn x · an you pack 3 I bncks tt.lat we pack j nto.J!!e box. half (~x I x 2J_of i,t_must be in .~ black 2 x 2 x 2 cube ~ ~ tl!e
. . n a tcrnattve question . , h h 62
squares usmg bricks without an b . k . . . IS w et er you can cover all other half must be in (~ white 2 x 2 x 2 cube. The problem is that each 2 x 2 x 2 cube can
the board, which requires a simt'l: ncl s ?vcrlappmg wtth each other or sticking out of orily be -used by 4 of the 1x 1x 4 bricks. So for the color with 13 cubes, be it black or
ctr ana ysts.)
white, we can only use them for 52 I x 1x 4 tubes. There is no way to place the 53th
~real chess ~oard figure surely he! s the v· ' . . . . .
chess. boa~d IS filh!d with alternat~ve bJa~~uahzatJOn_. As shown m F~gure 2.2, when a brick. So we cannot pack 53 bricks of dimensions 1x 1x 4 into a 6 x 6 x 6 box.
o~pos1tc <hagonal corners have the same c an~ whue squares, both squart:s at the
01
Will always cover one black uare or: ~t you put a I x 2 brick on the board, it
corner squares were removtdih ~nd one whne square. Let's say it's the two black Calendar cubes
wco only have 30 black squar'es el ~ t-e !:_de_!t of the. board can fit at most 30 bricks since You just had two dice custom-made. Instead of numbers 1 - 6, you place single-digit
e.t lan each 6i~ -k · - - -
Prtck J I bncks is out of the •.5 1.- nc reqUi res one black square). So to numbers on the faces of each dice so that every morning you can arrange the dice in a
ov .. ·h· qu..:: JOn, To cover all 62 . .
errc.lc mg. we must have exactly 31 b . k squares without ovcrlappmg or way as to make the two front faces show the current day of the month. You must use
nc s. Yet we have proved that 3 1 bricks cannot both dice (in other words, days 1 - 9 must be shown as 0 1 - 09), but you can swi tch the
10
II
Brain Teasers
-
A Practical Guide To Quantitative Finance Interviews

order of the .dice if y~u want. What numbers do you have to put on the six faces of each direct quest ion does not help us solve the problem. The key is to involve both guards in
of the two dtce to achieve that?
the questions as the popular answer does. For scenario l, if we happen to choose the
truth teller, he will answer no si nce the liar will say no; if we happen to choose the liar
Solution.:. The d~y~ of a month include II and 22~ so both dice must have 1 and 2. To
guard, he will answer yes since the truth teller wi!J say no. For scenario 2, if we happen
express smgle-?tgl~ days, we need to have at least a 0 in one dice. Let's put a 0 in dice
to choose the truth teller, he will answer yes since the liar will say yes; if we happen to
~ne first. Con~t~enng that we need to express all single dioit days and dice two cannot
choose the liar guard, he will answer no since the truth teller with say yes. So for both
lave all 1he.dtgtts ~r~m I - 9, it's necessary to have a 0 in°dice two as well in order to
express a11smgle-dtglt days. scenarios, if the answer is no, we choose that door; if the answer is yes, we choose the
other door.
So far we have assigned the following numbers:
-
Dice one I 2 0 ? Message delivery
? ?
Dice two I
1 2 0 '? You need to communicate with your colleague in Greenwich via a messenger service.
I
? ?
Your documents are sent in a padlock box. Unfortunately the messenger service is not
If we can ass1gn all the rest of cltgits 3 4 5 6 7
problem is solved. But there are 7 di. its' I ft Wl '8, and 9 to the rest of the faces, the secure, so anything inside an unlocked box will be lost (including any locks you place
think out of the box We c g e · . lat can we do? Here's where you need to inside the box) during the delivery. The high-security padlocks you and your colleague
time! So simply p, ~~ 3- 4 an dus5e a ~!IS~ ~ smce they will never be needed at the same each use have only one key which the person placing the lock owns. How can you
• ' • ' an on one dtcc and 6 7 . d 8 ·- . securely send a document to your colleague?6
tmarnumbers on the two dice are: • • an on the other dLce, and the
Solution: If you have a document to del iver. clearly you cannot delive r it in an un locked
Dice one I 2 0 3 4 5 box. So the first step is to deliver it to Greenwich in a locked box. Since you are the
Dice two I 2 person who has the key to that lock, your colleague cannot open the box to get the
0 6 7 8 document. Somehow you need to remove the lock before he can get the document,
which means the box should be sent back to you before your colleague can get the
Door to offer document.
Y?t~ are facing two doors. One leads to ·our ·o So what can he do before he sends back the box? He can place a second lock on the box,
ot either door is a guard. One guard al~a ·s J b o!fer and the other leads to exit. In fron t which he has the key to! Once the box is back to you, you remove your own lock and
You can only ask one guard one yes/ Y te~ls ltes and the other always tells the truth. send the box back to your colleague. He opens his own lock and gets the document.
ofler. what question will you ask? · no question. Assuming you do want to get the job

Solution: This is another classic b . Last ball


One popular answer is to ask ram teaser (maybe a little out-of-da te in my opinion).
· , 0 ne guard· '" W ld h A bag has 20 blue balls and 14 red balls. Each time you randomly take two balls out.
guardmg th~ door to the offer'"' If h . · ou t e other guard say that you are
no' c I1oosc tI)C door this ''uard .is t ed'answers yes (Assume each ball in the bag has equal probabil ity of being taken). You do not put these
• choose the other door; if he answers
5 an tng .m front of
.• e. two balls back. lnstt::ad, if both balls have the same color, you add a blue ball to the bag;
1here ure two possible scenarios: if they have different colors, you add a red ball to the bag. Assume that you have an
unlimited supply of blue and red balls~ if you keep on repeating this process, what will
l. lruth tdler guards the door toot . . .
2. l h Ter. Liar ~ruards the door to exit be the color of lhe last ball left in the bag?7 What if the bag has 20 blue balls and 13 red
nu teller guards the door to exit· Liar . balls instead?
lf we ask a I.!Uard ad ' • ' guards the door to offer.
. ~ Jrcct quesuon such as ,, A
scenano I· both guards will answer yes· fi re yo.u guarding the door to the offer?" For 6
Hint : You can have more than one lock oo the box.
7
' or scenano 2, both guards wi ll answer no. So a Hint : Consider the changes in the number of red and blue balls after each step.

13
Broin Teasers
A Practical Guide To Quantitative Finance Interviews

So!Uiion: Once you understand the hint, this problem should be an easy one. Let (8 , R) Quant salary
represent the number of blue balls and red balls in the bag. We can take a look what will
happen after two halls are taken out. Eight quants fro m different banks are get1ing together for drinks. They are all interested
in knowing the average salary of the group. Nevertheless, being cautious and humble
Uoth balls are blue: ( B, R) ~ ( B -I. R) individuals, everyone prefers not to disclose his or her own salary to the group. Can you
Both balls are red : ( R. R) ~ (8 + 1, R- 2) come up with a strategy for the quants to calculate the average salary without knowi ng
other people's salaries?
One red and one blue: (B. R) ~ ( B -l,R)
Solution: This is a light-hearted problem and has more than one answer. One approach is
Notice that R either stays the same or decreases by 2, so the number of red balls will for the first quant to choose a random nwnber, adds it to his/her salary and gives it to the
never become odd if we begin with 14 red balls. We also know that the total number of second quant. The second quant will add his/her own salary to the result and give it to
balls decreases by one each time until only one ball is left. Combining the information the third quant; ... ; the eighth quant will add his/her own salary to the result and give it
we have. the last ball must be a blue one. Similarly, when we start with odd number of back to the first quant. Then the first quant will deduct the "random" number from the
red balls. the tina! ball must be a red one. total and divide the "real" total by 8 to yield the average salary.
You may be wondering whether this strategy has any use except being a good brain
Light switches teaser to test interviewees. It does have applications in practice. For example, a third
party data provider collect fund holding position data (securities owned by a fund and
There is a light bulb inside a _room and four switches outside. All switches are currently the number of shares) from all participating firms and then distribute the information
at ?ff state and only one swttch controls the light bulb. You may turn any number of back to participants. Surely most participants do not want others to figure out what they
~wttches on or off any number of times you want. How many times do you need to go are holding. If each position in the fund has the same fund ID every day, it's easy to
nlto the room to figurt~ out which switch controls the light bulb? reverse-engineer the fund from the holdings and to replicate the strategy. So different
random numbers (or more exactly pseudo-random numbers since the provider knows
~ol.lllion: You may have seen the classical version of this problem wi th 3 light bulbs what number is added to the fund ID of each position and complicated algorithm is
tns1de the.room and 3 switches outside. Although this problem is slightly modified the involved to make the mapping one to one) are added to the fund ID of each position in
approach ts exact the same Whethe th 1· h · · · · '
. . . · r e tg t IS on and off 1s bmary whtch only allows the funds before distribution. As a result, the positions in the same fund appear to have
us to dtsiJngUish two switches. If we have another b' c: ' h 2 2 4
- "bl · · mary 1actor t ere are x = different fund IDs. That prevents participants from re-constructing other funds. Using
poss1 c combmatlons of scenarios · d. · · · ' ·
r.,J b lb 1 . · ·' so we can tstmgu1sh 4 swttches. Besides hoht, a this approach, the participants can share market information and remain anonymous at
J&&ll u a so em1ts heat and becomes hot after th b lb h b · " · 0 ,
we can use the on/olf and c0 ld/h . . ·e ~ a~ een ht 10r some t1me. So the same time.
\!On trois the 1ight. ot combmatJOn to dec1de which one of the four switcihes

· ~·urn on switches I and 2: move 00 to solve s • ., 2.4 Application of Symmetry


tor a whi le· turn off sw't ·h ? d .orne other puzzles or do whatever you hke
bulb and ohserve whetltel cth~ ~~nl ~~m on SWitch 3~ get into the room quickly, touch the Coin piles
· r e 1g 1t IS on or off.
:l:he l~ght bulb is on and hot-+ switch l controls the light; Suppose that you are blind-folded in a room and are told that there are I000 coins on the
floor. 980 of the coins have tails up artd the other 20 coins have head s up. Can you
l~ght bulb is otr and hot - switch 2 controls the light;
.I he separate the coins into two piles so to guarantee both piJes have equal number of heads?
fhc l~ght bulb is on and cold-+ switch 3 controls the light; Assume that you cannot tell a coin,s side by touching i t~ but you are allowed to tum over
any number of coins.
The light bulb i::; ofl~ and cold - switch 4 controls the light.
Solution: Let's say that we separate the lOOO coins into two piles with n coins in one pile
and 1000- 11 coins in the other. If there are m coins in the first pile with heads up, there

14
15
Brain Teasers
A Practical Guide To Quantitative Finance Interviews

must be 20-m coins in the second pile with heads up. We also know that there aJ:e Wise men
n- m coins in the first pile with tails up. We clearly cannot guarantee that m =I0 by
simply adjusting n. A sultan has captured 50 wise men. He has a glass currently standing bottom down.
Every J11inute he ca lls one of the wise men who can choose either to turn it over (set it
What other options do we have? We can turn over coins if we want to. Since we have no upside down or bottom down) or to do nothing. The wise men will be called randomly,
way of knowing what a coin's side is, it won't guarantee anything if we selectively flip possibly for an infinite number of times. When someone called to the sul tan correctly
coins. However, if we tlip all the coins in the first pile, all heads become tail s and all s tates that aJI wise men have already been called to the sultan at least once, everyone
tails become heads. As a result, it will have n-m heads and m tails (symmetry). So, to goes free. But if his statement is wrong, the sultan puts everyone to death. The wise men
start. we need to make the number of tails in the original first pile equal to the number of are allowed to communicate only once before they get imprisoned into separate rooms
heads in the second pile~ in other words, to make n- m =20-m. n = 20 makes the (one per room). Design a strategy that lets the wjse men go free.
equation hold. lf we take 20 coins at random and turn them all over, the number of beads
among these turned-over 20 coins should be the same as the number of heads among the SoLwion: For the strategy to work, one wise man, let's call bim the spokesman, will state
other 980 coins. that evety one has been ca lled. What does that tell us? 1. All the other 49 wise men are
equivalent (sy mmetric). 2. The spokesman is different from the other 49 men. So
naturally those 49 equivalent wise men should act in the same way and the spokesman
Mislabeled bags
should act different ly.
You are_given three bags of fruits. One has apples in it; one has oranges in it; and one Here is one of such strategies: Every one of the 49 (equivalent) wise men should flip the
has .a m1x of apples and oranges in it. Each bag has a label on it (apple, orange or mix). glass upside down the first time that he sees the glass bottom down. He doe s nothing if
Un_tortu_nately. your mana~cr tells you that ALL bags are mislabeled. Develop a strategy the glass is already upside down or he has fl ipped the glass once. The spokesman should
to~ tde~ltJfy the hags by takmg out minimum number of fruits? You can take any number flip the glass bottom down each tjme he sees the glass upside d ow~ and ~e should do
ot fnn ts from any bags. 8 nothing if the glass is already bottom down. After he does the 491h f11~, wh1ch means all
the other 49 wise men have been called, he can declare that all the w1se men have been
So!uJiun: Thc.key here is to usc the tact that ALL bags are mislabeled. For example, a called.
ba·g' labeled wtth apple must contain either oranges only or a mix of oranges and apples.
Let s look at the labels: orange. apple, mix (orange+ apple). Have you realized that the
0
~~ge !a~l and the apple ~abel are synunctric? lf not, let me explain it in detail: If you 2.5 Series Summation
pick a l':lut _from the bag wtth the orange label and it's an apple (orange ~ apple) then
the bag 1s etther all apples o · · If , · k · ~ · ' Here is a famous story about the legendary mathematician/physicist Gauss: When he
. ;-- r a tmx. ) ou pte a fruit from the bag with the apple label
and It s an orml''e (apple ~ 0 a ) th h . . . was a chi ld, his teacher gave the chi ldren a boring assignme_nt t~ add the n~mbers from I
. o r nge , en t e bag IS etther an orange bag or a mtx.
th
Symbmctn~ labels a:e not exciting and are unlikely to be the correct approach So let's u·v to 100. To the amazement of the teacher, Gauss turned m h1s answer m less than a
t: ag WJth the m1:x label and get 1· · r. · · • minute. Here is his approach:
. k . h b .· one nut •rom tt. If the fruit we get is an orange then
''e ncm· t at ag 1s actually or·1 , (I · · l
know tht: bag's lab;! ·, ) ·~~e t cannot be a mtx of oranges and apples since we 100

it must be th~ mix ~: wr~n~ . , mce the ?ag with the apple label cannot be apple only. In =I + 2+ ···+ 99+ 100}
Similarlv fo r the c~sc tgha. t n l the b~g wtth the orange label must be the apple bag. , ,1
100
I + + + .:::::::>
· 1b 1 II
··
the bags using one single pick.
app es are m the bag, w'th1 th fi
e mtx a c, we can tgure out a L n = 100 + 99 + ··· + 2 + I
;·~: ~ ~ ~ ~ ' 00 100 x I 0 I
2L n = 10 I + J0 l + ··· + l 0 I + I 0 1= I 01 x 100 ~ L n =
"~ d-1
2
.,,~ pmbl~m stntck OH: a~ a word game when I fi . .
details besides his or her logic reasoning skills. trst saw tt. But tt does test a candidate's attention to

16
17
Brain Tcasers
A Practical Guide To Quantitative Finance Interviews

.,,. f N(N +1)


I us approach can be generalized to any integer N: L,; n =----'' -'- Solution: Denote the missing integers as x and y, and the existing ones are z1, ••• , z98 .
n=1 2 Applying the summation equations, we have
Tht! summation formula for consecutive squares may not be as intuitive: 100
t 00 X I 01 98
')S
L:n =x+ y+ L,z, => x+ y = Iz,
'f 11
: = N(N + 1)(2N + I) = N 3 + N 2 + N. n= l
100
t;l
98
2
3
t=l

6 3 2 6 100 I 00 2 I00 98
"1
L,n =x 2 2 2
+y + I z; 2
=> x +y
2 2
=--+--+- -
3 2 6 ,.,
L,z,- ,

But if we correctly guess that "n = aN + b


N

~
2 3
u 2 + eN + d
1•v an d app 1y t he ·tmtta
··1
,.1 t:1

Using these two equations, we can easily solve x and y. If you implement this strategy
conditions using a computer program, it is apparent that the algorithm has a complexity of O(n) for
Jv;: O=:> o=d two missing integers in 1 ton .
N - I=:> 1=u+b+c+d
A = 2 =:> 5 -= 8a + 4b + 2c + d , Counterfeit coins I
1\ = 3 ~ 14 =27a+9b+3c+d
There are l 0 bags with I 00 identical coins in each bag. In all bags but one, each coin
weighs 10 grams. Howeve(, all the coins in the counterfeit bag weigh either 9 or 11
we
tl will
th --have the solution
· that - 0 · we can then east·1y show
. a = 1/3 ' b ==- 1/?-, c = 1/6, d- grams. Can you find the counterfeit bag in only one weighing, using a digital scale that
lat e same equation apphes to all N by induction.
tells the exact weight? 9

Clock pieces Solwion: Yes, we can identify the counterfeit bag using one measurement. Take I coin
out of the first bag, 2 out of the second bag, 3 out the third bag, · · ·, and I 0 coins out of
A clock (numbered 1 - p clockwis ) f ff h
find that the sums of the n~tmbers e ~11 ~ t e wall and broke into three pieces. You
10

(l,.'o strange 'h ~A •


the tenth bag. All together, there are L n = 55 coins. f f there were no counterfeit coins,
Piece?· ,.,. • on each ptece are equal. What are the numbers on each
-s apcu ptece IS allowed.) i~1

they should weigh 550 grams. Let's assume the i-th bag is the counterfeit bag, there will
Solwion: Using the summation equati ~ _ 12x l3 be i counterfeit coins, so the final weight will be 550 ± i. Since i is distinct for each bag,
. on, ~n -
2
=78. So the numbers on each we can identify tbe counterfeit coin bag as well as whether the counterfeit coins are
ptt:C(' must sum up to ?6 Some interv· . lighter or heavier than the .real coins using 550 ± i.
each piece have to be C~lt·t.ntto b tcwees fhlstakenly assume that the numbers on
us ecause no strange sh d · ·
sec that 5. 6, 7 and 8 add up to 26 Th th . : ape p1ece IS allowed. It's easy to This is not the only answer: we can choose other numbers of coins from each bag as long
they cannot find more consccut"•ve · been e mtervtewees' thinking gets stuck because as they are all different numbers.
num rs that add up to 26.
Such an assumption is not correct since 12 .
'HOng assumption is removed 't be and 1 are contmuous on a clock. Once that Glass balls
sc(ond pice(! is 11. 12 1 'llld 2 .·t~" th~odm~s cl~ar that 12 + 1= 13 and ll + 2 = 13. So the
• ' ' e Ir ptece IS 3, 4, 9 and 10. You are holding two glass balls in a 100-story building. If a bal! is .thrown out of th.e
window, it will not break if the tloor number is Jess than X, and 11 wtll always break 1f
Missing integers
SupJX)SC we have 98 distinct integers fJ I 9
Hint: In order 10 find the counterfeit coin bag in one weighing. the number of coins trom each bag must
two missing intt!gers twithin [I. lOOJ)?rom to IOO. What is a good way to find out the be different. If we use the same number of coins from two bags, symmetry will prevent you from
distinguish these two bags if one is the counterfeit coin bag.
18
19
Brain Teasers
A Practical Guide To Quantitative Fi nance Interviews

the floor number is equal to or greater than X. You would like to detennine X. What is
the strategy that will minimize the number of drops for the worst case scenario? 10
Matching socks
Your drawer contains 2 red socks, 20 yellow socks and 3 I blue socks. Being a busy and
Solution: Suppose that we have a strategy with a maximum of N throws. For the first absent-minded MIT student, you just random ly grab a number of socks out of the draw
tl~r.ow of ball one, we can try the N-th floor. r f the ball breaks, we can start to try the and try to find a matching pair. Assume each sock has equal probability of being
~c~~>,~d ~II from the first floor and increase the floor number by one un tiI the second selected, what is the minimum number of socks you need to grab in order to guarantee a
a re s. At most, there are N- 1 floors to test. So a maximum of N throws are pair of socks of the same color?
enough to cover all possibilities. If the first ball thrown out of N-th floor does not break
we hnvc N - I. throws 1e ft · Th'IS ttme
· we can only increase the floor number b N -I for' Solution: This question is just a va riation of the even simpler version of two-color-socks
:~: ~;;: ~::: ~~~:.~h~u~e~~(~~N~~)II ~~ only cover N- 2 floors if the fi rst balr breaks. ff problem, in which case you only need 3. When you have 3 colors (3 pigeon holes), by
the Pigeon Hole Principle, you will need to have 3 + 1 = 4 socks (4 pigeons) to guarantee
. . - t oor does not break, we have N- 2 throws left So
w~ can on 1Y tncrease the floo b b N · that at least two socks have the same color (2 pigeons share a hole).
can only cover N- 3 0 'frhnufim er Y -2 for the first ball since the second ball
oars t I e 1rst ball breaks ...
Using such logic, we can see that the n b 0 f
with a mnximurn of N thro . N ( H urn er floors that these two balls ca n cover Handshakes
WSJS + /v-1)+· .. +1-N(N+l) / 2 l d 00
stories. we need to have N(N + > . - · n or er to cover l You are invited to a welcome party with 25 fellow team members. Each of the fellow
. 2
l)/ - 100 · Tak,ng the smallest integer, we haveN =14 . members shakes hands with you to welcome you. Since a number of people in the room
Bastcally. we start the first ball on the 14 h t1 . haven' t met each other, there's a lot of random handshaki ng among others as wel l.lfyou
st:cond ball to try floors 1 2 .. . lJ with t . oor, tf the ball breaks, we can use the don)t know the total number of handshakes, can you say with certainty that there are at
14th floor is X). If the fl~t ball
doe a maxtmum throws. of 14 (when the l3th or the least two people present who shook hands with exactly the same number of people?
14+(14-1)=27th floor. If it breaks s w:Ot break) we wtll try the first ball on the
15, 16, .. . 26 with a total . h, can use the second ball to cover floors Solution: There are 26 people at the party and each shakes hands with from 1-since
, maxunum t rows of 'l 4 as well everyone shakes hands with you- to 25 people. In other words, there are 26 pigeons and
25 holes. As a result, at least two people must have shaken hands with exactly the same
number of people.
. 2. 6 The Pigeon Hole Principle
Here ts the basic version of th p· .
1 ptgcons• e tgeon Hole Pnnc·1 1 • ·r
t1an and vou put every · . . P c. J you 11ave fewer pigeon holes Have we met before?
, t .- p~geon m a ptgeon h0 1 th .
more t 1an nne ptucon Basicall . e, en at least one ptgeon hole has
· ,.. c · Y tt says that if 1, , Show me that, if there are 6 people at a party, then either at least 3 people met each other
ptgcons. at least 2 pigeons have to ·t . . you la\ c n holes and more than n + I
1.f ) .nu I1avc n holes and at least s tate one ot the I10I Thc generalized
. before the party, or at least 3 people were strangers before the party.
. es. version is that
0 f t1lC, holes. ·1•hese sitnple and · mn· +· I ptgeons
.~ ' a t Ieast m + 1 ptgcons
· have to share one
H.. • . tntlllttve tdeas ar · . Solution: Thls question appears to be a complex one and interviewees often get pul./.kd
. cr~:: \\t' will usc some exarnples to sl th . e s.urp~tsmgly useful in many problems. by what the interviewer exactly wants. But once you start to anaJyze possible scenarios,
lOw etr apphcatJOns.
the answer becomes obvious.
Let's say that you are the 6th person at tht: party. Then by generalized Pi geon Hole
Principle (Do we even need that for such an intuitive concJusion?). among the remaining
5 people, we conclude that either at least 3 people met you or at least 3 people did not
meet you. Now let's explore these t'.\'O mutually exclusive and collectively exhausti ve
1(111'
lilt: Assume we desiun a st . t . scenarios:
b.111 ~an t·ovcr N - I tl ~ ... ra c~y wtrh N maximum throws If I ti .
oors, •I the first ball is thro . . t le lrst ball IS thrown once the s~cond Case I: Suppose that at least 3 people have met you before.
Wll IWICC the db •
, secon all can cover N - 2 floo rs ...
20
21
Brain Teasers
A Practical Guide To Quantitative Finance Interviews

If two people in this group met each other, you and the pair (3 people) met each other. If we only use 2 coins from bag 2, the final sum for I coin from bag 1 and 2 coins from
no pair among these people met each other, then these people (> 3 people) did not meet bag 2 ranges from -3 to 3 (7 pigeon holes). At the same time we have 9 (3x3) possible
each other. In either sub-case, the conclusion holds.
combinations for the weights of coins in bag 1 and bag 2 (9 pigeons). So at least two
Case 2: Suppose at least 3 people have not met you before. combinations will yield the same final sum (9)7, so at least two pigeons need to share
one hole), and we can not distinguish them. If we use 3 coins from bag 2, then. the sum
If two people in this group did not meet each other, you and the pair (3 people) did not
ranges from -4 to 4, which is possible to cover all 9 combinations. The following table
meet each other. If all pairs among these people knew each other, then these people (;:::3
exactly shows that all possible combinations yield different sums:
people) met each other. Again, in either sub-case, the conclusion holds.
Sum t coin, bag 1

• I~
Ants on a square N -I 0 1

There are 51 ants on a square with side length of 1. If you have a glass with a radius of
"
CO -I -4 -3 -2
,;;
117, can you put your glass at a position on the square to guarantee that the glass c
'0 0 -I 0 1
encompasses at least 3 ants?'! U
~
1 2 3 4
Solu'io~: To guarantee that the glass encompasses at least 3 ants, we can separate the eland C2 represent the weights of coins from bag 1 and 2 respectively.
square mto 25 smaller areas. Applying the generalized Pigeon Hole Principle we can
show that at least one of the areas must have at least 3 ants. So we only need' to make Then how about 3 bags? We are going to have 33 = 27 possible combinations. Surely an
sure that. the glass is large enough to Cover any of the 25 smaller areas. Simply separate indicator ranging from -13 to 13 will cover it and we will need 9 coins from bag 3. The
the .area Into 5 x 5 smaller squares with side length of 1/5 each will do since a circle with possible combinations are shown in the following table:
radius of 1/7 can cover a square'? with side length 115.
Sum C2 -I C2=O C2 1

Counterfeit coins II
~
"
ee
CO
I~ -t 0 1 -I 0 1 -I 0 1

-I -13 -12 -II -10 -9 -8 -7 -6 -5


,;;
There are 5 bags with ~00 c~ins in each bag. A coin can weigh 9 grams, 10 grams or II c
'0 0 -4 -3 -2 -I 0 1 2 3 4
U
~r::s~~n~~~~a~ contain, cOl.n~of equal weight, but we do not know what type of coins ~
1 5 6 7 8 9 10 II 12 13
ti g d . au have a digital scale (the kind that tells the exact weight). How many
trues 0 you need to use the scale to d t ' hi 13
C 1, C2, and C3 represent the weights of coins from bag!, 2, and 3 res p ectiveiy .
e ermine w Ich type of coin each bag contains?
Solution: If the answer for 5 ba s is b . Following this logic, it is easy to see that we will need 27.coins from bag 4 and 81 coins
the problem-1 b WIg not 0 vlQus,.let's start with the simplest version of from bag 5. So the answer is to take 1, 3, 9.' 27 and 81 corns ~rom bags 1,.2,3, 4, ~n~ 5,
2 bags Ho ag.. e °dny need to take one com to weigh it. Now we can move on to respectively, to determine which type of cams each bag contams using a single weighing.
. w many cams a we need to tak f b ' ,
types of bag 1 and bag 2? C '. e rom ag 2 In order to determine the com
will need three coins fr~m ~nsli~nng tha~ there are three possible types for bag I, we
change the number/weight forat~re~ ~wo cOIn_Swon't do. For nota~ion simplicity, let's 2.7 Modular Arithmetic
ypes to I, 0 and I (by removing the mean 10), If
The modulo operation----<lenoted as x%y or x mod y-finds th~ remainder of divisio~ of
11

12 m~:Separate the square into 25 smaller areas' h number x by another number y. For simpicility, we only consider the case where! Is.a
A circle with radius r can cover a square ith "d' en at least one area has 3 ants in it.
"H' S . ..WI 51 e length t r: d positive integer. For example, 5%3 = 2. An intuitive property of modulo operation IS
mt: tart with a simpl" problem Wh t 'f up 0 ....2 r an Ji » 1.414.
d . alyouhavetwb f"
you nee from each bag to find the ty f . . . 0 ags 0 coins Instead of 5 how many coins do
num ers:'Th en how about three bags? pea Comsmeltherb ago'Wh' at IS the rmrumurn
b .. ' difference In
.' com

22
23
Brain Teasers
A Practical Guide To Quantitative Finance Interviews

that if XI%Y=X2%Y, then (XI-X2)%y=O. From this property we can also show that the rest of 99 prisoners and calculates s%3. If the remainder is 0, he announces red; if
the remainder is I, green; 2, blue. He has 1/3 chance of living, but all the rest of the
x%y, (x+l)%Y, "', and (x+y-I)%y are all different numbers.
prisoners can determine his own score (color) from the remainder. Let's consider a
prisoner i among 99 prisoners (excluding the first prisoner). He can calculate the total
score (x) of all other 98 prisoners. Since (x+0)%3, (x+I)%3, and (x+2)%3 are all
Prisoner problem
different, so from the remainder that the first prisoner gives (for the 99 prisoners
One hundre.d prisoners are given the chance to be set free tomorrow. They are all told including i), he can determine his own score (color). For example, if prisoner l sees that
hat each wII~be given a red or blue hat to wear. Each . ner can see everyone else's there are 32 red, 29 green and 37 blue in those 98 prisoners (excluding the first and
at but not hIS own. The hat colors are assigned randomly an nee the hats are placed himself). The total score of those 98 prisoners is 103. If the first prisoner announces that
on top of eac~ priso~er's head they cannot communicate with one other in any form, or the remainder is 2 (green), then prisoner i knows his own color is green (1) since
else t~ey are ImmedIatel~ executed. The prisoners will be called out' n random order and onlyI04%3~2 among 103, 104 and 105.
t~ehPnsonerhcalledout will guess the color of his hat. Each prisoner eclares the color of
hi s at so t at everyone else can hear it If . Theoretically, a similar strategy can be extended to any number of colors. Surely that
h he i '. I. a pnsoner guesses correctly the color of his
at, e IS set free Immediately; otherwise he is executed. requires all prisoners to have exceptional memory and calculation capability.

They
. are given the. night to come
. up WIith a strategy among themselves to save as many
pnsoners as POSSI ble What IS the b t t h
can they guarantee to's ?14 es s rategy t ey can adopt and how many prisoners Division by 9
ave.
Given an arbitrary integer, come up with a rule to decide whether it is divisible by 9 and
Solution: At least 99 prisoners can be saved. prove it.
The key lies in the first prisoner wh
be red if the number of red hats he a ca? see everyone.else's hat. He declares his hat to Solution: Hopefully you still remember the rules from your high school math class. Add
He will have a 1/2 chance f h . sees IS odd. Otherwise he declares his hat to be blue. up all the digits of the integer. If the sum is divisible by 9, then the integer is divisible by

0;
his Own hat color combin~ng :~m~gue~sed correctly. Everyone else is able to deduce 9; otherwise the integer is not divisible by 9. But how do we prove it?
among 99 prisoners (excludi e h edge whether the number of red hats is odd I
Let's express the original integer as a == a" 10" + Q,,_IIO"-I+ ... + QIIO + Qo' Basically we
(excluding the first and hims:~ F e irst) and the color of the other 98 prisoners
the other 99 prisoners A prison' or example, if the number of red hats is odd among state that if a" +Q,,_I+···+al +ao =9x (x is a integer), then the Q is divisible by 9 as
th h . er weanng a red hat will . well. The proof is straightforward:
e ot er 98 prisoners (excludi th fi 1 see even number of red hats III
red hat. mg e irst and himself) and deduce that he is wearing a 1
For any a=a"IO"+Q,,_110"-1+"'+QII0 +Qo' let b=a-(Q,,+a"_I+'''+QI+ao)' We
Th~ two-color case is easy, isn't it? What if . have b~a,.(10"-I)+a"_,(10"-'-I)+···+a,(lO'-I)~a-9x, which is divisible by 9
white? What is the best strategy the there are 3 possible hat colors: red, blue, and
guarantee to save?IS y can adopt and how many prisoners can they since all (10k -1), k = 1,·· ',n are divisible by 9. Because both band 9x are divisible by 9,
a = b + 9x must be divisible by 9 as well.
Solution: The a~swer is still that at least 99" . (Similarly you can also show that a = (-I)" a" + (-Ir-
l
Q,,_I+ ... + (-IYal + ao = lIx is the
that. the first prisoner now only has 113 pnsoners wl~1be saved. The difference IS
sconng system: red===Ogreen«] d bl _chance of survival. Let's use the following necessary and sufficient condition for a to be divisible by 11.)
, , an ue-2. The first prisoner counts the total score for
;;"-:-H::-' --------
tnt: The first prisoner can h
odd number of c see t e number of red and blu h
IS H' t: Th ounts and the other has even numb feats of all other 99 prisoners. One color has
mt: at a number is odd sim I er 0 counts.
x%3 instead p y means x%2 = 1. Here we h
. ave 3 colors, so you may want to consider

24
25
Brain Teasers A Practical Guide To Quantitative Finance Interviews

Chameleon colors (3x + 2,3y,3z + I) = (3x',3y'+ 1,3z'+ 2), one y meets one z
A remote island has three types of chameleons with the following population: 13 red (3x, 3y + 1,3z + 2) => (3(x -I) + 2,3(y + 1),3z + I) = (3x ',3y '+ I, 3z'+ 2), onex meets one z
chameleons, 15 green chameleons and 17 blue chameleons. Each time two chameleons {
(3(x -1) + 2,3 y, 3(z + I) + I) = (3x',3 y'+ I,3z '+ 2), onex meets one y
with different colors meet, they would change their color to the third color. For example,
if a green chameleon meets a red chameleon, they both change their color to blue. Is it
ever possible for all chameleons to become the same color? Why or why not?16 So the pattern is preserved and we will never get two colors to have the same module of
3. In other words, we cannot make two colors have the same number. As a result, the
Solution: It is not possible for all chameleons to become the same color. There are chameleons cannot become the same color. Essentially, the relative change of any pair of
several approaches to proving this conclusion. Here we discuss two of them. colors after two chameleons meet is either 0 or 3. In order for all the chameleons to
Approach 1. Since the numbers 13, 15 and 17 are "large" numbers, we can simplify the become one color, at least one pair's difference must be a multiple or 3.
problem to 0, 2 and 4 for three colors. (To see this, you need to realize that if
combination (m+I,n+l,p+l) can be converted to the same color, combination
(m,n,p) can be converted to the same color as well.) Can a combination (0,2,4) be
2.8 Math Induction

30
converted to a combination (O,0,6)? The answer is NO, as shown in Figure 2.3: Induction is one of the most powerful and commonly-used proof techniques in
mathematics, especially discrete mathematics. Many problems that involve integers can
be solved using induction. The general steps for proof by induction are the following:
(0,2,4). • (I, 2, • State that the proof uses induction and define an appropriate predicate P(n).

• Prove the base case P(I), or any other smallest number n for the predicate to be true.
~(O, 1,5)~
• Prove that P(n) implies P(n+l) for every integer n. Alternatively, in a strong
Figure 2.3 chameleon color combination transitions from (0,2,4) induction argument, you prove that P(l), P(2), "', and P(n) together imply
P(n+I),
Actually combination (1,2,3) is equivalent to combination (0,1,2), which can only be In most cases, the real difficulty lies not in the induction step, but to formulate the
converted to another (0, I, 2) but will never reach (0,0,3), problem as an induction problem and come up with the appropriate predicateP(n). The
AIPIPhroachh2. A different, and more fundamental approach is to realize that in order for simplified version of the problem can often help you identify P(n).
ate c ameleons to become th I ' :
e same co or, at certain intermediate stage two colors
h
must ave the same number T thi . . '
must h th bi . 0 see IS, Just imagme the stage before a final stage. It Coin split problem
as e com inatton (1,I,x). For chameleons of two different colors to have the
same number their module f'" b You split 1000 coins into two piles and count the numb~r of coins in each pile. If there
13 3' 0 .} must e the same as well. We start with 15:::: 3x,
= y+l, and 17=3z+2 cham I h are x coins in pile one and y coins in pile two, you multiple x by y to get -'Y. Then you
'II b . e eon, w en two chameleons of different colors meet,
we WI ave three possible scenarios: split both piles further, repeat the same counting and multiplicat.ion process, and add the
new multiplication results to the original. For example, you split x to XI and e., y to Yl
and jc, then the sum is + Y1Y2' The same process is repeated until you only
XY+X X
I 2
have piles of I stone each. What is the final sum? (The final 1 's are not included in the
sum.) Prove that you always get the same answer no matter how the piles are divided.

16 H'
mt: consider the numbers in module of3.

26 27
Brain Teasers A Practical Guide To Quantitative Finance Interviews

SoIUfiO~:Le~ n ~e the number of the coins and fen) be the final sum. It is unlikely that Solution: Let m be the number of the rows of the chocolate bar and n be the number of
a so~ut1onwill Jump to our mind since the number n = 1000 is a large nwnber. If you columns. Since there is nothing special for the case m == 6 and n = 8, we should find a
ar~n t surefihow to approach th~ problem, it never hurts to begin with the simplest cases general solution for all m and n. Let's begin with the base case where m = 1 and n::::: 1.
~nIt7 todmd a pattern. ~or this problem, the base case has n = 2. Clearly the only split The number of breaks needed is clearly O. For m > 1 and n = 1, the number of breaks is
IS + a~ t~e fi~al sum IS 1. When n == 3, the first split is 2 + I and we have .:ry = 2 and m -1; similarly for m = 1 and n > 1,the number of breaks is n -I. So for any m and n,
~~is2~~~t ~~I:I:Ill.further gi~e an extra mu1tip~ication result 1,so the final sum is 3. if we break the chocolate into m rows first, which takes m -1 breaks, and then break
total sun: will bO ~~e; ~he(hmt that when n coms are split into x and n-x coins, the each row into n small pieces, which takes men -1) breaks, the total number of breaks is
3 IF' e n -xn-x)+j(x)+j(n-x), 4 coins can be split into 2+2 or (m-1)+m(n-l)=mn-1. If we breaks it into n columns first and then break each
+ 6.
sum , 'Of either case we can apply x (n-x ) + j( x)+ fen-x) and yields the same final column into m small pieces, the total number of breaks is also mn -1. But is the total
number of breaks always mn -I for other sequences of breaks? Of course it is. We can
prove it using strong induction.
Claim: For n coins, independent of intermediate splits, the final sum is n(n -1) 17
We have shown the number of breaks is mn -I for base cases m :?-I, n = 1 and
2
m=l, u z l. To prove it for a general mxn case, let's assume the statement is true for
So how do we prove it? The answer should b I
have proved the claim for th b e c ear to you: by strong induction. We cases where rows < m, columns S n and rows::;;m, columns < n. If the first break is
n = 2 ... N -I . ease cases n=234' ,. A ssume t hee claic aim IS true for
" COins,we need to prove that .t h ld f . along a row and it is broken into two smaller pieces m x nl and m x (n - nl), then the
apply the equation fen) _ () lOS or n = N coms as well. Again we
total number of breaks is I+(mxnl-I)+(mx(n-nl)-1)==mn-1. Here we use the
N ~x coins, we have - x n-x + f(x)+ fen-x). If N coins are split into x coins and
results for rows:$ m, columns < n. Similarly, if it is broken into two pieces 1111 x nand
j(N)~x(N-x)+ j(x) + j(N-x) (m-11l )xn, the total number of breaks is 1+(m1xn-I)+((m-ml)xn-l)=mn-1. So
1
~x(N -x)+ N(~ -1) + (N -x)(N -x-I) = N(N -I) the total number of breaks is always mn -1 in order to break the chocolate bar into
2 2 mx n small pieces. For the case m = 6 and n = 8, the number of breaks is 47.

Soindeectitholdsforn~N as well and j(n)_n(n-l) , Although induction is the standard approach used to solve this problem, there is actually
th I' - 2 IS true for any n 2: 2 , Applying a simpler solution if you've noticed an important fact: the number of pieces always
e cone usron to n --1000 ,we have j(n) ~ 1000x999/2, increases by 1 with each break since it always breaks one piece into two. In the
beginning, we have a single piece. ln the end, we will have mn pieces. So the number of
breaks must be mn-1.
Chocolate bar problem
A chocolate bar has 6 rows and 8 I
' dtIVIidual squares by making a numb
In co umn s (48 sma 1I l x l squares). You break it into Race track
~wo.smaller rectangles. For example ~~;:; b~eaks. Each time, break one rectangle into Suppose that you are on a one-way circular race track. There are N gas cans randomly
ar IOta a 6x3 one and a 6x5 one Wh' ~ irst step you can break the 6x8 chocolate placed on different locations of the track and the total sum of the gas in these cans is
to break the coco
hi' ate bar Into 48 s ,at II IS the total n urnb er 0 f b reaks needed in order enough for your car to run exactly one circle. Assume that your car has no gas in the gas
rna squares?
tank initially, but you can put your car at any location on the track and you can pick up
the gas cans along the way to fill in your gas tank. Ca~ yo~ alw~~s choose a starting
" J(2)~I, JO)-J(2)'2 and J(4)-J(])- '
- 3 should give you h hi
position on the track so that your car can complete the entire Circle?
!(n)-",1+2+"'+(n_l)=o n(n-I) enoug hint to realize the pattern is

2 18 Hint: Start with N = 1,2 and solve the problem using induction.

28 29
Brain Teasers
A Practical Guide To Quantitative Finance Interviews

Solution: ~f you get stuck. as to ~ow to ~olve ~he problem, again start with the simplest which the statement holds. So the statement also holds for N == n + 1. Hence we can
ca~es (N -1,2) and c.onslder usmg an induction approach. Without loss of generality, always choose a starting position on the track to complete the entire circle for any N.
.. I J US!
let s assume that the circle has circumference of 1. For N --, I th e pro bl em .IS tnviat.
There is also an alternative approach to this problem that provides a solution to the
s~art a~where the gas can is. For N == 2, The problem is still simple. Let's use a figure to starting point. Let's imagine that you have another car with enough gas to finish the
visualize the approach. As shown in Figure 2.4A, the amount of gas in can I and can 2 circle. You put that car at the position of a randomly chosen gas can and drive the car for
expressed as the distance the car can travel, are XI and x2 respectively, so Xl + X2 = I~ a full circle. Whenever you reach a gas can (including at the initial position), you
measure the amount of gas in your gas tank before you add the gas from the can to your
The corresponding segments are YI and Y2' so YI + Y2 == 1. Since XI + x2 == I and
gas tank. After you finish the circle, read through your measurement records and find the
YI + Y2 = I, we must have x > y or
I - I x2 >
- Y2 ( Xl < YI an d X2 < Y2 cannot both be true). If lowest measurement. The gas can position corresponding to the lowest measurement
XI ~ YI ' we can start at gas can 1, which has enough gas to reach gas can 2 and get more should be your starting position if the car has no gas initially. (It may take some thinking
gas from gas can 2 to finish the wh I . I O' ' to fully understand this argument. I'd recommend that you again draw a figure and give
and pick up gas can I I hoe Cl~Ce. therwise, we will just start at gas can 2
a ong t e way to fimsh the whole circle. this argument some careful thoughts if you don't find the reasoning obvious.)

2.9 Proof by Contradiction


x,
In a proof by contradiction or indirect proof, you show that if a proposition were false,
then some logical contradiction or absurdity would follow. Thus, the proposition must be
true.

Irrational number
Can you prove that J2 is an irrational number? A rational number is a number that can
X, be expressed as a ratio of two integers; otherwise it is irrational.
Xi

Solution: This is a classical example of proof by contradiction. If J2 is not an irrational


A Yi number, it can be expressed as a ratio of two integers m and n. If m and n have any
B
common factor, we can remove it by dividing both m and n by the common factor. So in
Figure 2.4 Gas can locations on the cycle d the end, we will have a pair of m and n that have no common factors. (It is called
an segments between gas cans
irreducible fraction.) Since m/ n = J2,
we have m = 2n •
2 2 2
So m must be an even
The argument for N == 2 a Iso gives . us the h' number and m must be an even number as well. Let's express m as Zx, where x is an
show that if the statement holds for N _ tnt for the induction step. Now we want to
integer, since m is even. Then m2 = 4x2 and we also have n = 2x , which means n
2 2

N = n + I. As shown . F' - n, then the same statement also holds for


III tgure 2.4B we h must be even as well. But that both m and n are even contradicts the earlier statement
Yl+Y2+"'+Y
11+1
==1l':orN
11
'
==n+l. So there muer avr
ave XI+X2+"'+x
11+
,=1 and
that m and n have no common factors. So J2 must be an irrational number.
has X Y , That means h
~ e must exist at least one i, lsi:::; n + I, that
j I
. . w enever the car reache' .
(Forl=n+l It goes to . Li s Xi' It can reach x. With more gas
, 1 == Instead). In other word 1+1 Rainbow hats
X,+I to one gas can at the .. s, we can actually "combine" .r. and
h POSItion of x. with ' Seven prisoners are given the chance to be set free tomorrow. An executioner will put a
t e gas can i+I). But such binati an amount of gas x·+x (and eliminate hat on each prisoner's head. Each hat can be one of the seven colors of the rainbow and
com matron reduce th N I 1+1
the hat colors are assigned completely at the executioner's discretion. Every prisoner can
S e == n + I problem to N = n, for

30
31
Brain Teasers

see the hat colors of the other six prisoners, but not his own. They cannot communicate
Chapter 3 Calculus and Linear Algebra
with others in any form, or else they are immediately executed. Then each prisoner
writes down his guess of his own hat color. If at least one prisoner correctly guesses the Calculus and linear algebra lay the foundation for many advanced math topics used in
color of his hat, they all will be set free immediately; otherwise they will be executed. quantitative finance. So be prepared to answer some calculus or linear algeb~a
They are given the night to come up with a strategy. Is there a strategy that they can problems-many of them may be incorporated into more. complex problems-Ill
guarantee that they will be set free?l9 quantitative interviews. Since most of the tested calculus and linear algebra. knowledge
is easy to grasp, the marginal benefit far outweighs the time'y0u spend br~shll~g up your
Solution: This problem is often perceived to be more difficult than the prisoner problem knowledge on key subjects. If your memory of calculus or lmear algebra IS a little rusty,
in the modular arithmetic section. In the previous prisoner problem, the prisoners can spend some time reviewing your college textbooks!
hear others' guesses. So one prisoner's declaration gives all the necessary information Needless to say, it is extremely difficult to condense any calculus/linear algebra books
other prisoners need. In this problem, prisoners won't know what others' guesses are. To into one chapter. Neither is it my intention to do so. This chapter focuses only o~ so~e
solve the problem, it does require an aha moment. The key to the aha moment is given

(t
of the core concepts of calculus/linear algebra that are frequently occurrmg m
by the hint. Once you realize that if we code the colors to 0-6, x, ) %7 must be quantitative interviews. And unless necessary, it does so .~itho~t covering the proof,
details or even caveats of these concepts. If you are not familiar WIth any of the concepts,
among 0, 1,2, 3, 4, 5 or 6 as well. Then each prisoner i-let's label them as 0.6 as please refer to your favorite calculus/linear algebra books for details.
well-should give a guess gi so that the sum of gi and the rest of 6 prisoners' hat color
codes will give a remainder of i when divided by 7, where g; is a unique number
3.1 Limits and Derivatives
between a and 6. For example, prisoner a's guess should make (go + LX k
)%7 == O. Basics of derivatives
,,0 Let's begin with some basic definitions and equations used in lim.its ~d derivatives.
This way, we can guarantee at least one of gi == Xi for i = 0,1,2,3,4,5,6.
Although the notations may be different, you can find these materials III any calculus

We can easily prove this conclusion by contradiction, If e. "x" then (tx, )%7" i
textbook.
dy , Lly , f(x+LIx)- I(x)
Derivative: Let y = f(x), then rex) = dx = t':'o LIx = t~ LIx
(since ( s, + t;x, )%7" i and e, and X, are both between 0 and 6), But if s, "X, for all
The product rule: If u == u(x) and v = v(x) and their respective derivatives exist,

i = 0,1,2,3,4,5, and 6, then (~X)%7"


LJ , 0, 1, 2, 3, 4, 5, 6 ,w h'rch iIS c Iear I'y rmpossi ibt e. So
d(uv) dv
-=u-+v-. du ( uv-u
)'_ 'v+uv'

)+~-u:)jv', (~)=u'7v'
':ol dx dx dx
at least one of g must equal t A .
i 0 Xi' S a result, usmg this strategy, they are guaranteed
to be set free. The quotient rule ~(:

dy dy du
The chain rule: If y = f(u(x)) and u = u(x) , then dx = du dx

19 H' t L' . The generalized power rule:


dy" 11-1 dy -6 r 'Vn:t:-
dx = ny dx a
a
tnt: et s assign the 7 colors of rainbow with cod
' ) e 0-6 and Xi be the color code of prisoner i. Then
( L>,
I.,
%7 must be 0, 1,2 3 4 50r6 How
, " . many guesses can 7 prisoners make?
Some useful equations:

32
Calculus and Linear Algebra
A Practical Guide To Quantitative Finance Interviews

In(ab)=lna+lnb j'(c) > 0, [(x) is an increasing function at c; if j'(c) < 0, [(x) is a decreasing
function at c.
1im~=1 lim(l+x)"=I+!<x foranyk
.. --;0 X HO Local maximum or minimum: suppose that J(x) is differentiable at c and is defined
lim(lnxlx')=O for any r>O on an open interval containing c. If J(c) is either a local maximum value or a local
H'
minimum value of [(x), then j'(c) = O.
d" =e-
-e "du d"a " Ina)- du d I du u' Second Derivative test: Suppose the secondary derivative of J(x), J"(x), is
-=(a -Inu=--=-
dx dx dx dx dx udx u continuous near e. If J'(e) = 0 and f"(e) > 0, then J(x) has a local minimum at e; if
d . d j'(e) = 0 and ["(e) < 0, then [(x) has a local maximum at c.
dx smx e cos x, dx cosx = -sinx, ~ tan x e sec- x

tr
Without calculating the numerical results, can you tell me which number is larger, e or
What is the derivative of y = In Xln .. ?1 J[e ?2

Solution: This is a good problem to test . Solution: Let's take natural logs of elf and ffe. On the left side we have Jr In e , on the
specifically, the chain rule and th d your knowledge of basic derivative formulas-
e pro uct rule.
right side we have e ln x. If elf >lle, ell" >1[e ee s-x ln e c- e x ln a c> Ine > lnff.
e 1r
Let u=lny=ln(lnx'''')-1 - nxx In (I nx ) . .
h . Applying the cham rule and the product rule
we ave '
Is it true? That depends on whether J(x)::::: lnx is an increasing or decreasing function
x
du = d(lny) . , 1/ .r x x ln r l-eln x
~_: = d~X) xln(lnx)+lnxx d(ln(lnx)) In(ln x) In x
from e to fl. Taking the derivative of lex), we have J (x)::::
c

dx dx +--, x:1 :::::


x2 '
dx x xlnx
To derive d(ln(lnx)) . which is less than 0 when x> e (In x > I). In fact, J(x) has global maximum when
dx ' we agam use the chain rule by setting v = In x : Ine Ina d e" e
x v e for all x>O. So ->-- an e »w,
e 1r
d{1n(lnx))_d(lnv)dv I I
dx - -=-x-=~ Alternative approach: If you are familiar with the Taylor's series, which we will discuss
dv dx v x xln x • 1
.. . xx"", xx-x ' 3

.i-dy _In(lnx) Inx d mSectlOn3.4,youcanapplyTaylor'ssenestoe : e ::::LJ!=I+,+-,+~,+··· So


n=O n. I. 2. 3.
dx - +-==>2_Y(1 ln x'?"
x xlnx dx --:; n(InX)+I)=~(ln(lnx)+I).
y
e x > 1+ x, v» > O. Let x = ff I e -1, h
t en e
,1'1e > 1l I e ¢:> e tt t e > J[ ee- e If > st e .

Maximum and minimum


Derivative ['( ) .
L'Hospilal's rule
• essentially the slope of the
X IS .
the Illstantaneous rate of ch ( . tangent line to the curve y = [(x) and Suppose that functions [(x) and g(x) are differentiable at x -+ a and that ,~~ g '(a) " O.
ange velocity) of .h
Y Wit respect to x. At point x:::: c, if Further suppose that lim [(a) =0 and limg(a)=O or that lim[(a)-+±oo and
x--;o X--;Q X--;U

'H'
tnt: To calculate the derivative 0 .
logs on both side f functIOns with the format _ ,.. 2 Hint: Again consider taking natural logs on both sides; In a > In b :::::> a > b since In x IS a
s and then take the derivativ . Y - f(x) , It IS common to take natural
e, Since d(lny)/ cit- '" 1/ yx dy/ dx. monotonously increasing function.
34
35
Calculus and Linear Algebra
A Practical Guide To Quantitative Finance Interviews

limg(a)
Ho
-> too, then lim f(x) = lim f'(x)
HO g(x) .<->a g '(x)
L'Hospital's rule converts the limit from F(a) ~ Yo => F(x) ~ Yo + r f(t)dl

an indeterminate form to a determinate form. k"


The generalized power rule in reverse: f k
u du ==--+c
U
(k '* I), where C IS any
k+ 1
2
What is the limit of eX / x as x ----t u), and what is the limit of Xl In x as x ----t O+? constant.

, Integration by substitution:
Solution: lim;" is a typical example of L'Hospital's rule SInce lim eX ==00 and ff(g(x)),g'(x)dx= ff(u)du with u~g(x), du~g'(x)dx
t~'" x:
==00. Applying L'Hcspital's rule, we have
~~~ Xl
Substitution in definite integrals: r f(g(x))'
1,
g '(x)dx ~ f(h
J/i(aj
i
f(u)du
f(x) e' f'( x ) ,
lim--== lim-== lim __ _ ==lirn!...-
x~a g(x) x~"'X2 x~'" g'(x) x~"'2x Integration by parts: JUdv ==uv- JVdu

lim f(x)
The result still has the property that -"-",,, - I'umev.r
e
-
e co an d I'Img(x)==hm2x:::=00,so
,
I X-a) <-->'" X~
A, What is the integral ofln(x)?
we can app y the L' Hospital's rule again: - a)

, f(x) I' e' f'(x) d( ')1


, Solution: This is an example of integration by parts. Let u ==In x and v ==x , we have
IIm--== Im-==lim--r e e dxli eX
x_"'g(x) x-."'x2 .<-+:og'(x) -x~2x ==}!!!'d(2x)ldx ==~~2==oo d(uv) = vdu + udv ~ (x x IIx)dx+ Inxdx,

At first look, L'Hospital' I d :. Ilnxdx==xlnx- Idx==xlnx-x+c, wherecisanyconstant.


s ru e oes not appear to be applicable to lim Xl In x since it's

not in the format of lim f(x) H ,HO', Inx


x-.a g(x)· owever, we can rewrite the original limit as IIm----:?
d Ir b x-4O·x- B. What is the integral of sec(x) from x ==0 to x = lr /6?
an It ecomes obvious that lim x-2 == co and !!~o.In x ==-co. So we can now apply
L'Hospital's rule: x-.O· ,~
Solution: Clearly this problem is directly related to differentiation/integration of
trigonometric functions. Although there are derivative functions for all basic

li~x2Inx=Iimlnx=li d(lnx)ldx , Ilx ,x' trigonometric functions, we only need to remember two of them: ~sinx e cos x,
t_O x-+O' X -2 x-->~ d( 2) I dx ==lim ==lim - =0 dx
X x-->O' -21x' x~O, _ 2
~cosx:::: -sinx. The rest can be derived using the product rule or the quotient rule. For
dx
example,
3,2 Integration
Basics of integration dsecx ==d(J/cosx) == sinx e sec r tan x,

Again, let's begin with some basic definitions .


dx dx cos" X

If we can find a fu . and equations used in integration.


, ncuon F(x) with deri ,
onllderivative of f(x) , envatrve f(x), then we call F(x) an

If f(x) = F'(x) rf r = sec x( sec x + tan x) .


~d:c(~s:::ec:cx~+~t:::an~x)
,1 (x) = 1F'(x)dx = [F(x)]: = F(b)- F(a) dx

36
37
Calculus and Linear Algebra
A Practical Guide To Quantitative Finance Interviews

Since the (secx+tanx) term occurs in the derivative, we also have

d In I secx+ tan x 1_ secx(secx+ tan x)


~ e sec r
dx (sec x + Ian x)
~ fsecx=lnlsecx+tanx!+c

d f''r/6
an .10 secx ~ In(sec(Jr /6) + lan(Jr /6» - In(sec(O) + tan/O) = In(,f3)

Applications of integration
A. Suppose that two cylinders h . h d' .
centers also intersect. What is ::c wilt ra flUS 1.mtersec! at right angles and their
e vo ume a the intersection?

Solution: This problem is an a licati fi . Figure 3.1 Interaction of two cylinders


applied problems, the most di~ I on o. integration to volume calculation. For these
ICU t part IS to correctly [annulate the integration. The
f'
'.

general IntegratIOn function to calculate 3D vol . V B. The snow began to fall some time before noon at a constant rate. The city of
ume IS = A(z)dz where A(z) is the Cambridge sent out a snow plow at noon to clear Massachusetts Avenue from MIT to
cross-sectional area of the solid cut b I . '"
The key here is to find the right y ~ pane perpendicular to the z-axis at coordinate z. Harvard. The plow removed snow at a constant volume per minute. At I pm, it had
expression for eros s-sec tirona Iarea A as a functton
" of z. moved 2 miles and at 2 pm, 3 miles. When did the snow begin to fall?
Figure 3.1 gives us a clue. If you cut the i . Solution: Let's denote noon as time 0 and assume snow began to fall T hours before
b' ntersecnon by a horizontal plane, the cut will
e a square WIth side-length ~( 2)' (2)2 noon. The speed at which the plow moves is inversely related to the vertical cross-
calculate the total 1 r - z . Taking advantage of symmetry, we can sectional area of the snow: v =cjl A(t), where v is the speed of the plow, c1 is a constant
vo ume as
representing the volume of snow that the plow can remove every hour and A(t) is the
cross-sectional area of the snow. If t is defined as the time after noon, we also have
2x 1[{2r)2 _{2Z)2}tz =8x[r2z_z3 /3]; = 16/3r3 ~ 16/3"
A(t) = c2 (t + T), where C2 is the rate of cross-sectional area increase per hour (since the
An alternative app h " c, c c
". roac reqUIres even b tt 3 . where c~-' Taking the
IS lllscnbed inside both cylinders . ~ ~r D Imagination. Let's imagine a sphere that snow falls at a constant rate). So v= =
sphere should have a radius of
from the sphere IS
i~ lt
A IS mscribed inside the intersection as well. The
"" Inscribed r iine. th I each cut perp en diICU Iar to the z-aXIS,
"" the eireIe
c2(t+T) t+T c,
integration, we have

1
Acirde = ~ A'<'1 a/'t" Since it's true for all e Isquare from the intersection as well. So
l1

z va ues, we have c
--dt=cJn(l+T)-clnT~cJn (I+T)
-- ~2,
V:;ploere -- 141l (')3 T+t T
2" = .!L V

l'--dt=cJn(2+T)-clnT~cJn
4 Intersect,OJ!:::::> V-I
'Ole'sec/IOJ! -
6/3 r 3 = 1613.
c (2+T)
-- =3
T+t T
From these two equations, we get

(I ;T)' ~+-
(2 T)' =>T'-T+1~0=>T=(J5-1)/2.

38
39
\
Calculus and Linear Algebra
A Practical Guide To Quantitative Finance Interviews

Overall, this question, although fairly straightforward, tests analytical skills, integration Changing Cartesian integrals into polar integrals: The variables in two-dimension
knowledge and algebra knowledge. plane can be mapped into polar coordinates: x =: r cos e, y == r sin e. Tthe integration in a
continuous polar region R is converted to

""
l./Expected value using integration
Integration is used extensively to calculate the unconditional or conditional expected
value of continuous random variables. In Chapter 4, we will demonstrate its value in
fff(x,y)dxdy
n
~ jff(rcosB,rsinB)rdrdB_
II

probability and statistics. Here we just use one example to show its application:
Calculate [e-xlI2Jx.
If X is a standard normal random variable, X - N(O, I), what is E[ X I X > O]?
Solution: Hopefully you happen to remember that the probability density function (pdf)
Solution: Since X - N(O, 1), the probability density function of x is f(x) = .$r e- t12
.r
2

of the standard normal distribution is f(x) == ~


x1
e- /2. By definition, we have
and we have E[X IX > 0] ~ f xf(x)dx ~ f x ;", e- II
'" dx . ..,2"
Because d(-1/2x )=-x
2
and JeUdy=eu +c, where c is an arbitrary constant, it is [f(x)dx~ [Jz;e-""dx=2f Jz;e-"l2dx=l=> fe-"l2dx~J%-

obvious that we can use Integration by substitution by letting u = -I / 2x2• Replace


If you've forgotten the pdf of the standard normal distribution or if you are specifically
e an d x dx wrt
. h e"
e ~lIhlWit - h -du, we have
[_J_e- l/2m-=I,
rx r -j==beudu r-r
asked to prove X
you will need to use polar integrals to solve the
Jke~112X\lx =: =: - ;;[euJ; =: - AJr(O-I) =: h' where is .J2"
rr
problem:
determined by x =: ~ ~ 0 and x =: OCJ ~ U =: -OCJ •
[ e-x212 dx [", e~J'2/2dy == [( e~(Xl+yl)/2dxdy == e ~(rlcos2B+r2sin20)/2rdrde

~f re-"12rdrdB f e-"I'd(-r'/2) r
-- E[X I X > OJ= l/fh' (".
= - dB
~

3.3 Partial Derivatives and Multiple Integrals ~-[e-"I'IrBr ~2"

Partial derivative: w= f(x,y)=> af (xo'Yo) = lim f(xo + ill:,Yo)- f(xo,Yo) = J,


ax ik-.,.O tu x
Since [e~x2/2dx= [e~y212dy,wehave (e~x212dx=:.J21r:::::> [e-XlI2dx=:J%.
Second order partial derivatives: a'f = ~(af), a' f a af a af
ax' ax ax ax0' = ax (0') ~ a/a)
3.4 Important Calculus Methods
The general chain rule' Supp th
. ose at w== f(xt,x2,···,x ) and that each of variables
Taylor's series
Xl' x2, "., xm is a function of the variables 11' f , "., 2
;~. If all these functions have
One-dimensional Taylor's series expands function f(x) as the sum of a series using the
continuous first-order partial derivatives, then 8w ::::mv aXt + Ow aX2 + ... + Ow ax'!!. for
derivatives at a point x > xo :
each i, I s; i:<; n. at, aXl afi &:2 at, ax", at i
1"( o ) f"'(x 0 )
f(x)=f(xo)+ I'(xo)(x-xo)+ X (x-xo)'+---+ 1 (x-xo)"+---
21 n.

40 41
Calculus and Linear Algebra
A Practical Guide To Quantitative Finance Interviews

If Xo =0, J(x) = J(O) +J,(O)x + J"(O) x' +...+ J''''(O) x" + ... Combining these three series, it is apparent that ei8 ==cos 8 + i sin B.
2! n!
When f) ==st , the equation becomes eiJr ==cos II + i sin II ==~ 1. When 8 ==II /2, the
Tavlor's seri~s are often used to represent functions in power series terms. For example iJr/2
equation becomes eiJrl2 =cos(1l/2)+isin(1l/2)==i.3 So Ini==ln(e )==ill/2.
aylor s senes for three common transcendental functions, e", sin x and cosx a;
xo=Oare ' JrI2
Hence, In(ii) ==Hni ==i(i1!/2) ==-J[ /2:::::} ii ==e- .

2 3
x~l XX X
e =L.-==l+-+-+-+ ...
/I"on! I! 2! 3! '
B. Prove (l + .r)" 2':l+nx for all x > -1 and for all integers n~2.
. ~(-I)"X2/1+1 x) x' 7
stn x e L. =x--+ __ x
"00 (2n+ I)' 3! 5! 7T+'" Solution: Let f(x) ==(l + x)" . It is clear that 1 + nx is the first two terms in the Taylor's
series of I(x) with o::: O. So we can consider solving this problem using Taylor's
L"(1)/12/1- 2 4 X
6
cosx e x =1-':"'- X x
"o0 (2n)! 2! +41-61+'" senes.

The Taylor's series can also be expressed For Xo ==0 we have (1 + x)" ==1 for v n ~ 2. The first and secondary derivatives of f(x)
h
as t e Sum of the nth-degree Taylor are I'(x) = n(1 + x)"-' and I"(x) = n(n -1)(1 + X)"-2. Applying Taylor's series, we have
polynomial T,,(x) = J(xo) + I'(xo)(x _ x ) + J"(xo) ( )' J'''' (x )
• 0 21 x-xc + ... + 0 (x-xo)" and
J(x) = J(xo) + I'(xo)(x - xo) + I"(x) (x - xo)' = J(O) + ('(O)x + I"(x) x'
aremamder R,,(x): J(x)=I;(x)+R,,(~.~ n! 2! . 2',

For some x between x and


______ o
( ) _ J''''''(x)
'''X_ R (n+1)!
t/ ~
I x-xo 'I......
")
/.LetMbethemaximumof
= I + nx+

where x:$x:5:0
n(n -1)(1 + x)"-' x2

if x<O and x 2':x 2':0 if x o Il .

IJ''''''(x)-I for all i between xo' and x, we get constraint !R" (x)l :$ M x I x - Xo I
,,+1 Since x>-l and e z z.we have »c-D, (n-l»O,(1+x)"-2
2
>O,x 2':O.

(n+ I)! Hence, n(n-I)(1+x)"-'x22:0 and J(x)=(I+x)">I+nx.


If Taylor's series does not jump to your mind, the condition that n is an integer may give
you the hint that you can try the induction method. We can rephrase the problem as: for
every integer n 2':2 , prove (I + x)" 2':1+ nx for x > -I .
Solution: The solution to this probl
can be proven using Taylor's seri eLmuses Euler's formula, e" ==cos19+isinB which The base case: show (I + x)" 2':1+ nx, v x > -1 when n ==2, which can be easily proven
,e nes, et's look h '
e ,cos8 and sin 8, Wehave at t e proof Applying Taylor's series to
since (1+x)22':1+2x+x2 2':1+2x, Vx>-l.
eiU = I iIJ (i1J)'
+ +-+
(i1J)3 ('IJ)'
1 0 IJ' 3 4 The induction step: show that if (l + x)" 2': 1+nx, \Ix > ~I when n ==k, the same
I! 2! 31+-;-+ ..·=I+i- ·O 0 .BS (1+x)"'2:I+(k+l)x,'1x>-1. This step IS
. 4. II 21 '31+-+1-+ ... statement holds for n :::k + I :
IJ' IJ' If . . . 4! 5!
cosB=l __ + straightforward as well.
2! 4T-6T+'"
.
sm8=19 __8 +_
OS 87 3
8 3
3! 5! -71+''':::}isin8=i __ i~ .Os .B'
. }1 +1--1_+ ... 'CI ear Iy t hey satlS'J
. 3! 5! 7' 'fi, equatIOn
. e
('''')'.' '" I '" e ,. = - 1.
42
43
Calculus and Linear Algebra
A Practical Guide To Quantitative Finance Interviews

(I+x)'" =(I+x)'(I+x) Alternatively, we can use algebra since it is obvious that the solution should be slightly
~(I+kx)(I+x)=I+(k+l)x+kx2, '1x>-1 higher than 6. We have (6+y)2=37=;.y2+l2y-l=0. If we ignore the / term,
~1+(k+l)x which is small, then y = 0.083 and x = 6 + y = 6.083.

So the statement holds for all integers n 2:: 2 when x > _I.
B. Could you explain some root-finding algorithms to solve f(x) =. O? Assume f(x) IS

a differentiable function.
Newton's method
Solution: Besides Newton's method. the bisection method and the secant method are two
Newton'~ met.hod,.also known as the N~wton-Raphson method or the Newton-Fourier alternative methods for root-finding. 5
method, IS an iterative process for solving the equation [(x) = O. It begins with an initial
Bisection method is an intuitive root-finding algorithm. It starts with two initial values
value Xo and applies the iterative step x
Il+]
=x Il
- I(x")
f'(x,,)
t
0
1 I()
so ve
(Lif
x = I XI,X2,'"
aoand bo such that J(ao) < 0 and J(bo) > O. Since I(x) is differentiable, there must be
converge." an x between Go and bo that makes f(x) =. O. At each step, we check the sign of

Convergence of Newton's meth d . J(a,+b,)/2). If J«a,+b,)/2)<0, we set b,,, =b" and a,,, =(a,+b,)I2; If
is far away from th 0 ~snot guaranteed, especially when the starting point
e correct so 1unon For Newt' th d .. ft J( (a" +b")/ 2) > 0, we set a,., = a, and b"., = (a" + b")/2; If I( (a" +bJ/2) = 0, or its
necessary that the initi I . . . --. _ on s me 0 to converge, It IS 0 en
~ . bl a pomt .Js sufficiently- close to the root; f(x) must be absolute value is within allowable error, the iteration stops and x='(G" +bJ/2. The
I erentIa e around the root When it d - - - --;''---;-
2' - oes converge, the convergence rate is quadratic, . X/HI-XI
hi
w Ichmeans
(x
"+1
-x)
f <0<1 h
bisection method converges linearly, ::; 0 < 1, which means it is slower than
(X,,-X )2 - ,were xf is the solution to !(x)=O. - ---k~t
f
Newton's method. But once you find an Go/ bo pair, convergence is guaranteed.

Secant method starts with two initial values xO' XI and applies the iterative step
A. Solve x2 =. 37 to the third digit.
x 1 =X - x" -X,,_I J(x ). It replaces the f'(x ) in Newton's method with a
Solution: Let J(x)=x2-37 .. th ... "J( x" )-J( xn_1 ) " "
, e onginal problem is e . I I· J() 0
Xo =. 6 is a natural initial guess. Applying N ' qurva ent to so vmg x = . linear approximation f(x,,)- [(x" I). Compared with Newton's method, it does not
ewton s method, we have
x" -X"_l
x =x _ J(xo) _ x;-37 36-37 require the calculation of derivative f'(x,,), which makes it valuable if f '(x) is difficult
J'(x ) -xo-

---
1 0 2x =6
o 2x6 =6.083.
o to calculate. Its convergence rate is (I + .J5)/2, which makes it faste~than the_bisection
2
(6.083 = 37.00289, which is very close to 37.) method but slower than Newton's method. Similar to Newton's method, convergence is
--
If you do not remember Newton's meth d . not guaranteed if initial values are not close to the root.
O
function f(x)=-/; with f'(x) =.lx_112. ,you can directly apply Taylor's series for
2 •

J(37)~ J(36) + 1'(36)(37-36) = 6+ 1/12 = 6.083. Lagrange multipliers


The method of Lagrange multipliers is a conunon technique used to find local
maximums/minimums ofa multivariate function with one or more constraints. 6

5 Newton's method is also used in optimization-including multi-dimensional optimization problems-to


find local minimums or maximums.
44
45
Calculus and Linear Algebra
A Practical Guide To Quantitative Finance Interviews

Let I(x" x" "', x,)


" be a function of n variables x = (x I' x 2" XII ) WIith gra d'lent
", Separable differential equations
vector V!(x)=(Z" %1' "', ~). The necessary condition for maximizing or
A separable differential equation has the form dy = g(x)h(y). Since it is separable, we
minimizing !(x) subject to a set of k constraints dx

gl(XI,X2,",X,,) = 0, g2(XI'X2,"',xJ =0, "', gk(XI'X2,' . ,XII) = a can express the original equation as dy = g(x)dx. Integrating both sides, we have the
h(y)
is thatV/(x)+A,Vg,(x)+A,Vg,(x)+ ... +AkVg.(x)=O, where A,,···,Ak are called the
solution f dy ~ fg(x)dx.
Lagrange multipliers. h(y)

What is the distance from the origin to the plane 2x + 3Y + 4z = 12 ? A. Solve ordinary differential equation y'+ 6xy = 0, y(O) =1
Solution: The distance (D) from th " I' . . dy
. '. e ongm to a pane IS the nurumum distance between
the ongm and points on the plane. Mathematically, the problem can be expressed as Solution: Let g(x) = -6x and h(y) = y, we have - ~ -6xdx. Integrate both sides of
y
min D
J
= !(x,y,z) = x + / + Z2
fdY
2

s.t. g(x,y,z)=2x+3y+4z-12=O
the equation: = f -6xdx <> In y = _3x2 + c :::::> y = e~3xl+c, where c is a constant.
y
Applying the Lagrange multipliers, we have Plugging in the initial condition y(O) = 1, we have c = 0 and Y = e-J.r'.
i!f i!f
iJx+A.fu"=2x+21=0
iJj 1 iJj
iJy+/loay=2y+3A.=0 B • S 0 Ive or dimary diff . I equation
I rerentia . y ,x= -- - Y .7
if
a: + /loa:= 2x + 41 = 0
~aj "" D=~(1!)'
29
+(")'
29 + (-"-)'_~
29 -.J29 x+y

2x+3y+4z-12=O Solution: Unlike the last example, this equation is not separable in its current form. But
we can use a change of variable to turn it into a separable differential equation. Let
In general, for a plane
with equation ax + by + CZ = d, the distance to the origin is Z = x + y , then the original differential equation is converted to
D= Idl
.Ja2 +b2 +c2 • d(z -x) = x-(z -x) c> dz -I = 2x -I ""zdz = 2xdx => fzdz = f2xdx+ C
dx z dx z
=::::} (x+ y)2 = Z2 = 2x2 +c =::::} i + 2xy-x2 =c

3.5 Ordinary D'u . First-order linear differential equations


In thi . I"erentlal Equations
~s ~ectlOn, we cover four tical di .
seen In mterviews. YP IfferentJal equation patterns that are commonly A first-order differential linear equation has the fonn : + P(x)y = Q(x). The standard

approach to solving a first-order differential equation is to identify a suitable function


l(x), called an integrating factor, such that f(x)(y'+P(x)y)=f(x)y'+f(x)P(x)y

6 The method of Lagran e '. _


reveals the necessa g . ~ultlphers is a special case of .
ty conditIons for the solun ~arush-Kuhn_ Tucker (KKT) conditions, which 7 Hint: Introduce variable z = X+ y.
IOnsto constrain d I'
46 e non mear optimization problems.

47
Calculus and Linear Algebra
A Practical Guide To Quantitative Finance Interviews

= (1(x)y)'; Then we have (1(x)y)' = I(x)Q(x) and we can integrate both sides to solve I. If f1 and r: are real and 'i :;t:. f2, then the general solution is y = cle'lX + c2e'2X ;
fI(x)Q(x)dx
for y: I(x)y = fI(x)Q(x)dx =:> y 2. If fl and f2 are real and 'i = r2 = z-, then the general solution is Y = cle'x + c~)
I(x)
3. If rl and f2 are complex numbers a ± ifi, then the general solution is
Thee !mtegratmg
ina factor, I(x), must satisfy
' dI(x) T = I(x)?(x), which means I(x) is a Y = e'" (c, cos fix +C, sin fix) .

It is easy to verify that the general solutions indeed satisfy the homogeneous linear
separable differential equation with general solution lex) = ef"lX)dt. 8
solutions by taking the first and secondary derivatives of the general solutions.

Solve ordinary different equation y'+ y = --\-, y(1) = 1, where x> O. What is the solution of ordinary differential equation y"+ Y '+ Y = O?
x x
Solution: In this specific case, we have a = b = c = 1 and b' - 4ac = -3 < 0, so we have
Solution: This is a typical example of first-order linear equations with P(x) =..!.. and
complex roots r = -11 2 ±.,J3 /2/ (a = -112, fJ = .,J3/2), and the general solution to the
x
- I S I
Q( x ) -7' 0 (x)=e
1"<". »e (III,",=e"'=x
I
and we have I(x)Q(x)=-,
I differential equation is therefore

., I(x)(y'+ ?(x)y) = (cry)' = I(x)Q(x) = II x


x
y = e'" (c, cos fix + c2 sin fix) = e-lI2x (c cos( .J3/2x)
i + c2 sin(..Jj / 2x)).

Taking integration on both sides , xy -- f(l/)dx


x I
=nx+c::::::>y= In x + c . Nonhomogeneous linear equations
x
Plugging in y(l) = I, we get c = I and y = In x+ I Un Iik
I e a
homogenous '
hnear equation 2 dx + C = 0, a non homogeneous
,d'y a dx + b dy I'mear

x 2
equation a d ; + b dy +c = d(x) has no closed-form solution. But if we can find a
dx dx "-
Homogeneous linear equations d' d
particular solution Yr(x) for a--?+b-.!+c=d(x), then y=y,(x)+ y,(x), where
A homogenous linear '. dx dx
d' e~atlOn IS a second-ordej- differential equation with the form
, - - - , ' d'y dy
a(x)--?+b(x) dy +c(x),'J,O yg(x) IS the general solution of the homogeneous equatIOn a""""d7"+b-;;;+c=O, IS a
dx dx '

It is easy to show that if d , d'y dy


homogeneous li
,Iyany
. I 2 are
rmear I'y independent solutions to t e
h general solution of the nonhomogeneous equatron a dx2 -r b dx +c = d(x).
mear equation, then any y( ) _ ()
arbitrary constants is a I t' x - CIYI x +C2Y2(X), where c\ and c2 are
, so U Ion to the homo li
Wh b geneous mear equation as well
en a, and c (a*O) are constants' d '
linear equation has cia de. mstea of functions of x, the homogeuow
se lorm sOlutIOns:
Let r: and r be th
1 2 e roots of the characteristic equation ar2 + br + cu~ 0 9 9 . . ' . d 'c I -b+..}b'-4uc
A quadratic equation ar"+hr+c=O has roots given by qua lonnua r=o . You
'a
railC
v ,

B The Constant c is not needed' th' . should either commit the fonnula to memory or be able to derive it using (r + bI2a)' = (b' - 4ac)/4a' .
In IS case Since itjust I
sea es both sides of the equation by a factor.
48
49
Calculus and Linear Algebra
A Practical Guide To Quantitative Finance Interviews

Alth~ugh it may be difficult to identify a particular solution YI'(x) in general, in the Inner product/dot product: the inner product (or dot product) of two R" vectors x and
special case when dCi) is a simple polynomial, the particular
,
!'olynomial of the same degree.
solution is often a
y is defined as L X,Yi = xTy
1.. 1

What is the solution ofODEsy"+ y'+ y = 1 and y"+ y'+ Y = x? Euclidean norm: IIXII~~tx"
~.JXTX; Ilx-yll~J(x-y)'(x-y)
,
Solution: In these ODEs, we again have a = b ~ c --1 an d b' - 4ac = -.)' < 0 so we have Then angle B between R" vectors x and y has the property that cos o = II x
Y
complex solutions r~-1/2±J312i (a~-1I2 , fJ-- "/2) an d th e general' solution
'\Ij ., IS ___ __ xillY II" x and y
I

y = e-'''' (c, cos( J312x) + c, sin( J312x)). are orthogonal if xl'y = O. The correlation coefficient of two random variables can be
viewed as the cosine of the angle between them in Euclidean space (p = cos e).
What is a particular solution for y "+ y'+ Y = I? CI I _
y"+ y'+ Y = I is . ear y y -I IS. SO the solution to
There are 3 random variables x, y and z. The correlation between x and y is 0.8 and the
correlation between x and z is 0.8. What is the maximum and minimum correlation
Y = Y,(x) + Y,(x) = e-u" (c, cos( J312x) + c, sin( J312x)) + 1. between Y and z?

To find a particular solution for y"+y'+ = L Solution: We can consider random variables x, y and z as vectors. Let e be the angle
y x, etYI'(x)=mx+n, then we have between x and y, then we have cos e = PX,y = 0.8. Similarly the angle between x and z is
Y '"+Y+Y= a +m+(mx+n)=x:::>m=l n-- . e as well.For Y and z to have the maximum correlation, the angle between them needs
the solution to y"+y'+' ' - l. So the particular solution is x-I and to be the smallest. In this case, the minimum angle is 0 (when vector y and z are in the
y= x IS
same direction) and the correlation is 1. For the minimum correlation, we want the
maximum angle betweeny and z, which is the case shown in Figure 3.2.
y = y,(x)+ y,(x) = e-u" (c, cos( J312x)+ c, sin(J312x)) + (x-I).
If you still remember some trigonometry,
all you need is that
. 3.6 Linear Algebra cos(28) = (cos 8)' - (sin 8)'
Lm~a~ algeb~a is extensively used in a Ii '. ,
= 0.8' - 0.6' = 0.28
~tatlshcs, optimization Monte C I . pp e~ quantitative finance because of its role in -, h
It is I ,ar 0 sImulation si I . Otherwise, you can solve the problem using
di a so a comprehensive mathematical fi ld ha igna processing, etc. Not surprisingly, ",
Pythagoras's Theorem:
0.8
lSCUSS several topics that have . .file t at Covers many topics In this section we " ,
methods. stgm tcant applications in statis~ics and nume;ical 0.8x 1.2 = I xh => h ~ 0.96
y 12:.. UJx __ --,- __ -"'" Z cos2B ~ .JI' -0.96' = 0.28
Vectors 0.6 0.6
Figure 3.2 Minimum correlation and maximum angle between vectors y and z
~n '" 1.(column) vector is a one-dimensional a
POint In the R" (n-dimensional) E I'd rray. It can represent the coordinates of
uc I ean space.

50 5I
Calculus and Linear Algebra
-
A Practical Guide To Quantitative Finance Interviews
QR decomposition
To minimize the function /(/3), taking the first derivative 11 of f(/3) with respect to fJ,
QR decomposi~ion: ~or eac~_f!On-singutar nxn matrix A. there is a unique pair of we have f'(f3)=2Xr(Y-X/J)=O:::::>(XTX)/J=XlY, where (XTX) is a pxp
orthocronal
e
matnx Q and upper-tn·angu Iar matnx
· R V.'lt· 11 poSH· ·tve d ·tagonal elements such
that A= QR. 10 symmetric rnatrix and XT Y is a p x 1 column vector.
T
Let A== (X X) and b = X 7 Y, then the problem becomes A/3 = b, which can be solved
A

QR , dccomposjtion
. . . is often used to solve linear systems Ax = b when A ·IS a non-smgu
· 1ar
matnx. Smce Q IS an orthogonal matrix Q- - Qr d ORx b
1 o~ r using QR decomposition as we described.
. . , - an _ == ::::> JU = Q b. Because R
an _up~r-tnangular ma~ix, we can begin with xn (the equation is simply
1
; Alternatively, if the programming language has a function for matrix inverse, we can
, ...x" -{Q h)"). and recumvely calculate all X;, V'i == n,n- 1, .. ·, 1. directly calculate /J as jJ = (X~'Xf 1 X rY. 12
Since we are discussing linear regressions, it's worthwhile to point out the assumptions
behind the linear least squares regression (a common statistics question at interviews):
If the progranuning language you arc . d l. T~e relationship between Y and X is linear: Y =X f3 + &.
sq uares regression how w ld d ~smg oes ~ot have a functi on for the linear least
. ou you estgn an algonthm to do so? 2. E[&;]==O, "ifi = l ,··· , n.
Solution: The linear least squares re ,· . 3. var( c,) == a 2 , i = 1, .. ·, n (constant variance), and E[c,c) = 0, i ;t j ( uncorrelated
analysis method Let's . gressiOn lS probably the most widely used statistical
· go over a standard app 0 h · . errors).
regressions using matrices A . . r ac to so 1vmg linear least squares
expressed as · 1
simp e hnear regression with n observations can be 4. ~~ perfect multicollinearity: p(x,, x) ;t ±1, i ;t j where p(x,,x1 ) is the
correlation of regressors x, and x.~.
Y, =f3nx,,o +Ax" + ... + f3 1x + "if.-
· P- •,p-J c,, 1
-l, .. ·,n, where x = 1 V'i is the ,· n•erccpt 5. E and X; are independent.
term and x .. . x ;() - ' ' ~~
'·' ' , . •.r ' are p- I exogenous regressors.
Surely in practjce, some of these assumptions are violated and the simple linear least
The goal of the linear least . . squares regression is no longer the best linear unbiased estimator (BLUE). Many
squares regression IS to fmd a set of p =[ n R ... p ]' econometrics books dedicate significant chapters to addressing the effects of assumption
" Po • f/1 • ' r-t
that makes :L>.2 the smallest. Ler s ex . . violations and corresponding remedies.
,_, · press the ltnear regression in matrix fomtat:
Y -= X fJ + c, where y == [Y. }' . .. y ,
. , . 2• • ] and c =[ , l' are both n x 1 column
vectors: .\' 1s a n x p mat . .h " c:,, c2, · · ·, &, Determinant, eigenvalue and eigenvector
· n x Wtt each colu ·
mtercep!) and each row repres f mn representmg a regressor (includ ing the Determinant: Let A be an nxn matrix with elements {A,), where i , j = l, .. ·, n. The
. " en mg an observation. lhen the problem becomes
mm f( p) :::•ru·n" 2 • determinant of A is defi ned as a scalar: det(A) = Ll/l(p)a1.f\ a~.r·l .. .a,,"", where
I! · ~ c. == mm(Y_ X /3)1 (Y p
II /., P -Xp)
p ==(pi> p2' ... , Pn) is any permutation of (1, 2, ... , n); the sum is taken over all n!
possible permutations; and

11
To do that. you do need a little knowledge about matrix derivatives. Some o f the importanl derivative
A nonsingulur matrix Q is called - r.a c:x
• r 1.J.• C'·x' A:c , ,-.• x'.lr
• co
vector·slmalnccs
. ca (A' + 1)
1
equat•ons arc -:- =-.-11 =a. -r~\• • x. , - ~ .1.
~olun · . an orthogonal matrix if Q • "' 1 • ..
10r
err rx
== 11. - - "'
o.>:

c.u {
Ill:; (<~nd row:\} of Q ~ Q · Q ts orthogonal if and only tt the
onhonof]nalization r oml an orthononnal s
dccOtnlO!iition PI. ~ ocess (often improved to ' et of vectors in R·. The Gram-Schmidr o_
-
( A_x_+_h:.....
)'_c...:..·(l_.J.\_.+_!!....:.)
-= A I ( ' ( v.,
n...
• e ) + D' ( .' ( .,,...• ,.. b).
. ca~ refer to a linear algebra textb·:~e:r~ nume.rica l stability) is often used for QR 12
The m;;;ix inverse introduces large numerical error if the matrix is close to sinaular or badly scaled.
5'> }Ou are mterested in the Gram-Schmidt process.

53
Calculus and Linear Algebra
A Practical Guide To Quant itative Finance Interviews

1. if p can be coverted to natural order by even number of exchanges


~(p)=
{ -1, if p can be coverted to natural order by odd number of exchanges . If matrix A: [~ ~] , what are the eigenvalues and eigenvectors of A?
For example, determinants of 2 x 2 and 3x 3 matrices can be calculated as Solution: This is a simple example of eigenvalues and eigenvectors. Tt can be solved
using three related approaches:

dct ([: !])=ad - be, de{ [: : ~ ] ) =aei +bfg +cdh-ceg -afo- bdi l l
Approach A: Apply the definition of eigenvalues and eigenvectors directly.

Let A be an eigenvalue and x = [;:] be its corresponding eigenvector. By defioitioo, we


Determinant propertil!s: det(AT) = det(A), det(AB) = det(A)det(B) det(A- 1) = 1
have
' det(A)
Eigenvalue: Let A be an n x n matrix. A real number ..< is called an eigenvalue of A if Ax= [2 21][xx '] = [2x,+ x2] =A.x = - A.x, ]=> {2x, + x2 =A.x, J(x, + x~ ) =A.(x, + x2)
:::::>
the.re ~xists. a non~ero. vector x in R" such that Ax = A.x. Every nonzero vector x J 2
x + 2x
1 2 LA.x 2 x + 2x = A.x
1 2 2

sausfymg th1s equation ts called an eigenvector of A associated with the eigenvalue l So either A. =3 , in which case x1 =x 2 (plug A. = 3 into equation 2x1 + x2 = A.x, ) and the
Eig~nvalu~s~ and .eigenve~tors are crucial concepts in a variety of subjects such as
?.rdt~ary dtflcrenu~l equat.tOns, Markov chains. principal component analysis (PCA). etc.
I he nnportance ot determmant lies in its relationship to eigenvalues/eigenvectors.'~
corresponding normalized eigenvector is
[1l!../2]
1
.J2 , or x, + X2 = 0 , tn ' l case the
· wh IC'

The determinant of matrix A- A. I. where 1 is an n x n identitv matrix with ones on the


main .diagonal and zeros elsev.'here, ·ts ca lied 11e 1 cbaractenshc • ~ • polynooual
• of A . The normalized t1.J2
eigenvector is [ -l J2 ] and A. = I (plug x2 = -x, into equation
1
equatton det(A - J../) = 0 is called th h · -:- . · f
e c aractenshc equahon of A . The etgenvaJues o
A are the real roots of the cham t · · ·- .- - • . . · 2x1 + x 2 = A.x1 ).
· c ensttc equation of A. Ustng the characteri stic equauon.
we can also show that ~A, ... A. =det(A) and f. , ( ~ Approach B: Use equation det(A- J..l) = 0.
, L../'-1 =trace A)= ~ A,,.
,,., ,., . det(A-A./)=0~(2-A.)(2-A)-1=0. Solving the equation, we have ?.., =I and
.-1 is diagooalizabJe if and onJ if · h · . 1~
- .1 , b . . Y It as linearly mdependent eigenvectors. · Let ~ =3. Applying the eigenvalues to Ax= A.x, we can get the corresponding
A, • "'2 , · · ·, ;1., e t1le etgenvalues of A
• xl . x1• .. . , x, be the corresponding eigenvectors. eigenvectors.
and X =[x, I x2 ... I x, ), then II II

}'t
Approach C: Use eq uations A,·}":!··· A., = det(A) and ~A., =trace( A)=~ A,,,.

de t(A) =2x 2- 1 x 1= 3 and trace(A) =2x2 =4.


A, x J":! =3} :::> {A, == 1·
So we have ?..,+~=4 Aoai
e
n apply the eigenvalues to Ax= A.x, and we
1
~;::: 3
can get the corresponding eigenvectors.
11 I .
u pn~ctJCc, dctcnninant is usually n t I . ·.
cnmputatJonally inetl1cicnt t u d ~. 50 ved by the sum of all pcmtutations because rt 1 )>
r ·t . d . ecomposrllon and c: •
1 " ~::l ·
11 J

co.actors are often used to calculate detcnnmants


• lktenninam can also be appl'ed . .
oJ If II 11 . ' to matnx mverse d I'
a eJgi.TJvalucs are real and d' 1· ~n mear equations as well.
ts met, then the e 1g . · 1
envectors are mdepcndent and A is diagonahzab e.
54
55
Calculus and Linear Algebra
A Practical Guide To Quantitative Finance Interviews
Positive semidefinite/definite matrix
When A is a symmetric n x n matrix, as in the cases of covariance and correlmjon det(P) =1x det ([p1 p1 ~ ) -0.8 x det (ro.s
...1 l p o1.sjl•J +O.Sxdet([o1.8 oP.8])
r
matrices, all the eigenvalues of A are real numbers. Furthennore, all eigenvectors that
0.8x (0.8 - 0.8p) + 0.8x (0.8p - 0.8) = -0.28 + 1.28p- p 2 ~ 0
2
belong to distinct eigenvalues of A are orthogonal. = (l- p )-

Each of the following conditions is a necessary and sufficie nt condition to make a ~ (p -l)(p- 0.28) s 0 ~ 0.28 s p sl
symmetric matrix A positive semidefinite:
,. So the maximum correlation betweeny and z is I, the minimum is 0.28.
J. x Ax ~ 0 for any n x I vector x .
2. All eigenvalues of A are nonnegative. LU decomposition and Cholesky decomposition
3. All the upper left (or lower right) subrnatrices AK, K =I, ... : n have nonnegatiye . Let A be a nonsingular n x n matrix. LU decomposWoo expresses A as the product of a
determinants. 16 · lower and upper triangular matri x: A= LU. 17
~ovariance/correlation matrices must also be positive semidefinite. If there is no pcrft:ct LU decomposition can be use to solve Ax= b and calculate the determinant of A:
hnear ~ependenc~ among random variables, the covariance/correlation matrix must also
L•.. nU
"
be P?~JtJve defimte. Each ~f the following conditions is a necessary and sufficient =
LUx =b ~ Ux = y, Ly b; det(A) =det(L) det(V) =IT
"
,., ,... • -
11
condtt1on to make a symmetnc matrix A positive definite:
I. x' Ax > 0 for any nonzero n x 1 vector x . When A is a symmetric positive defi nite matrix, Cbolesky decomposition expresses A
as A= R1 R, where R is a unique upper-triangular matrix with posi tive diagonal entries.
.., All eigenvalues of A are positive.
Es~e~tially, it is a LU decomposition with the property L = ur.
3
· All the upper left (or lower right) submatrices AK K = 1 ... n have positive Cholesky decomposition is useful in Monte Carlo simulation to generate correlated
detenninants. ' ' '
random variables as shown in tbe following problem:

There are J random variables r d - Th . How do you generate two N(O, I) (standard nonnal distribution) random variables with
corrdation between v • d : 'Y an .:.. ~correlation between x and y is 0.8 and the
_, an z IS 0.8 What 1s tl · · · · correlation p if you have a random numbe r generator for standard normal distribution?
between y and z? · ' le max1mum and m11umum correlatiOn

Sulurion: The problem can be solved u .·, , .. . . . Solution: Two N(O, l) random variables x., x2 with a correlatio n p can be generated
correlation matrix. smg the POSittve sem1defimteness property of the from independent N(O, l) random variables z1 , z2 using the following equations:
Let the correlation between v and - b .
~ " e P · then the correlatton matrix for x, y and z is x, =z,
I 0.8 0.81
x2 = pz1 + JI - p 2 z~
P = 0.8 p .
[
0.8 p 1 J It is easy to confirm that var(x1) =var(zJ =I, var(x2 ) = p 2 var(z,) + 0- p 1 ) va r(z2 ) =I,
and cov(xl'x2 ) = cov(z1 ,pz1 + .J1~j/z 2 ) = cov(z,.pz,) = P ·
This approach is a basic example using Cholesky de~omposition to generate_ corre~ated
random numbers. To generate correlated random vanables that follow a n-dnnens1onal
A nee~ ·.sa , b
11
' •
r •~ I). ut not sufficient, condition ~0 r .
l~gattvc dragonal elements. matnx A to be positive st:m iditinitc il thai I ha~ 00
'' LU decomposition occurs naturally in Gaussian elimination.
56
57
Calculus and Linear Algebra

multivariate nonnal distribution X =[X X . . .


" l• •
x , ]' V(·
~ J tJ. 2:)
wtth mean
J.l = [J.i, •J11 , · .. ' p,Jr and covariance matrix l: (a n x n positive defi nite matrix) 18 , we can Chapter 4 Probability Theory
decompose the covariance t · z: · r
. _ ma nx tnto R R and generate n independent N(O. J) Chances are that you will face at least a couple of probability problems in most
random vanablcs z,, .:, . .... z . Let vector
r 19 "
z _[ J'~
- - ~~ z2,-· ·,zn , then X can be generated
7 quantitative interviews. Probability theory is the foundation of every aspect of
as X =p+RZ. quantitative finance. As a result, it has become a popular topic in quantitati ve interviews.
Alternatively. X can also be generated . . Although good intuition and logic can help you solve many of the probability problems,
called singular value d .. usmg another tmponant matrix decomposition having a thorough understanding of basic probability theory will provide you with clear
r. · • ccomposthon (SVD): For any n x P matrix X there exists a and concise solutions to most of the problems you are likely to encounter. Furthennore,
ractonz..auon of the form X= UDVr wh ' .
matrices with column . . t· , ' . ' ere U and V are n x p and p x p orthogonal probability theory is extremely valuable in explaining some of the seemingly-
. ' ~ 0 u sparmmg the colum fX counterintuitive results. Anned with a little knowledge, you will find that many of the
spanmng the row space· D is d. n ~pace o , and the columns of I'
F .. . ' · a px P tagonal mat.nx called the singu lar ,-a lues of X interview problems are no more than disguised textbook problems.
or a posttlvc detinue covariance t . .
D is the diagonal matrix f . manx, we have V =U and 2: == UDU' . Furthermore. So we dedicate this chapter to reviewing basic probability theory that is not only broadly
o etgenvalues ; 1 . . . 1 d U . h . . tested in interviews but also likel y to be helpful for your futu re career. 1 The knowledge
corresponding e· .,, "'2• • "'-,. an IS t e matnx ot n
is applied to real interview problems to demonstrate lhe power of probability theory.
1gcnvectors. Let DJ ·~ be a d' .
jJ; jT;2 ... f) h . •agonal matnx with diagonal elements Nevertheless, the necessity of knowledge in no way dovvnplays the role of intuition and
~ ' ~ ' ' 'IJ~"·u' t en Jt is clear that D = (DI' 2)2 _ (D' I2)(D"2 )' , d logic. Quite the contrary. common sense and sound judgment are always crucial for
~ == UD''l(Ulf:> ' . . - an
· ) · Agam, tf we generate a . · analyzing and solving either interview or real-life problems. As you will see in the
z
Yariables = f ~ , vector of n mdependent N(O, l) random
z" -'· •· .. · z"] · X can be generated as x = +(UD" l)Z. following sections, all the techniques we discussed in Chapter 2 still play a vital role in
11 solving many of the probability problems.
Let's ha ve some fun playing the odds.

4.1 Basic Probability Definitions and Set Operations


First let's begin wit h some basic definitions and notations used in probability. These
definitions and notations may seem dty without examples- which we will present
momentarily-yet they are crucial to our understanding of probability theory. In
addition, it will lay a solid ground for us to systematically approach probability
problems.
Outcome (w) : the outcome of an experiment or tri al.
Sample space/Probabilit)' space (0): the set of all possibl(; outcomes of an experiment.

1
As I have emphasized in Chapter 3, th is book does not teach pr?bability or any other math topics due to
the space limit · - it is not my goal to do so, either. l11e book g1ves _a su~mary of the frequentl y-tested
' Tile probability densitv of n I . . knowledoe and shows how it can be applied to a wide range of real Jntervtcw problems. The knowledge
• lU trvanate nomlal d" 'b . ( used in this chapter is covc::rcd by most introductory probability books. Tl is always helpful to pick_ up one
1,, rstn Ut1 on is f t , _ ~:"P l-' - .u)' E (.t- ,ut)
In general ·r t' - -"----- or two classic probability books in case you want to rcfrc::sh your memory on some of the top1cs. My
. • I "" l \ ' h. where .4 and hare consta I lh ( 2~r) d~t<E >' personal favorites are First Cour.~e in Probubility by Sheldon Ross and lntmtluction to Probubilily by
n • en the covariance mat rice l. r Dimitri P. Bertsekas and John N. Tsitsiklis.
58 . 11: " .I

w
Probability Theory
A Practical Guide To Quantitative Finance Interviews

P(rv): Probability of an outcome (P(a>) ~ 0, \f(t) En, I P(w) =J ). Coin toss game
lliEfl

Event: A set of outcomes and a subset of the sample space. Two gamblers are playing a coin toss game. Gambler A has (n +I) fair coins; B has n
fair coins. What is the probability that A wilJ have more heads than B if both flip all their
P(A): ProbabilityofanevcntA, P(A)= LP(a>). coins?2

Au R : Union A v B is th
e set o f outcomes In · event A or in event 8 (or both). Solution: We have yet to cover all the powerful tools probability theory offers. What do
A(") lJ or AB ·· Intersection A(") B (or -'',~B) Is
· the set of outcomes in both A and B.
we have now? Outcomes~ events, event probabilities, and surely our reasoning
capabilities! The one extra coin makes A different from B. If we remove a coin from A
'
.rl'. ·. The complement of A. which is the evem ''not A». A and 8 will become symmetric. Not surprisingly, the symmetry will give us a Jot of
Mutually Exclusive: A(") B =<I> where "' . nice properties. So let's remove the last coin of A and compare the number of heads in
w Is an empty set. A's first n coins with B's n coins. There are three possible outcomes:

For any mutually exclusive events F. £ ... ,..


'" 2, J.:. .v ,
r(U
NE ) = I.\' P( E )
I I •
£,:A's n coins have more heads than B's n coins;
•~I i=l E1 : A' s n coins have equal number of heads as B's n coins;
Random variable: A function that m· . , . £3 : A's n coins have fewer heads than B's n coins.
the set of real numbers. aps each outcome (co) 1n the sa mple space (Q ) into
By symmetry, the probability that A has more heads is equal to the probability that B has
Let's use the rolling of a six-sided d' .
of a dice has 6 possible outc ( Ice to explam these definitions and notations. A roll more heads. So we have P(£1) = P(E). Let's denote P(£1) = P(£3 ) = x and P(£2 ) = y.
omes mapped to a d .
the sample space n is 11 ...
• 2 4
_ ran om vanable): I, 2, 3, 4, 5, or 6. So
t • ·-'· .:>.6} and the p ob bT f · 16
Since L P(o;) = l, we have 2x+ y= 1. For event £1' A will always have more heads
(assummg a fair dice) We . d fi · r a t Ity o each outcome 1s J,
· · can e me an event A · than 8 no matter what A's (n+ l )th coin's side is; for event £3 , A will have no more
1S an odd number A =={I ., } h representmg the event that the outcorn~
• -'· 5 , t en the c 1
P(A) = !'(!) + P(J) + 1'(5) == 1I 2 Let B be omp 'ement of A is A' = {2, 4, 6}. ('lt:arly heads than B no matter what A's (n + !)th coin's side is. For event £ 20 A's (n + l)th
B ={4, 5. 6}. Then the t . • the e\ ent that the outcome is larger than J: coin does make a difference. If it's a head, which happens with probability 0.5, it wi ll
• •mon IS Au B == {I 3 4 c 6 . . . make A have more heads than B. So the (n + l )th coi n increases the probability that A
11 (") B = {5}. One popular rand . ' • · -'~ } and the mtersectton IS
,.. bl ) . om vanable called . d' . has more heads than B by 0.5 y and the total probability that A has more heads is
\Mta e tor event A is defined . · In Jcator vanable (a binary dummY
. as the followmg: x+0.5y=x+0.5(l-2x) =0.5 whenAhas (n+l) coins.
1 , = r 1.tr x E {I. 1 s} .
~l 0• if ·\" ~ {1• 3• 5l, · Basacally 1 • -- 1 w hen A occurs and I =0 if Ac occurs. The
~.::xpectcd value of 1 is £[/ ] _ p
11
Card game
I .I - (A).
Now• t 1'n1·~... tl~'0 r some examples. A casino offers a simple card game. There are 52 cards in a deck with 4 cards for each
j3ck queen ktn.g ~cc
value 2, 3, 4, 5, 6, 7, 8, 9, l 0, J, Q, K, A . Each time the cards are thoroughly shuffied
(so each card has equal probability of being selected). You pick up a card from the deck
and the dealer picks another one without replacement. If you have a larger number, you
win; if the numbers are equal or yours is smaller, th~ house win as in all other casinos,
the house always has better odds of winning. What is your probability of winning?

2
1-:lint: What are the possible results (events) if we compare the number of heads in A's first n coins with
B"s n coins? Ry making the number of coins equal. we can take advantage of symmetry. For each event,
what \.viii happl!n if A's last coin is a head? Or a tail?
60
61
Probability Theory
A Practical Guide To Quantitative Finance Interviews
Solution: One answer to this roble . .
card. The card can have a v:ue ? ~ '.~ ..~consider all 13 dif!erent outcomes of your £ 1 : Seat # I is taken before #I 00;
value of 2 the probability of . -·. ' . , and each has 1/ I _; of probability. With a
· · . ' wumtng IS 0/51· with a 1 f 3 h .. £ 2 : Seat # 100 is taken before # J.
w~nn~ng IS 4/5 1 (when the dealer icks a 2 . ' . . va ue o , t e probablilt)' of
wrnnlllg is 48/51 (when the d lp . k ), ... , WJth a value of A. rhe probabilitY of If any passeng_er takes seat #100 before # 1 is taken, surely you will not end up in you
winning is ea er pte s a 2 3
' · or K) · So your probability· of ~wn seat. But tf any passenger takes #1 before #100 is taken, you will definitely end up
tn you own seat. By symmetry, either outcome has a probability of 0.5. So the
I ( 0 4 48'\ 4 probability that you end up in your seat is SO%.
Ox 51+51+ .. ·+51) =~x(O+ 1+ .. ·+ 12) = 12x 13 = _!_
4 ><
xSI 2
13x51 · In case this over-simplified version of reasoning is not clear to you, consider the
.. hlrOGvard
Although th,·s ,· s a stta1g c
so l t' · 17 following detailed explanation: If the drunk passenger takes# I by chance, then it's clear
sequence. it is not the most eff · u ton and It elegantly uses the sum of an integer all the rest of the passengers will have the correct seals. If he takes# I 00, then you will
spirits of the coin tossino probt~tent way to solve the problem. If you have got the core not get your seat. The probabilities that he takes #I or #100 are equal. Otherwise assume
different outcomes: o m, you may approach the problem by considering three that he takes the n-th seal, where n is a number between 2 and 99. Every one between 2
and (n- 1) will get his own seat. That means the n-Ih passenger essentially becomes the
~~ ~ Your card has a nwnber larger than the dealer' s· new "drunk." guy with designated seat # l. If he chooses # l , all the rest of the passengers
EJ. your card has a number equal to the dealer's. . will have the correct seats. If he takes #100, then you will not get your seat. (TI1e
El : Your card has b ' probabilities that he takes #I or #100 are again equal.) Otherwise he wil l just make
anum er lower than the dealer's.
another passenger down the line the new "drunk" guy with designated seat # 1 and each
Again by symmetry. P(£) = p new "drunk" guy has equal probability of taking #I or # 100. Since at all jump points
pro ba b'l'
I uy that two cards h
I
· So we onlY need to figure out P( E2 ). the
(£,).
there's an equal probability for the "drunk" guy to choose seat #I or 100, by symmetry,
Arnon th · · ave equal value Let's
g e remammg 51 cards on!
3
d say you have randomlv selected a card. the probability that you, as the 1OOth passenger, will seat in# IOO is 0.5.
t lt! probability that the two ca.rds h)' car s will have the same value ~s your card So
1
Lhat yo u wm · ·ts J>( £ ) == (1- P(E ))I?_
ave(lequal valu c Js
· 3/5 I. As a result, the probability
·
1
2 - - - 3151 )12== 8/i7. N points on a circle
Given N points dra\.vn randomly on the circumference of a circle, wbat is the probabi lity
Drunk passenger that they are all within a semicircle't
A line of 100 airline passe ' Solution: Let's start at one point and clockwise label the points as I, 2. · · ·, N. The
one of the 100 .. · ngers are waiting to bo d .
line has a ticke~c~: on that flight. For convenien~e ~ ~la~e. They each hold a ticket ~o probability that all the remaining N -1 points from 2 to N are in the clockwise
random scat ( . r t?e seat number n. Be in d · et s say that the n-th passenger tn semicircle starting at point 1 (That is, if point 1 is at 12:00, points 2 to N are all
go to thd; p cqua 11Y likely for each seat). All 7thrunk. the first person in line picks a between 12:00 and 6:00) is 1/2'' ' 1 • Similarl y the probabi li ty that a clockwise semicircle
choos\: 't fr. ~oper seats unJess it is already oo ~other passengers ate sober and will
. · ' cc seat. You'r ccup1ed· In 1 . ' . starting at any point i, where i e {2, .. ·, N} contains all the other N -I points is also
tn your st:at C • , . e person number 100 Wh ·. t lat case. they wtll random!)
t.c ., scat #1 00) ?.l · at IS the probahi1 ity that you end up l I 2.v-1 •
Solwiun: l.et'sco .d Claim: the events that all the other N -l points arc in the clockv.~se semicircle starting
ns• er seats #I and #I 00 Th
· ere are tw0 poss1'blc outcomes: at point i, i = l. 2~···, N are mutually exclusive. In other words, if we. starting at point i
' ,. . .
1 1111. It you :Jr, I . and proceeding clockwise along the ci rcle, sequentially encounters points i + l, i + 2, · ·. ,
• · . c rvme to usc ·· -
<~&am. If )·ou d .d· , comp1tcated co d' . N, 1, · · ·, i - 1 in half a circle, then starting at any other point j. we cannot encounter all
.mcrem· 1 ec• I! to star! wu, .I a · n lllonal P"ob b' l·
·- . 101-' lll! number of pa 5Imp1er version of' tt a 1 1ty to so 1ve the problem. go back and th1n~

c1l1Cil'nth. ssengers to ·h 1e problem t 11 · . ~·J
. . .•. nur t1le probl~m i~ I . . s ow a pattern b . d . , s a mg Wllh two passengers anu
o
nn mluJIIVC t~n~wer . lluch Simpler than that F y tn uctlon, you can solve the problem rnor~ 4 Hint: Consider the events that starting from a point 11, you can reach all the rest of the points on the circle
. ocus on eve nts an d symmetry and vou will have
clockwise. n e {I •... , N} in a semicircle. Are these events mutually exclusive?
62 •
63
-
Probability Theory
A Practical Guide To Quantitative Finance Interviews

other p.oints within. a clockwise semicircle. Figure 4.1 clearly demonstrates this • n1 possible first entries,
conc lu s ~ on. If startmg at point i and proceeding clockwise along the circle. we
• n 2 possible second entries for each first entry,
sequent_tally encounter points i + I, i + 2, .. ·• N, 1., ... , i -1 within half a circle, the
• n possible third entries for each combinatio n of first and second entries, etc.
clockwt~e a~c between i -1 and i must be no less than half a circle. If we stan at any 3
other pomt, m order to reach all other poiots clockwise, the clockwise arc between i- 1 Then there are a total of n1 • 172 • • • nk possible outcomes.
!
and are always included. So we cannot reach all points within a clockwise semicircle
starling from any other points. Hence, all these events are mutually exclusive and we Permutation : A rearrangement of objects into distinct sequence (i .e., order matters).
have

UE,l \'
n!
Property: There are different pennutations of n objects, of wh ich n1 are
p(
N
= IP<E, )~P UE, Ji= Nx l i 2"'-
(N 1
=N I 2"'- 1 n1 !n2 !...nr!
•· f '-1 • I I alike, 172 are alike, · · ·, n, are alike.
~f:lc sa~)~ argumct:t can be extended ~o any arcs that have a length less than half a circle. Combination: An unordered collection of objects (i.e., order doesn't matter).
the r.a~to o~ the arc _leng~h .to the Circumference of the circle is x ( x ~ 1I 2 ), then the
probabthty ot all N pomts tmmg into the arc is N x XN-1 . 11
Propeny: There are ( ) = n! different combinations of n distinct objects taken
r (n-r) !r!
r at a time.

Binomial theorem: (x+ y)" = t(


k=-0
17
k
) xky"-•

lnclusion-Exclosion Principle; P(£1 u £ 2 ) =P(EI) + P(£2)- P(£,£?)


P(£ u £ u £ ) = P(£1) + P(£2 )+ P(£3 ) - P(£,£2 ) - P(E1EJ)- P(£2£ 3) + P(£,£2 £~ )
1 2 3

and more generally,

+(-1) N+l P( EI E2 ... E.'J )

1
Figure 4.1 N points fall in a clockwise se ..
where L P(E,, £ 1! ..• £,. ) has ( ~ \) terms.
,, ( 11 <.. ,,
mJclrcle starting from ;

4.2 Combinatorial Anal . Poker hands


Many problems in prob b't· YSIS Poker is a card game in which each player gets a hand of 5 c~rds. There are 52 cards in a
d'fll . a t tty theory ca b
1 crent \\·ays that a certain evem
. . deck. Each card has a value and belongs to a su1t. There are 13 values,
n e solved by stmply counting the number ot J·••k qu~cu ~~ r.~ au: ~!J<"lc dub b~~11 ,r,:un .n.l
often rdt!rred 1·o as combtnatorial
. can occur
. · The mat. hcmat1c
· thcorv ot, cow1t1ng
· IS·
1
c~)ver the basics of combinator"tal ania ~sts (or combinatorics). In this 'seclion we will
2, 3. 4. s. 6. 7, 8. 9, 10, J. Q, K. A. and four suits, • , 4, ., , + .
, . ana YSIS. '
Uasac prmciple of counting· Let <'1 b
· • e a set of 1ength-k sequences. If there are

65
Probability Theory
A Practical Guide To Quantitative Finance Interviews

What are the probabilities of getting hands with four·of-a-kind (four of the five cards Solution: Let's begi n with the simplest cases and consider solving the problem for any
with the same value)? Hands with a full house (three cards of one value and two cards of number of stairs using induction. For n =I , there is only one way and /(1) = 1. For
another value)? Hands with two pairs?
n == 2, we can have one 2-stair bop or two !-stair hops. So .f(2) = 2. For any n > 2,
Solution: The number of different hands of a five-card draw is the number of 5·element there are always two possibilities for the last hop, either it's a !-stair hop or a 2-stair hop.
ln the former case, the rabbit is at (n- 1) before reaching n, and it has /(n-1) ways lO
52
suhscts of a 52-clement set, so total number of hands = ( ) = 2, 598.960. reach (n -I). In the latter case, the rabbit is at (n- 2) before reaching n, and it has
\5 f(n - 2) ways to reach (n-2). So we have f(n)=f(n-2)+/(n - 1). Using this
Hands with a four-of·a-kiod: First we can choose the value of the four cards with the function we can calculate f( n) for n = 3, 4, · · · 6
same value. there are 13 choices. The 5th card can be any of the rest 48 cards (12
choices for values and 4 choices for suits). So the nu mber of hands with four-of-a kind is
13x48 =624.
Screwy pirates 2
Hands wit~ a Full House: In sequence we need to choose the value of the triple. 13 Having peacefully divided the loot (in chapter 2), the pirate team goes on for more
. h . f' l/41
ch01ces~ t e su1ts o the triple, ) choices; the value of the pair, J2 choices; and the
looting and expands the group to ll pirates. To protect their hard-won treasure, they
3 gather together to put all the loot in a safe. Still being a democrutic bunch, they decide
that only a majority - any majority - of them (2:6) together can open the safe. So they
suits of the pair, (; Jchoices. So the number of hands with full house is ask a locksmith to put a certain number of locks on the safe. To access the treasure,
every lock needs to be opened. Each lock can have multiple keys; but each key only

12x(~) = 13x 4x 12x6= 3, 744.


opens one lock. The locksmith can give more than one key to each pirate.
13x(;}
What is the smallest number of Jocks needed? And how many keys must each pirate
cany?7
Hands with Two Pa irs· In ·
.. ~· sequence we need to choose the values of the two pa1rs.
LJ) h · ~~ 4j\ choices~ the suits of the second pajr. (4
( 2. choices·· the ·s UJ' ts 0 f t e first pair, , 1
, )
Solution: This problem is a good example of the appJ i ~ation of combinatorial a naJ ys~s in
information sharing and cryptography. A general versiOn of the problem was expl~1ned
2 2
chotccs: and the remaining d 44 ( 52 in a 1979 paper "How 10 Share 0 Secret" by Adi Shamir. Let's randomly select 5 ptrates
. car • -4 x 2, since the last cards can not have the from the 11-member group; there must be a Jock that no~e of them h~s the key to. Yet
same value as etther pair) ch · • S h
otccs. o t e number of hands with two pairs is any of the other 6 pirates must have the key t~ this lock smce. any 6 ptrates can open all

(~H ~H~Jx44 = 78x6x 6x44 =123,552.


locks. In other words, we must have a "spectal" lock to whJch none of the 5 selected
pirates has a key and the other 6 pirates a~! have keys. Such 5-pirate g~oups .ar~ randomly
selected. So fo r each combination of 5 ptrates, there must be such a special lock. The
To calculate the probability of ea ·h
kind by the total possibl
. . .
b c r' we only need to dtvtde the number of hands ot each minimum number of Jocks needed
.IS (IJr) = 11!! !:::: 462 locks. Each lock has 6 keys,
.
· e num er o hands. 5 56
which are given to a unique 6-member subgroup. So each pirate must have
Hopping rabbit 4 62 x 6 =
252 kcvs. That's surely a lot of locks to put on a safe and a lot of keys for
11 ..
A rabhit sits at the bottom of a stairc. .
two stairs at a time How d'ffiase Wtth n stau s. The rabbit can hop up only one or each pirate to carry.
top of the stairs?5 · many 1 erent ways arc there fo r the rabbi t to ascend to the
6y · ed that the seqtl•'ncc
' Hint: Consid~!r an induct' ou may have recogmz "' is a cPC!tJCnce
J~t
of Fibonacci

numbers. •

; I . IOn approach. Befo th 1H'mt: every su bgroup o f 6 p1ra


· tes should have the same kcv • to a umque lock that the other 5 pirates do
ell 'ei the (n-l)th statr or the (n-'>)th st · r~ e final hop to reach the n-th stair the rabbit can be ai not have.
- a1r assummg n > 2_ • •

67
Probability Theory
A Practical Guide To Quantitative Finance Interviews

Chess tournament
A chess tournament has 2'' players with skills I > 2 > · · · >2n. It is orgaruzed as a Now let's move on to the counting approach. Figure 4.2A is the general case of what
happens in the final. Player 1 always wins, so he will be in the final. From the figure, it
knockout tournament, so that after each round only the winner proceeds to the next
round. Except for the final, opponents in each round are drawn at random. Let's also is obvious that 2" players are separated to two 2"- 1 -player subgroups and each group
assun~c that when .t~o players meet in a game, the player with better skills always wins. will have one player reaching the final. As shown in Figure 4.28 , for player 2 to reach
What s the;: probabthty that players I and 2 will meet in the final? 8 the final , he/she must be in a different subgroup from J. Since any of the remaining
players in 2, 3, · · ·, 2" are Iikely to be one of the (2''- 1 - I) players in the same subgroup
So!u~ion: Th~r~ ar~ nt least two approaches to soJve the problem. The standard approach as player 1 or one of the 2"- 1 players in the subgroup different from player I, the
~p~ltcs multJph~atiOn rule ?ased on conditional probability, while a counting approach probability that 2 is in a different subgroup from 1 and that I and 2 will meet in the final
Is tar more effic1cnt. (We will cover conditional probability in detail in the next section.)
. . 2"-1
IS stmply " _ . Clearly, the counting approach provides not only a simpler solution but
Let's begin with the conditional probability approach, which is easier to grasp. Since 2 1
there arc 1" . • s, the tournament w1·11 have n rounds (including the final). For round
- !)laver· also more insight to the problem.
1
l, players 2.3,. .. ,2" each have " _ probability to bel's rival, so the probability that General Case I & 2 in the Final
2 1
}" 2 2 (')II I 1 I
land 2 do not m~et in round 1 is.:___:.__-
2" _ - x ...n _ -1) · Cond"t' h l d 2 do not
1
1 2 1
1 IOn on t at an
t t
meet in round 1· ?" - · PJ·ayers proceed to the 2nd round and the conditional probability + +
1
that I and 2 will not meet in round 2 is T- -2 -_ 2 x (2n-
,-1 _
2
n_ 1 _
-1)
• We can repeat the same nth round 1 ? nth round l 2

1\ 1\ 1\ 1\
2 1 2 1
-
process untt'I thc (n -l)th d · . 2
.. roun • m whtch there are 2 (= 2" / 2"- 2 ) players left and the
condntonal
, probability that 1 and 2 Wt·· 11 not meet m . round (n- I) is ? + (n-J)th round I + 2 +
(n -1 )th round l +
~- ~2 _ 2 x (2~ -- 1)
1
? ? ? ?

- -I - - - I
1] ?1

L'-~t f.'• b~.: the ~vent that 1 and 2 do no~+ meet mmund

I·,
~ be- ,the event thau l and 2 do t . 2"·' players 2"·' players 2"" 1 players 2"' 1 players
no meet m rounds 1 and 2;
A 8
1
Figure 4.2A The general case of separating 2n players into 2"· -player subgroups;
Fll he the ~vent that I and ) do not n
I .
- 'leet m round I, 2,. .. , n _ 1. 4.29 The special case with players 1 and 2 in different groups
AJilply the mtlltiplication ruk. we have
P(l and 2 meet in the nth game):::;: P(E) x P(E
" ' . . , ., 1 1 , E, )X···xP(E IEE···E) Application letters
.! X(_ - l) 2x(2" ~ - !) ? ~- I • n -l 1 2 n- l
x - x(2 -- 1) 2"-1
2"- ) '")" I l X···X -~-......:.!... You're sending job applications to 5 firms : Morgan Stanley, Lehman Brothers, UBS.
... - 2l -I =2< - l Goldman Sachs. and Merrill Lynch. You have 5 envelopes on the table neatly typed with
names and addresses of people at these 5 finns. You even have 5 cover letters
~ Hint: Consider ""CP'Lrnt· personalized to each of these firms. Your 3-year-old tried to be helpful and stuffed each
' • lllg t he pla)•ers. t
2· -· subgroups.. What
!lame !.!T11 11 l '> Or
- P· ·
not m the same group? o two
Will
. happen if player 1 and 2 .111 the cover letter into each of the envelopes for you. Lnfortunately she randomly put letters

68
69
Probability Theory
A Practical Guide To Quantitative Finance Interviews

into envelopes without realizing that the letters are personalized. What is the probability
that all 5 cover letters are mailed to the wrong firms?9 :. P(~E) = l -2_ +~ -J_ +_.!_ = .!2_
/ -'I 2! 3! 4! 5! 30
I

Sulurion: This problem is a classic example for the Inclusion-Exclusion Principii:. In tact } ) ll
a more general case is an example in Ross' textbook First Course in Probability. So the probability that all 5 letters are mailed to the wrong firms is I- P ( uE, =-.
,. , 30
Let's denote by £,. i =1 ~···.5 the event that the i-th letter has the correct envelope. Then

P( ~f.',) is the probability that at least one letter has the correct envelope and Birthday problem
How many people do we need in a class to make the probability that two people have the
1-P(~t ) •-1 J
is the probability that all letters have the \vtong envelopes. p U
1

I
5

I
£,)can same birthday more than 1/2? (For simplicity, assume 365 days a year.)
be calculated using the Inclusion-Exclusion Principle: Solution: The number is surprisingly small: 23. Let's say we have n people in the class.
Without any restrictions, we have 365 possibilities for each individual 's birthday. The
P(~E,)= ±P(£)- LP(E, EJ+···+(-ItP(EE ···E)
I I I J • I 1 5 basic principle of counting tells us that there are 365" possible sequences.
1.. ,·
1<:sJ
We want to fi nd the number of those sequences that have no duplication of birthdays.
For the first individual we can choose any of the 365 days; but for the second, onJy 364
' .
remaining choices left, ... , for the rth individual, there are 365 - r + 1 chotces. So for n
It, s obv10us
. I
S.
that P( E,) = \i i = l, ... , 5 . So
s
P( £,) =I. L people there are 365 x 364 x · · · x (365 - n + l) possible sequences where no two
1~1
365 X )64 X · ·· X (365 - n + 1)
P( E' 1E'! ) is the event tl1at both 1ctter 1· and 1etter 1,. have the correct envelope. The individuals have the same birthday. We need to have , < 112
1 365
probability that ;, has the correct envelope is l/5; Co~ditioned on that i has the correct for the odds to be in our favor. The smallest such n is 23.
1
envelope, the probability th t 1· h
a ~ as the correct envelope is 1/4 (there are only 4
en\'elopes left). So P(E,/.) = ~ x ~ == (5 - 2)1 100th digit
) 5-1 5!
What is the 100th digit to the right of the decimal point in the decimal representation of
There an! (
\2
5
)=2!(5-5! 2)! members of, P(E,. E,) in LP(E, E, ) , so we have
(l + J2 ) 3000 ?10
1 l

Solution: If you still have not figure out the solution from the hint, here is one more hint:
(I + J2 )" + ( 1- J2)" is an integer when n == 3000 .

Applying the binomial theorem for (x + y)", we have

(l+-'2)" =t.(:}"-•-'2' =. 't)~}·-•-'2' ~ + ,_, ) : }· ' J2'

Hint: ·n,e complem\!nt is that at least o I . . ]IJ Hint: (I - J2 ): + (l - J2 r : 6 . What will happen to (I - .fi )~n as 11 becomes large?
ne ettcr IS maJied to the correct finn.
70 71
Probability Theory
-
A Practical Guide To Quantitative finance Interviews

Law o(tota/ probahiliry: fo r any mutually exclusive events {r;}, i=l ,2, .. ·,n, whose
n
union is the entire sample space ( F, n Fi = <1>, "if i :;t: j; UF, = n ), we have
r;:; )" +(J -Ji)"
So (I + v£ -2
-
""
k=!;;;s.~ k
(nJl"-1 "Lrt , whrch· .rs always an .mteger. It is easy to 1=1

"
2 P(E) = P(EF;) + P(EF;) + .. . + P(EF,,) = LP(E I F, )P(F,)
see that 0 <(1- fiiooo << w-' 00. So the JOOth digit of (l + .fi)" must be 9. /cl

= P(E IF; )P(f;) + P(E I f;)P(F; ) + · ·· + P(E I F,,)P(F,,)

Cubic of integer Independen t events: P(EF) =P(E)P(F) ~ P(EFc ) = P(E)P(F(.) .

Let X be an integer between J a d I o'2 h 15. . Independence is a symmetric relation: X is independent ofY c:> Y is independent of X.
with II ?" n 'w at the probability that the cubic of x ends
P(E IF1 )P(F)
Bayes' Formula.· P(F, 1E) = , ' ·c
1 rc;. 1· = I, · · ·, n, are mutua IIy
Solution: All integers can be e
A .
d
xpresse as x = a+ IOb, where a is the last digit of x. ,L P(E IF,.)P(F,)
,..,
pplyrng the binomial theorem, we have ~ = (a+ 1Ob) 1 = 0 J + 300 2b + JOOab2 + OOOb;.
1 exclusive events whose union is the entire sample space.
3
The unit digit of x onlv d d :l 3
this requ'rc t d .{ epe~ son a . So a has a unit digit of 1. Only a= l satisfies As the following examples will demonstrate, not all conditional probability problems
t men an " =1 Smce aJ - I 1J1
so "'e, must · - • e tent h dtglt
have that 3b ends in l wh' .
. . ,
only depends on 30a·b = 30h. have intuitive solutions. Many demand logical analysis instead.
Consequentlv the last two d. . • ' tch reqUi res the last digit of b to be 7.
·Integers between
'' 1 and 10'2. rgtts otxshouldbe71 ' wh'hh .. of 1% Jor
as a probab1ltty r:
IC Boys and girls
Part A. A co mpany is holding a dinner for workjng mothers ~ith at least one so n. Ms.
Jackson, a mother wi th two children, is invited. What is the probaffitity tl1at both
4.~ Conditional Probability and Bayes' formula children are boys? k
r, > J ~- .. .... ,
Many .tinanctal transactions are res onses .. .
most l1kely incomplete- · r .P
tn10m1at1on. Co d·r
to probabtlr ty adjustments based on new-and
..
Solwion: The sample space of two children is given by n = {(b ,b), (b,g),(g,b),(g,g)}
popular tt:s! subjects in quant't t' . n .1 JOna 1 probabthty surely is one of the most (e.g., (g , b) means the older child is a girl and the younger child a boy), a.nd each
.. 1 a tve mtervrews s · h' . .
condtltonal probability defi ·t· , · o m t 1s section, we focus on baste outcome has the same probability. Since Ms. Jackson is invi ted, she has at least one son.
lilt tons and theorems.
Let B be the event that at least one of the children is a boy and A he the event that both
Conditional p b bT children are boys, we have
ro a 'tty P(A I B): If P(B) > 0, then P(A / 8) = P(A B) is the fraction
of B Outcomes that are also if
.· outcomes.
P(B) P(AIB)= P(A nB) = - P( {(b,b)})~ == 11 4 =~ .
Multiplicntion Ru/1!: P( El £ , ... E == P(B) P({(b,b),(b,K),(g,b)}) 314 3
- , ) P(EI)P(E2 1EI)P(£J I E,£2) ·· ·P(E., 1£, .. . £ ,).

Part B. Your new collcaoue, Ms. Parker is known to have two children. If you see her
walking with one of her ~hildren and that child is a boy. what is the probability that both
children arc boys?
" trrnt: rlrc h~ttwo digits of rJ I
. on y depend on the last two digits ofx.

73
Probability Theory
A Practical Guide To Quantitative Finance Interviews

Soltllion: the other child is equally likely to be a boy or a girl (independent of the boy up heads. So P(B I A'') = (1/2) 10 = J/ l 024. Plug in all the available information and we
you've seen), so the probability that both children are boys is 1/2.
have the answer:
Notice the subtle difference between part A and part B. In part A. the problem essentiallY
asks given t~ere is at least one boy in two children, what is the conditi onal probabi lit)· P(A I B)= P(B I A)P(A) = 1/JOOOxl ~o.s.
that ??lh chtldren .a.re boys. Part 8 asks that given one chi ld is a boy, what is the P(B I A)P(A) + P(B I Ac)P(A'' ) 1/1 OOOx 1+999 / 1000 X 1/ 1024
cond1t10nal probab1hty that the other child is also a boy. For bo th pans. we need to
assume that each child is equal likely to be a boy or a girl.
Fair probability from an unfair coin
If you have an unfair coin, which may bias toward either heads or tails at an unknown
All-girl world? probability, can you generate even odds using this coin?
In a primitiv~ society, every couple prefers to have a baby gi rl. There is a 50% chance
Solution: Un like fair coins, we clearly can not generate even odds with one toss using an
~hat each chtld they have is a girl, and the genders of their children are mutually
mdependent. ~f each co~ple insists.on having more children until they get a girl and once unfair coin. How about using 2 tosses? Let pH be the probability the coin will yield
tfrhey .have a ~~rl .they. W ill stop havmg more children, what will eventually happen to the head, and Pr be the probability the coin will yield tails (PH+ p., =l ). Consider two
act ton of g1rls m th1s society? independent tosses. We have four possible outcomes HH, HT, TH and 1T with
probabilities P(HH)=PHPH• P(HT)=P"Pr• P(TH )=PrPH• and P(TT)=PrPr·
b· bT It was surprisino
Solwion: . 0 that many mtervtewees-mclude
· . . many who studied
~ro ; ~,Ity~have the ~ms~onceptioo that there wi ll be more girls. Do not let the word So we have P( HT) =P(TH). By assigning HT to winning and TH to losing, we can
~~c er an Ia wrong tntUition misguide you. 'lbe fraction of baby girls are driven b"
tM ure, or at east the X and y chromosomes b .
generate even odds.12 'r Vo
I..J ~ J. r ){I 0 I , 'I i. r
need to look at th k . [I . ' not Y the couples' preference. You only
equal probability ~f :~~~ ~r:atlon: 5?% and independence. Every new-born child has
So the fnction of g· b::> . Y or a gtrl regardless of the gender of any other children. Dart game
1
<
stay stable at 50%. 1r s orn IS always SOo/c0 and tl1e r.HactJOns
· ·
of g1rls · ·
m the soctety w1
'II
Jason throws two darts at a dartboard, aiming for the center. The second dart lands
farther from the center than the first. If Jason throws a third dart aiming for the cenler,
what is the probability that the third tluow is farther from the center than the first?
Unfair coin Assume Jason's skillfulness is constant
You are given 1000 coins i\.m h .
0
coins an: t~tir coins. y ~ ·ra d onT t -~n, 1 com ?as heads on both sides. The other 999 Solution: A standard answer directly applies the conditional probability by enumerating
coin turn::; up heads. What i~ ~h~mr~bc ~~se a com an~ toss it I 0 times. Each time. the all possible outcomes. If we rank the three darts' results from the best (A) to the worst
P ability that the com you choose is the unfair one? (C), there are 6 possible outcomes with equal probability:
Sulwiun: This is a chssic co0 d't' 1 1 11 I
A beth~ event that ~~~ ·c hos ? ~ probability question that uses Bayes , theorem. Let
· · ·en
(:Otn •s a tair ont!. Lt:t IJ be th
com ts the unfa·tr one, then Ac is the event that the chosen
e event that aH ten tosses tum u head A lv Bayes·
theorem ''e have P( .l l B) :: P(B I A)P(A)::: P(B I A)P(~ s. PP.
. . P(B) P(B I A)P(A) + P(B; A'.)P{A<').
1 he pnor.> are Pl A) = Ill 000 and p ' - 12 I should point out that this simple approach is not the mo_!>1 efficient ~pproach since r am ?isregarding
turnsuphcads. so J>(BIA)= I (A_ ) ~ 9 99 1 1000. lf the coin is untair. it always the cases HH and TT. When the coin has high bias (one sid~ •s far more likely than the .other s1d~ to occ~r).
· Ifthe com 1s ra·tr. eacb hmc
. .1t has 1/2 probability tunllng
. the method may take man , runs 10 generate one uSI!ful result. For more c~mplex algonthl~ that mcre~mg
efficiency, please refer 10>Tree Algo!Jthms [~r l. ';WUJ.Yc!d tnit!J<J.Eing wtlh_g /li(Ued Corn by Qucntm F.
Stout and Bette L. Warren. Annals ofProbab1hLy I:!Il QS·n. PP· 2 12-222

74 75
2&

Probability Theory
A Practical Guide To Quantitative Finance Interviews

Outcome 2 3 4 5 6 don't know anyone else's birthday and all binhdays are distributed randomly throughout
c the year (assuming 365 da,i's in a year), what position in line gives you the largest chance
1st throw A 8 A B c of getting the free ticket? 1
2nd throw B A c A c B
3rd throw c c B B A A Solution; If you have solved the problem that no two people have the same birthday in
an n-people group, this new problem is just a small extension. Assume that you choose
The information from the first two throws eliminates outcomes 2, 4 and 6. Conditioned to be the n-th person in line. In order for you to get the free ticket, all of the first n -l
on outcomes I, 3, and 5, the outcomes that the 3rd throw js worse than the 1st throw are individuals in line must have different birthdays and your birthday needs to be the same
outcomes 1 and 3. So there is 213 probability that the third throw is farther from the as one of those n -l individuals.
center than the first.
This approach surel~ is reasonable. Nevertheless, it is not an efficient approach. WlJen p(n) =p(first n -l people havenosamebirthday) x p(youn among those n -l birthdays)
the number o~ darts 1s smalL we can easily enumerate all outcomes. What jf it is a more 365_
_ 364
x __
x .._· (365- n +_
;,..___ _ 2) Xn-
--I
complex verst on of the original problem:
365"-l 365
~ason thro_ws n (n ~ 5) darts at a dartboard, aiming for the center. Each subseguent dart
15
J~~9~e_ceo.terJhan e fir·t dart. If ~ason throws the (n+ i) rh dart~~wn ;~ It is intuitive to argue that when n is small, increasing n will increase your chance of
pr~b@y that It IS also farther from the CeQ!er-t-hanhisJir:,t? - -· - - getting the free ticket since the increase of p (yours among those n -I birlhdays) is
This q~estion is equivalent to a simple question: what is the probability that the {n --- 1)/h more significant than the decrease in p(firsl n -I people have no same birthday). So
throw lS not the hcst among all { 1) hr ? s· when n is small, we have P(n) > P(n-1). As n increases, grad ually the negative impact
fi n + t ows · mce the Ist throw is the best among the
trst n throws, essentially 1 ~m saying the event that the (n + l)th throw is the best of all of p (first 17 - 1 people have no some birthday) will catch up and at a certain point we
(n +I) throws (lefs call it · -~ - --- · · - · - -
.- _ A,,~, ) ts mdependent of the event that the Jst throw is the best will have P(n+l)< P(n). So we need to find such ann that satisfies P(n)> P(n-1)
ot the first n throws {Let's call 1·t A ) 1 f . .
thr 1 .....:. n act, A,., IS mdependent of the order of the first and P(n) > P(n +I).
II ows. Are these two events real!, . d d ? ..
is not obvious to you that A . . ) tn epen ent · The answer is a resounding yes. It tl
. , _, IS Independent of the order of the first n throws. let's look 365 364 365-(n-3) n - 2
at ll another way· the order of th ti - P(n-1)=-x-x···X ·- -· x~
. . · e trst n throws is independent of A . Surely this claim 365 365 365 ~65
IS consptcuous. l3ut indep, d . . ,, .. ,
I/( n + I). the probability h en ence ts sym~etnc~ Since the probability of A,/., is
P(n) = 365 x 364 x- .. x 365-(n-2) x~
365 365 365
365
. . . t at (n + l)lh throw IS not the best is n l(n + I) _u
!·or the o. ngmal versi.Otl th d 365 364 365-(n-2) 365-(n-l)x~
· · ree arts arc thr · · n P( n + 1) = - x- x ... x x 36~ 365
chance of being the best thr , A own. mdependentJy, they each have a J. J 365 365 365 ~
1
worse than the first dart Th U\\~ s ong as the thtrd dart is not the best throw, it will be
· erc 1orc the answer is 2/3. ·
365 - (n-2) n - 1 n-2
2
P(n) > P(n -1 ) => 365 x 365 > 365 n - 3n - 363 < 0 }
:::=> on= 20
Birthday line Hence, 2
n -n - 365 > 0
n - l 365 - (n - I) n
.'~I u movie theater. a whimsical m l P(n) > P(n + l) o 365 > 365 x 365
t~rst P~rson in line whose b'nhd an~ger announces that she will give a free ticket to the
ttckct. You UTI! given the o t a~ ts the same as someone who has aJread) bought a You should be the 20th person in line.
pponurutv to chouse ·. . . . .
• any POSitiOn m Ime. Assurmng that ) 00
11
I !ere vuu cnn · 14H. If • · - to get the free ticket. the first (n-1) people in line must not have
. agam use syrnmctry argument· . mt: you are the n-L•l person m 1me. . f h
. each throw IS equally likely to beth~: best. the same binhday and you must have the same bmhday as one 0 t em .
76
77
Probability Theory
A Practical Guide To Quantilalive Finance Interviews

Dice order Amoeba population


We throw 3 dice one by one. What is the probability that we obtain 3 points in stricth· Th~r~ is a one amo~b~ in a pond ..Aft~very ~inute the am?eba may die. st~y the same,
increasing order? 15 • spht mto two or s~o three wtth equal probabilitLAII its offspring, if it has any, wil l
behave the same (and independent of other amoebas). What is the probability the
S~Jl~tlion:
To have 3 points in strictly increasing order, first all three points must be amoeba population will die out?
?ttlere~t numbers .. Co~ditioned onthree different numbers, the probability of strictly
mcrcasm~ order ts stmply 1/3! =J /6 (one specific sequence out of all possible Solwion: This is just another standard conditional probability problem once you realize
permutations). So we have w~ need to derive the probability conditioned on what happens to the amoeba one
P = P(diffcrcnt numbers in all three throws) x ?(increasing orderl3 different numbers) mmute later. Let P(E) be the probability that the amoeba population will die out and
apply the law of total probability conditioned on what happens to the amoeba one
"'· (lx %xi)x7;=5/54
minute later:
P(E) = P(E I F;)P(F;) + P(E I F2)P(F;) + .. · + P(E IF,,)P(F,,) .
Monty Hall problem For the original amoeba, as stated in the question, there are four possible mutually
MDonty Hall problem i~ a probability puzzle based on an old American show Lei's Make excJusive events each with probability l/4. Let's denote F; as the event the amoeba dies;
a eal. ,The .problem ts· named
. after the show ' s host. Suppose you're on the show now. F; as the event that it stays the same; F; as the event that it splits into two; ~ as the
andtyoure
, y gtven
d . the chotce of 3 .doors. B eh'md one door IS . a car; behind the other two.
event that it splits into three. For event F;, P(£ IF;) = I since no amoeba is left.
goa s. ou on t know ahead of lime what is behind each of the doors.
P(E I F;)=P(E) since the state is the same as the beginning. For F1 , there are two
You pick one of the doors a d .
one of the other two d nh a~nounce lt. As soon as you pick the door, Monty opens amoebas; either behaves the same as the original one. The total amoeba population will
option to either kee ' oors ~ l ~t le k~ows has a _goat behind l.t. Then he gives you the die only if both amoebas die out. Since they are independent, the probability that they
What is the probab·f·~ oufr o~tgt~al cholc~ or switch to the third door. Should you switch?
1 1 Y 0 wmnmg a car tf you switch? both wiJJ die out is P(£) 2 • Similarly we have P(FJ =P(E)". Plug in aJI the numbers,
2
the equation becomes P(£) = 1/ 4x I+ 1/ 4x P(E) + 1/4 x P(£) + JI 4 x I'(El Solve
SoluJion: If you don't switch wh 1 .
of showing vou a goat so ' etbler.~ou Wln _or not is independent of Monty 's action this equation with the restriction 0 < P( E)< I~ and we will get P( E)= J2-) : : : 0.414
- , your pro abthty 0 f · ·
\vould argue that since there are onJ . wmnmg IS 1/3. What if you switcl~? Many
the probability of winning ·s /? B Y~ 0 ~oors left after Monty shows a door w1th goat. (The other two roots of the equation are I and - fi -1 ).
, 1 1 -· ut IS this argument correct?

It yo.u h.Jok at the problem from a differ . .. .


a s~Yttching slrategy. you win the car if ~nt pe~:sp~ctlve, th_e .answer becomes clear. Us~ng Candies in a jar
whJCh has a probability of ~ (Y , . and only 1f you ongtnally pick a door with a goat.
another noat so the 011
21
.> ou p1ck a do or wtt· h a goat Montv shows a door WI'th You are taking out candies one by one from a jar that has 10 red candies, 20 blue candies,
. :::. ' -
.
e you swttch t h ' . .• · . . . and 30 green candies in it. What is the probability that th~re arc at least I16blue candy and
picked the dnor with the car h'
S
°
must ave a car behtod tt). If you ongmally
, w IC1\ 1las a probabTty f 1/3 . . h. l green candy lefi in the jar when you have taken out all the red candies?
0 your probability of winning b , . ,· h' . 11 o , you wtll Jose by sw1tc mg.
) sv.ttc mg ts actually 2/3.
Solution: At first look, this problem appears to be a combinatorial one. However, a
conditional probability approach gives a much more intuitive answt:r. Let T,, 7;. and T.~

16 Hint: (f there are at least 1 blue candy and 1 green candy left. the last red candy rnusl have been

removed befor~ the last blue candy and the last green candy in the sc<Jucnce of 60 candies. What i!> the
15
probability that the blue candy is the last one in the 60-candy sequence? Con<.lilioned on that, what is the
Hint· T · · .
in a SC. 0 O~larn. 3 ~lniS Ill Strictly incr~in r probability that the last gre~n candy is the last one in the 30-candy sequence {10 red, 20 green)? What if
· quen~..~. stnclly mcreasing order is one ~~~er, th~ 3 P<>1ms must be dif'ft.!rent. For 3 diO"'erent po~ntS
0
• •

the green candy is the last one in the 60-cand)' sequence? )' ,,
posstble pennulations.
78 79
I Probabil ity Theory
J
A Practical Guide To Quantilat ive Finance ln!erviews
be the number that the last ed bl d·
hav - t I I bl - -- ..!_;__, ~:..an _s:_een candtes are taken out respective!)'. To
J
. , e a deast ue candy and I green candy left when all the red candies- are taken out becomes the first one to toss an H. ln that case, A has ( l- P(A 1H)) probability of
v. c nee to have T < T. and T T I ,
r h r < !! n other words, we want to derire winning. So P(AIH)=l l 2x0+11 2(1- P(A[H))~P(AIH)= l l3
0

P(T < T. 11 T < T ) The .


' ~ ' .. x · re are two mutually exclus1ve events that satisfy T, < r, and
Combining all the available information, we have
T, < T~: : ~ < 7" < T. and T < T < r.
~ ' K II '
P(A) = l /2x l/ 3 +I /2(1- P(A)) ~ P(A) = 4 / 9.
:. f(T, <T, n T, < T,) = P(T, < T,. < T,) + P(T < T < T.)
~ r !! h
T, < 1;, < 7',. means that the last cand · · Sanity check: we can see that P(A) <I /2, which is reasonable since A cannot win in his
are c . II · J'k Y IS green ( T~ = 60 ). Smce each of the 60 candies first toss, yet B has I /4 probability to win in her first toss.
qua Y ' c1Y to be the las1 cand d
., 30 Y an among them 30 are green ones, we hare
P(l~. - 60) = - . Conditioned on r - 60
60 ;: - ' we need P(T, < T,, I Tn = 60). Among the 30
Russian roulette series
red and blue candies each cand i .
• y s again equally likely to be the last candy and there are Let's play a traditional version of Russian roulette. A single bullet is put into a 6-
20 blue candies, so P(T < r. 1T = 60) _ 20 30 20 chamber revolver. The barrel is randomly spWl so that each chamber is eq ually likely to
' " ~ - 30 and P(T, < T, < T) =- x - Sjmilarl\'
f/ 60 30 ° , , be under the hammer. Two players take turns to pull the trigger- with the gun
we have P(T, < r~ < 1,.) = 20 x 30 unfortunately pointing at one's oWid1ead - without further spinnin~; until the gun goes
. 60 40' off and the _e_er~9!:!_ who gets killed loses. If you, one"'fllle playt'rs, cnn cnoosc to go-first
He nc~.
orsecond, .how wili you-choose-? And what is your probability of loss?

Solution: Many people have the wrong impression that the first person has higher
probabi lity of loss. After all, the first player has a J/6 chance of getting killed in the first
~ound before the second player starts. Unfortunately, this is one of the few times that
Coin toss game Intuition is wrong. Once the barrel is spun, the position of the bullet is fixed. If you go
Two players A d . first, you lose if and only if the bullet is in chamber I, J and 5. So the probability that
1
h . , an 8 'alternattvely toss a fa. . you lose is the same as the second player, 112. In that sense, whether to go first or second
e com, then A, then B ) Th Jr COin (A tosses the coin first then B tosses
h d fl0 ll . . . . e sequence f h d . , does not matter. -
~a . owed by a tail (Hr subs uence 0 ea s aod tatls is recorded. If there is a
tall wms. What is the probability~· A ): the game ends and the person who tosses the
at wms the garne') l7 Now, Jet's change the rule slightly. We ·will spin the barrel again after every trigger pull.
SoJwion: Let P( ·I) b 1 · Will you choose to be the first or the second player? And what is your probabjlity of loss?
p 8 , c t h.~ probability that A ,· . .
( ) ::. I - P( A). L~t' s condition P(A) , Wtns, then the probability that B wins IS
Solution: The difference is that each run now becomes independent. Assume that the
(n~ds) und 112 probabi litY~~( .... on A s"[II~ toss, which has J/2 probability of H first player's probability of losing is p. then the second player's probabili ty of losing is
J> tails).
( A)= 112P(A I H)+ 112P(A IT} 1- p. Let's condi tion the probability on the first person's fir~t trigger pull. He has 1/6
A' s firsr to ;,. T lh 0
If -- pr:oba bility of losing in this run. Otherwise, he essentially becomes the second player in
HT ~ubsrqucn . ')
· · ......
s- en o
c~.: ·' owe have P(A 1T) _
·
ess~!lt!1!J.!.Y becomes th fi , .
-~~~s (An HIS required Jor the
. , the game with new (conditional) probabili ty of losi ng I- p. That happens with
probability 5/6. That gives us p = tx 116+(l- p)xS/6 ~ p= 6111. So you should
It·· 1' ~ - P(B) =1- P( A)
/ s first toss en l . · · choose to be the second player and have 5/ I 1 probability of losing.
of gcltin, T . t s tn If. lct >s further cond't'
g . m that cuse A loses. For the 1~~on on B'_s. first toss. B has l/2 probability
__ - probabthty that B gets H. B essentiall}' lf instead of one bullet, two bullets are ~al}domly put in t~ chan1~r. Your opponent
,, lrnt:-:--------
~~·
condition on th~ I -
played the first and he was alive a1ler the first trigger pull. You are given the option
whether to spin the barrel. Should you spin the barrel?
resu t of A's fin;ttoss and use S)• m
metry
80 °

81
-
Probability Theory
A Practical Guide To Quanti1a1ive Finance Interviews

Solution: if you spin the barrel, the probability that you will lose in this round is 2/6. If
needs to have one ace, we can distribute the aces first, which has 4! ways. Then we
y~u don ' t spin th_e_ barrel , there are only 5 chambers left and your probability of losing Ln
48!
th1s round (cond1t10ned on that your opponent survived) is 2/5. So you should spin the di stri bute the rest 48 cards to 4 players with 12 cards each, which has - -- -
barrel. 12!12!12!12!
permutations. So the probability that each of them will have an Ace is
Wb~t if th~ two bullets are randomly put in two consecutive positions? If your opponent 48! 52! 52 39 26 13
surv1ved h1s first round, shouJd you spin the barret? 4!x + =- x-x- x- .
12!12!12!12! 13!13!13!13! 52 Sl 50 49
Solution: Now ~e have _to condition our probability on the fact that the position!> of the The logic becomes clearer if we use a conditional probability approach. Let's begin with
two bu llets are consecutive. As shown in Figure 4.3, let's label the em pty chambers as I, any one of the four aces; it has probability 52 I 52= 1 of belonging to a pile. TI1e second
2. 3 and 4; lab~l the o~e_s with bullets 5 and 6. Since your opponent survived the first ace can be any of the remaining 51 cards, among whi ch 39 belong to a pile different
ro~md, the possible pos1t~on he encountered is I, 2, 3 or 4 wi th equal probability. With from the first ace. So the probability that the second ace is not in the pi le of the first ace
11
~_ch~?ce. ~he next ?ne IS a _bullet (the position was 4). So if you don' t spin, the chance is 39 I 51 . Now there are 50 cards left, among wh.ich 26 belong to the other two piles. So
~It s~l~vJva! J~ 3/4. It you spm ~he barrel, each position has equal probability of being the conditional probability that the third ace is in one of the other 2 pi les given the firs t
c lOsul, and your chance of survtval is only 2/3. So you should not spin the barrel. two aces are already in djfferent piles is 26/50. Similarly, the conditional probability
that the fourth ace is in the pile different from the first three aces given that the first
/~ -- three aces are in different piles is 13/49. So the probability that each pile has an ace is

( 0) 8
'
lx 39x26xQ
5 t 50 49.

Gambler's ruin problem


A gambler starts with an initial fortune of i dollars. On each successive game, the
gambler wi ns $1 with probability p, 0 < p < 1, or loses $1 with probabili ty q =l- p. He
will stop jf he ejther accumulates N dollars or loses all his money. What is !he
probability that he will end up with N dollars? tA ) -> f , . .- J. _ ) ,J.. f -../.
1
Solution: This is a classic textbook probabi lity problem culled the Gambler's Ruirr{
Problem. Interestingly, it is stiiJ widely used in quantitat ive interviews.
............. ~

From any initial state i (the dollars the gambler has}. 0 ~ i ~ N, let P. be the probabili ty
Figure 4.3 Russian ro~;;:~h tw .
0 consecutrve bullets. that the gambler's fortune will reach N instead of 0. The oext state is either i +I 1..vith
probability p or ; -1 with probability q. So we have
Aces
p u=: - ~ )
2

Fifty- rwo cards arc randomly d·~ 'b I I -·J 1


!L 1 p. ) cP,_, -
P = pPa) + qP => P~ ~~ - P = p <P- P , > =(!L
I
P.-) ) =.. · =(!L)'
What is the probability that ~acltstrft uted t~ 4 players with each play~.:r g~:tting 13 cards.
l o them Will have an ace'J We also have the boundary probabilities Po = 0 and P_, =1·
So/wion: The problem can be . . .
answered usmg st d d · 'b te So starting from ~,we can successively evaluate P, as an expression of ~ :
52 cards 1 4 . an ar counting methods. ·1o d1strt u
1
. o p ayers With 13 cards each h 52'
. · . 1f l:UC
as ! ! · !IJ! permutations. -. h player
13 13 13
83
Probability Theory
A Practical Guide To Quantitative Finance Interviews

P~.l = p ( (4,1) I (3, I)) X ~ I+ p ((4,1) 1(3, 2)) XP.) ') =~ X ]_ + 0 X..!..= .!.
. ·- 3 2 2 3
P4.2 = P( (4,2) I (3, l)) XP31+ P((4,2) I (3,2)) X Pn = ]_ x ~ + .!.x J.. =J..
' ··- 32 32 3

~.3 = p ( ( 4, 3) I(3, 1)) X~.I + p (< 4,3) I(3,2)) Xpl]


.
= 0 X..!..+~ X.!.=.!.
2 3 2 3

The results indicate that P,,_x = ~l , Vk =1, 2, .. ·, n - I , and give the hint that the law of
n-
total probability can be used in the induction step.
Extending this expression to p·" 'we I1avc . 1
Induction step: gtven that Pn.k = -n -l ' Vk = I' ?- ,· · · ' n- I, we need to prove

)_=l'r + i.p +... + (!!._p J·' -~] p, -.- J1--qcq pp)'\ ~' . q p :;: t
' ·" - I I
1
I if I
1
P,.l) =- --- --
(n+l)-1 n
'\1 k = 1, 2, · · ·, n. To show it, simpl y apply the law of total

l N~, ifq lp=l probability:


1-qlp • { P,••,~, =P( miss I(n,k)) P,,,k + P( score I(n,k -1) )P,)-t
~= '* ·r
+- ~t~l k~l n~l ~
I
::::> I - (q I p )"' , l[ q I p l l - ( q I p) p
{ li N . ~P, = l - (qlpt "~ p:t:JI2
· ifq l p=l i iN . + =
, ifp=l/2
1
The equation is also appl icable to the P,...• and P, ....n' although in these cases k- = 0
Basketball scores n

A bask(!tball player is takino 100 ~·


through
. the Itoop and zero pointe
sl throws
·rJ.fCe . · She scores
. . 1f
one pomt . the ball passes J
and (1- ~ = 0, respectively. So we have P,,, = n ~ , '<1 k = 1, 2, .. ·, n - I and '<1 n ~ 2.
1
1
~ 0.11 her second. I·•or each of th· 1e.... mtsses
m1ssed ll . · Sh• e has scored
. on her first throw and Hence, ~oo.so =I 199.
I1c traction of th rows s 1e has made soe far
tthe !O ·OWJno throw th
F e b b' · · ·
. _e pro a 1hty of her scorutg IS
1
• 40, 111. t1lrm.,~, the probability that sh. :. or cxa~plc, If she has scored 23 points at1er
5~~\-\sk(mcl,~dtng the first and the se~o~:)J 11. ~cor.e tn the 41th throw is 23/40. After !00
11
Cars on road
as ·cts'?" · · · w at IS the probability that she scon;s exactly
!fthe probability of observing at least one car on a highway during any 20-minute time
Solution: Let (n k ) 1< k tnterval is 6091625, then what is the probability of observing at least one car during any
tlmn... s d p ' · - s; 11 · be the event that the 1 . 5-minute time interval? Assume that the QrQ.bability of seeing a car a~~.Y._moment _i~
=
an n.t P ( (n. k )) Th . . P ayer scores k baskets after n
• ~J . . · e solut1on 15 su · · 1 . . . uniform (constant) for the entire 20 minutes.
3 ~proac t starting with n =
' ~ = I/ ? and p
· -
3
.
1.!
Th .
=112. For the ,
(pn smg YSi mple 1f we use <m inducuon
e thrrd throw has l/2 b ..
pro abrhty of scorino. So we ha,e
-
Solution: We can break down the 20-minute interval into a sequence of 4 non-
prob·abT
·1 tty case when 11 = 4, let's apply the °law of total overlapping 5-minute intervals. Because of constant default probability (of observing a
car). the probability of observing a car in any 5-minute interval is constant Let's denote
~ flint : At!aiu don I the probability to be p, then the probability that in any 5-minutc interval we do not
patr~m b ~. ·, . 01 et the number 100 .
> mcrcasJng n; and rov scares you. Start with . - observe a car is 1- p .
P e the pauem usinu ·ndu t' smallest n, solve the problem · trv 10 tmda
o 1 c ton. · ·
84
85
-
Probability Theory
A Practical Guide To Quantitative Finance Interviews

The probability that we do not observe any car in all four of such independent 5-minute independently a success with probability p. ~qisson random vari~ble repres~ts the.
4
intervals is (1- p) = I- 609 / 625 = 16/625, which gives p = 315. n_~mber of e~ents. oc~~rl~& in a fix~d period of time with the expec~~~ . numb~~ o~
occurrences l..t when events occur with a lnown average ra1e .t and arc mde_P.enden~ of
the time since the fast event. Geometric random variable represents the trial number (n)
4.4 Discrete and Continuous Distributions toget the fi~t success when each trial is independently a success with probability p.
Negative Binomial random variable represents the trial number to get to the r-th success
In this section, we review a variety of distribution functjons for random variables that when each trial is independently a success with probability p.
are widely used in quantitative modeli ng. Although it may not be necessary to memorize
t~e _pro~erties of t?esc distr.i ~utions, havi ng an intuitjve understanding of the
E[X] var(X)
dt~tn~utJOns ~nd havmg the ab!ltty to quickly derive important properties are valuable Name Probability mass function (pmf)
sktlls tn practice. As usual, let's begin wi th the theories: b+a (b - a+ l)J - I
J --
Uniform P(x) = , x =a,a+ l,···,b
Common function of random variables b-a +l 2 12

Ta~le 4. I summarizes how the basic properties of discrete and continuous random (n) ' ,_, x = 0, 1,- · ·,n np np(l - p)
vana bles are defined <)r calculated. These are the basics you shou ld commit 1o memory. Binomial P(x) = x p (l- p) · ,

Random variable (.A)


-- e- )J (A.tY
- - -
Continuous19 A.J_.)
Discrete 20 At
Poisson P(x)= X= 0, },.. ·
x! ' ._ -- -
CUJnulative distri bution function/cdf F(a) ~ P{X <a} F(a)::: f. f (x)dx ~ = (1- p)-"-1 p , x = 1,2, .. .
]
-
1- p
Probability tuass function /pmf
pmf: d
Geometric P(x) p IT
Probability j_ensity function /pdf

Expected value/ E[Xl


--
p(x) = P{X

I xp(x)
= x} pdf: f(x) = - F(x)
-
[. xf(x)dx
clx ! Negative
Binomial
P(x)= (x-1) , )'-'
r- 1
p (l-p • x= r ,r+ l, ...
r
-
p
r(l - p)
/ _j
~-Pi:t)>O
Table 4 .2 Probability mass function, expected value and variance of d1screte random
Expected value of g(X)/ E[g(X)]

Variance of XI vur(X)
~
I:
pi_x po
g(x)p(x)
r: g(x)f(x)dx
-
variables

Continuous random variables


E[(X £[X]/] E[X ; ]- (E [ X]) 2
· 1d f the commonly encountered continuous distributions.
Tabl e 4.3 me u es some o . . · ., . 1
Standard deviation of XI .\'lei( X) Uniform distribution describes a random variable unifonnly dtstnbutc~ ove~ th~ m~cTV~
Jvar(X )
Table 4 .1 Ba ·
SIC properties of discrete and continuous random variables
- . ·1 theorem normal distribution/Gaussian dtstnbutton IS
[a, bl . Because of t11e centra I I1011
· ·

'b
by far the most popular contmuous d1stn utJOn. ~ · E
·
ponential
. . .
dtstnbutJOn mn
d
- . . .- e
th
1s c
.
. I . f ·r . h . constant arrival rate A. Gamma dJstnbutJon With
Discrete random variables an:lVa time 0 an event 1 II . as~ .
r

- n
. 1)1 of the amount of time one
parameters (a, ;. ) often arises, m practice, as the d~s~ ul. 0 ~ d •
Table 4.2 includes some of th . has to wait until a total of n events occur. Beta dtstnbuttOns are used to mo e1 events
random variable reprcst:nts the most Widely-used discrete distributions. Discrete unifonn
values in the set J Cl • e occurrence of a va lue between number a and h when all
l · a+ 1 .. · b} have 1 I
r~prt!scnts the nu be f · ' equa probability. Binomial random variabc
m r o successes in a se . J.
"7"--- -- - - - - quence of n experiments wh<:n each trta 15
II)
"~ · define the parameter (expected value) since it is
For continuous random variables P(X - ·· Here we use the product of arrival rate ). and ~m1e I to
• - x) =O, Vx e (- -::.o~ 7JL SIP P{.Y s \'}= fl{ .X < x} · the definition used in many Poisson process stud1es.
86 87
Probability Theory
A Practical Guide To Quantitative Finance Interviews
. . a defined .mterval. B~a d.Justing
that me constrained w1th.in . the shape parameters a and p.
it can model different shapes of probability density functions. 21 60
55
i
Name Probability density function (pd.f) E[X] var(X) :

I
I (b- a) 2
L' niform --
h ' (I
a-5x $ b b+a
- - I
2 12
- ( .t-p)=
Normul
I 2a1 .,
-e • x e (-oo,oo) fJ (r
&a
Exponential ). - .lr
. .,_(! ' x?!O l/ 2 I / ,.(' I
J I

5:
Gamma
.J.e A.Y(AX )a-1

f(a)
X ?! 0. f(a) = r
e·Y ya-1 alA. a/ 2 2 0
...
5 X 55 60

Figure 4.4 Distributions of Banker A•s and Banker B's arrival times
Beta f(a + fi) u-1 (1- )P-I a ap
X X , 0< X< J
~
f(a)f(P) ~

a+jJ (a+P+l)(a+P)j
Table 4.3 Pro b ab11 y ens1
random variables .l.t d ·ty funct·1on, expected value and var·f ance of continuous Probability of triangle ·~
distribution on the stick),
. l (each cut point follows a ~m o~2
A stick is cut tWJce random Y ts can forrn a mangle?
what is the probability that the 3 segmen •th of the stick is I. Let's
Meeting probability
r , let's assume that the !eng
Solution: Without Joss of genera Jt) 'x and the second cut as .Y • ·
Two bankers each arrive at the station at some random time between 5:00am ••;d ~~ also label the point of the first cut as _ _ _ ----::7"r-----~l
am (arrival time for either banker is uniformly distributed). They stay exact Y 1 1
minutes and then leave. What is the probability they will meet on a given day? If x < y then the three segments are x, y-x and /
1-y. Th~ conditions to fonn a triangle are
,
.'io/111irm: Assume banker A arrives X minutes after 5:00 am and B arrives Y minutes ~~
5:00 am. X and Yare independent unifonn distribution between 0 and 60. Stnce , if
onl~ l" lc;; 5.exactly five minutes, as shown in Figure 4.4, A and B meet tf and on)1
I X - sta)
~...,.
x y-x
A 37'
y

1/2; '·
/
So the probability that A and B will meet is simply the area or the shadowed reg:"t:
di\'idc<.l by the area of the square {the rest of the region can be combined to a square " 1
SiLc lcngOl 55): 60x60- 2 x (l / 2x 55 x 55)= (60 + 55)x (60- 55) = 23 .
60x60 60 x60 144

.' :~"'P '· """ "'~'" ,;.k managem~n ·


!I Fo ex I ... _ ·1• ·b · · 1 lfyou
uuon "widely Used ;n modet;ng loss g;ven default ;,
"" lam' h:v Wllh Bay""" '"";stks, you wHt a!SQ «<ogn; 70 ;, as a popu tac co~jugate prior funcll 011
· -
n Jl;nt let the fi<SI CUI point be X, the second one bey, use the figure to
show th~ distribution of x andy.
89
Probability Theory
A Practical Guide To Quantit.ative Finance Interviews

The total shadowed area represents the region where 3 segments can form a triangle, This is another example that your intuition may misguide you. You may be wondering
which is 1/4 of the square. So the probability is 1/4. that if the last bus on average arrived lO minutes ago and the next bus on average will
arrive 10 minutes later, shouldn't the average arrival time be 20 minutes instead of 10?
The explanation to the apparent discrepancy is that when you arrive at a random time,
Property of Poisson process you are more likely to arrive in a long time interval between two bus arrivals than in a
Yo_u are waiting f~r a bus at a bus station. The buses arrive at the station according to a short one. For example, if one interval between two bus arrivals is 30 minutes and
P01sson process. With an average arrival time of I 0 minutes (A == 0. t1 min). If the buses another is 5 minutes, you are more likely to arrive at a time during that 30-minute
~ave ?een runnmg for a.lqngji_n)~ and you arrive at the bus station at a random time, interval rather than 5-minute interval. In fact, if you arrive at a random time, the
what IS your expected waiting time? On average, how many minutes ago did the last bus E[X 2 ]
leave? expected residual life (the time for the next bus to arrive) is for a general
2E[X]
Solulion: Consider~ng the importance of jump-diffusion processes in derivative pricing distribution. 25
and the r~le of Potsson. processes in studying jump processes, let's elaborate more on
~~~onentlal random .van~bles and the Poison process. Exponential distributjon is wide!~
sed to model the hme mterval between independent events that happen at a constant Moments of normal distribution
average rate (arrival rate) )·.. f(t)-- {le-J.t (I~ 0) · The expected arnva
· · · J/ j
1 ttme 1s ,,
If X follows standa~d nor'!la.~ distribution (X- N(O, I) f) wh.at. i.s E[X"] for n = I. 2. 3
0 (t < 0) and 4? 1
tr /
•.
_
: r - ' _.
\ i\
I I
- ·
l /v\ . ... ~ .= )
and the variance js 11A! u · · · . 1

. . . · smg mtegrahon, we can calculate the cdf of an exponenhal Solution: The first to fourth moments of the standard normal distribution are essentially
dtstnbutton to be F(l) == P( r <f)= 1- e_,
. - and P( r > 1) == e - rt , where r .ts the random the mean, the variance, the skewness and the kurtosis. So you probably have
vunable for arrival time 0 · . . . . .
memorylcssncss· P{ . · 1 n~ umque property of exponentLal dtstnbutton IS remembered that the answers are 0, 1, 0 (no skewness), and 3, respectively.
t' .. · r>_.~.+l i r>s}=P(r>t}. 23 That means if we have waited for s
tme umts. I 1le extra wanmg time has th! d' . . Standard normal distribution has pdf f(x) = --i=e ·.
2
. Using simple symmetry we
start at time 0. e same IStnbuttOn as the waiting time when we
...J2ff
When the arrivals of a series of ' . . 1-e-r ndx = 0 when n is odd. For n = 2, integration by parts are
have £[x"J =[ x"-
1

distribution with arrival rate ). h e\ents each m?ependently follow an exponenual


'• 1 e number of arnvals between time 0 and t can lx ..&
often used. 'fo solve £[X") for any integer n, an approach using moment generating
modeled as a Poisson process P(N(t)- ) - e_;., J..lx 24 ·d
-x - - - . x = O, I ... The expect~: functions may be a better choice. Moment generating functions are defined as
number of arrivals is itt and the varia11 . , . x! '
of exponential distribution th be ce 15 ~lso J..t. Because of the memory less n~ture _L e'x p(x), if x is discrete
• e num r of arnvals between time s and 1 is also a P01SS0° M(t) = E[e'x] =
proCI!SS P(l\'(t- .\') =x) = e--<tt-f) (A(/ - s ) r r
{ ( e'xf(x)dx, if xis continuous
x!
laking advantage ot the memo ·I Sequentially taking derivative of M(f), we get one frequently-used property of M(l):
the expected waiting time · 7J.. ess pro~rty of exponential distribution we know that
1
property stills applies s IS .. == IOmm l!_~u look back in time. the memooje.SS
. o on average the Ia t b - . - . - M '(t) = !!_ £[e''' ]= £[ Xe'x] => lvf '(0) = E[ X],
· s us arnved 10 minutes ago as well. dl
2
M "(I)=.!!_ E[Xe'x 1=E[X 2e'·\ ]=> M "(0) == E[X l.
dt
;: P{r>s+t lr>s} = e-~' ·•o;e-;.., :=ce-"'-·
Morl! rig11rously /\'(I). d fi - P(x > t}
· 1s e 10ed as · 1 23 · .., r·· o · ''tochastic Pr(lcess'' by Robert G. Gallager.
a ng lt-continuous function. fbe residual life is explained in Chapter J o · tscrete ~., ·
~0
91
Probability Theory
-- A Practical Guide To Quantitative Finance Interviews
{ I I 0 l I
and .\lr(O) =E[X" ], Vn 2:.1 in general. Conditional expectation and variance • ~J u 1 ' "
., _r v '-' _

We can use this property to solve E[X"] for X~ N(O, I). For standard normal For discrete distribution: E[g(X) IY = y] = _Ig(x)pxj) {xI y) = Lg(x)p(X ~\' I Y = y)
.t

distribution M (I)= E[e'x ] = [ e'.c ,!.-- e-·' 2


'2 dx::: /12 [-1-e-< ,_, / n d.,'(= e' 'z .
1

v2n ~ For continuous distribution: E[g(X) I Y = y] = [g(x)fYJr (x I y)dx

(};e-1' 1
~ isthe pdfof normal distribution X -N(t, 1)-so (f(x)dx= l ). Law of total expectation:
L E(X I Y =y]p(Y =y), for discrete Y
Taki ng derivatives, we have
E[X] =£[£(X I Y]) = Y
'( )
:\ ·/ I
,: I '
=te ~M'(0) = 0,M"(t)=e,. ·~ +t 1/n :::::>M"(0)=eo=l ,
' {[ E[X I Y = y]ft (y)dy, for continuous Y

.M 1 (1)= tc/ ' ! +2JLl


• ·~+ t-'e': ,2 -_ 3t''·2
e + t 3e'' r>- => M 3 (0) = 0,
and M4(t ) =3e'I "- +3re~"
1 •
· 2 +3t 2e•' .-2 +3t4e'l'2=> M4(0)=3eo =3.
Connecting noodles
You have 100 nood les in your soup bowl. Being blindfolded, you are told to take two
ends of some noodles (each end on any noodle has the same probability of being chosen)
in your bowl and connect tbem. You continue until there arc no free ends. The number
4.5 Expected Value, Variance & Covariance of loops formed by the noodles this way js stochastk Calculate the expected number of
~xpcctcd valu~:, variance and covariance . . . . circles.
nsks of any im·estments. Natu . are md!spensable Jn estimating returns and math induction / Recursive
The basic knowlcduc inclltde rtah11~.t11ey .ate a popular test subject in interviews as well. Solution: Again do not be frightened by the large number 100. If you have no clue how
:=- s e tO11owmg:
to start, let's begin with the simplest case where n = l . Surely you have only one choice
If £lx,
. l is fini te for all ; = 1· . .. ,n. then E[X, +· ··+X ]-E[X] E[X] The (to connect both ends of the noodle), so £[/(1)] =1. How about 2 noodles? Now you
re\attOnship holdS whether the , , . . I n - I + .. • + II •

. . x, s me tndependent of each other or not. .. (4 l 4x3


have 4 ends ( 2 x 2) and you can connect any two of them. 1here arc 2 / - - 2 = 6
lf .\ and r arlo! indcpendcn lh
. t. en E[g(X)h(Y)] = E[g(x)]E[h(Y)].
Covariance : tfn•(X }') _ 1:;[ X combinations. Among them , 2 combinations will connect both ends of the same noodle
. - ( -E[X])(Y-EIY])]=E[XY]-E[X]E[Y]. together and yield 1 circle and 1 noodle. The other 4 choices will yield a single noodle.
Corrclatiun: p( ..\'.Y) = Cov(X.Y) So the expected .number of circles is
~Var(X) Var(Y) £[f(2)] =2 / 6x (l + £[[(1)]) + 4/6 x £[/(I)]= 1/3 + £[/(I)J = 1/ 3 + I .
I f .rand y an: independent. Cov( X . Y) == 0 and
General rules of "ariaoce and cov<traance:
.
p(X .Y) == 0. 26
We now move on to 3 noodles with ( 6 ) ::: ~ . : 15 choices. Among them. 3 choices
,2 2
Cm·( f. f. will yield l circle and 2 noodles; the other 12 choices will yieJd 2 noodles only. so
La,.\',. L b ) ~ ) := L• ""' ab C (X
L..... ' . I ov y )
I I ' J
J•
I •
I £[[(3)] =3115 X (1 + E[f(2)]) + 12/15 X £[/(2))::: 1/5 + £[/(2)] = 115 +I / 3 + I .
M

J·llr( '\..., \' )


f....1 ~ , =
r •I

Var(X)
'
·ILL Cov(X
"" - X )
1
See the pattern? For any n noodles, we will have l:.lf(n)] == 1 +I 13 + 1 5 + · · · + l /(2n - l).
1.--f
"! I
('
I
\Vhich can be easily proved by inductiC?n. Plug 100 in, we will have the answer.

11li! ~\crsc b not tme •


· p( ,\ · Y) = 0 onlv means ,,\' and y ar -~'
J
e uncorrelated: they rnay well be depend~:~~
92 93
Prob<tbility Theory
A Practical Guide To Quantitarive Finance Interviews

Actually after the 2-noodle case, you probably have found the key to this question. If 112 chance to get Y e {4, 5, 6}, in which case you get expected face value 5 and extra
2 throw(s). The extra throw(s) essentially means you start the game again and have un
you start with n noodles, among ( n ) = n ( 2 n - I ) possible com bi nations. we halt
2 extra expected value E[X]. So we have E[X I Y e (4,5,6)] = 5 + E(X]. Apply the law of
total expectation, we have E[X] = E[E[X I Y]] =tx2+tx(5+ E(X]) ~ E[X]= 7 .
27
n -l
=-2n- probab'l' . d . ? n- 2
1 tty to ytel I Circle and n -1 noodles and - probability
n(2n- I) 1 2n -I .
1
to yield n -I noodles only, so E[f(n)J = E[f(n -I)] + - -. Working backward, you Card game
2n-l
can get the final solution as well. What is the expected number of cards that need to be turned over in a regular 52-card
deck in order to see the first ace?
Optimal hedge ratio Solution: There are 4 aces aod 48 other cards. Let's label them as card 1, 2, .. ·, 4a. Let
You just bought one share of stock A and want to hedge it by shorting stock B. How X == { 1, if card i is turned over before 4 aces
m~~Y shares of B sl~ould you short to minimize the variance of the hedged position?
' 0, otherwise
As~umc that the vanance of stock A' s retum is a~; the variance of B's return is a;:
th~tr ~orrdation coctlicient is p. The total number of cards that need to be turned over in order to see the first ace is
4R 48

Solution:

Suppose

that we short ,L shares of B, the vanance
· of the portfolio return ·ts
X =1+LX,, so we have E[XJ = I+ L E[ X,]. As shown in the followinB sequence,
I~ I~
2
var(J I -/uH) = a I - 2pha.~ a H + h- a2II
1
each card i is equally likely to be in one of the five regions separated by 4 aces:
Th~ best hedge mtio sho ld · · · var(rA-hrJj). Take the first order partial IA2A3A4A5
u mtntmtze
dcri,·ati,·c with respect to hand set it to ze . Dvar - 2 2 a 4 So the probability that card i appears before all 4 aces is 1/5, and we have £[X,] = 115 ·
ro. - - - pa a + 2ho = 0 .::::::. h -:: p- ·
8h tl H Jj (J/1 48

Tl) confirm it's the minimum w-. Therefore, E[X] = 1 + L E[X,] = 1+ 48/5 =10.6 .
~.. · ~can a 1so check the second-order partial derivative: t=l
c - var ,
_ _ ,,..... > 0 This is just a special case for random ordering of m ordinary cards and n special cards.
eh: - -u /J • So Indced \VI'et1 h
' a • the hedge portfolio has the minimum
= P~. "' m
ntriance.
O'H The expected position of the first special card is 1+ LEl XJ = I +-;;+~ ·
t=l

Dice game
Sum of ra ndom variables
Suppos~ that you roll a dice. for . h . . Assume that X X . . . and X are independent and identically-distributed (liD)
or 6. you can roll the dice g· . e~ rolL you are pa1d the face value. If a roll gives 4.'
cx(")\:cted payuf'f of this gam~? c~m. nee you get I. 2 or 3, the game stops. What is th~ random variable~ wi:~ u~iform di~·tribution between 0 and l. What is the probability
that S,, == X I + X 1 + ... +X < 1~ 8
II- •

Solution: This is an CX"t"ple t' h I


. •·
dtlkrcm dcpendinc on' "the" o l e aw oft · 1
~ ota expectation.· Clearlv your payoff wtll · be
. - 0 utcome of ftrst roll L t E['X · ff d
} be the outcotlH..' of your fi . t h · e 1 be your expected payo an
· w8 ld'

1 1
case the expected , )I . rs ro\\ · you have 1/2 chance to get )' e -'I 2 3' in which
1 expected f:
t ue ts tle .I t • • , •
ny
!8 ?u will also see that the problem can be solved uslf'l~ s
. HlOt: stan with the simplest case where n ... 1. 2. and .> · Try ro
i ualitv
d '
10
in Chapter 5
a genera
1formuia and prove it using
ace v.t ue 2. so £[X I y e {1,2.3} I == 2: you have mduction.

95
Probability Theory
A Practical Guide To Quantitative Finance Interviews

Solution: fhis problem is a rather difficult one. The general principle to start with the
simpkst cases and try to find a panern will again help you approach the problem; ewn 1- X
,.
I' So its volume should be (1 - x n+ l )"
n!
instead of~-
n!
Plugging in these results,
though it may not give you the (ina! answer. When n = I , P( S1 $ 1) is I. As shown in
Figure 4.6, when n = 2, the probability that X 1 +X 2 ~ I is just the area under wehave P( S ~ I)= r(l-Xn+lr dX =J._[ (l - .,.¥,.,)".. ']' =J..x - 1- =--
, ..,1 ..b n! , .. , n! n+i n! n +l (n+l)!
X I+ x2.$ 1 'v\'ithin the square with side length I (a triangle). So P(S"l ~ l) = 1/ 2. When 0

the probability becomes the tetrahedron A BCD under the piane X 1 +X2 +X 1 ~I
n = 3,
So the general result is true for n + 1 as well and we have P(S, $1) =J I n!.
within the cube with side length I. The vo lume of tetrahedron ABCD is 1/6. 29 So
fl (S , ~ I) = J / 6. Now we can gul!ss that the solution is 1/ n! . To prove it, let's again
resort to induction. Assume P(S, ~ 1) =1I n!. We need to prove that Coupon collection
I'(S,," .S I) == 1/(n+ I)! . There are N distinct types of coupons in cereal boxes and each type, independent of prior
selections, is equally likely to be in a box.
A. If a chil d wants to collect a complete set of coupons with at least one of each type,
how many coupons (boxes) on average are needed to make such a complete set?
B. If the child has collected n coupons, what is the expected number of distinct coupon
types-r 1
.'
'
'I'. Solution: For part A, let x,, i =1, 2, ... , N, be the number of additional coupons needed
X~_,
I
I
to obtain the i-th type after (i -1) distinct types have been collected. So the total number
• N
'•
of coupons needed is X =X,+ X 2 +··· +XN =LX, ·
0 I
' I

-tJ.
'...
.. ~.; ·-•··---· --
,;,
~)..# -
B .-·# ·······-.. For any i , i -1 distinct types of coupons have alread~ _been co_llected. It follo~s that a
0 0 new coupon will be of a different type with probab1ltty l - (J - 1) / N=(N - t+l) / ~.
n=2 Essentially to obtai n the i·th di stinct type, the random variable X, follows a geometric
n=3
Figure 4.6 Probabil ity that Sns 1 when n = 2 or n= 3 . distribution with p =(N - i + l) I N and E[X,] =N I( N- i + 1). For example. if i =1' we
simply have X; = E[X,] =1.
l-1-.!re we can use probabilit h d' · ·
Y Y con thonmg. Cond1 t1on on the value of X . v\'e have
..
N ( 1 I 1)
/
'( \; ~
· • ~ I ) = j/(X 1 )P(S < 1- X
,, 1
.
:. E( X]= L E[X,]=
N
I
N
.
N- +J
=N -+ N-l +· "+).
I \ N
~~ )dX" ..'' where /(X,,. 1) is the probabili ty denstl)
ial i=l
• • "' • -
functmn ol .\ ,. so r(.r ) ~ 1 -
• • 1 · But how do we calculate P(S < t- X ) ? The case)
ol 11 = , "'rld ., .. 1 , - ,., ·
- " ' - ·' 1avc provtded ·h .
we c ~nthll)· ncod t ., . k us WJt some clue. For S, .s 1-X +I instead of Sl, ~ I .
, '" o s mn. everv d. • . . , ,
• tmcnston of the n-d1mensional si mpJex·'0 from I 10 31 ·
Hmt : For part A let X be the number of extra coupons co ec
ll ted to get the i-th distinct coupon after
. ' ' h 1expected number of coupons to collect
t-1 types of distinct coupons have been collected. Then t e tota .
'I You Ca ll lkrivc I! b integrat1on:
. r ...
2: . . 1
E[X,] . For part B. wh1ch 1s n e ex
pected probability (P) that the Hh
1
' An n-Simpl · · ~ .
J, A( _ cl.· _

k
. 1 · ) • - l / 2:"dz '= I! 6 . where A(:) is the cross-sectional areJ.
c\ ll> t ll·dlm\!nSJonal analog of a triangle.
all distinct types is .E[X] =
tal

coupon type is not in the n coupons'?


96 97

Probability Theory
A Practical Guide To Quantitative Finance Interviews
For part B. let Y be the number of distinct types of coupons in the set of n coupons. We
P(A or B defaults)= E[I 11 ] + E[J 8 ] - E{l AI 11 )
introd uce indicator random variables I, , i =I, 2, · · ·, N , where
= E[lA] + E[JR] - ( E[J A]E(!nJ- cov(JA,J8 ) )
f I,= I, if at least on.e coupon of the i-th type is in the set of n coupons
I , =0, otherwise
=0.5 + 0.3 -(0.5x 0.3 - PA11a ,laB)
=0.65- JOij f2pAIJ
N
So we have Y == 11 + 12 + .. ·+ 1., = Ll, For the maximum probability, we have 0.65- J05i 12pAH =0.8 =>PAn= -J3i7 ·
•• I

For the minimum probability, we have 0.65- Jo.2J 12pAR = 0.5 => PAn = J3i7 ·
For each collected coupon, the probability that it is not the i~th coupon type is A~\~ 1.
In this problem, do not start with P(A or B defaults) = 0.65- Jo.2I 12p,us and try to .set
Since all n coupons are independent. the probability that none of then coupons is the i~th
N -1 \ " and we have £[1 ] = P(l = l) = 1_ ( N -l \ I" .
pAIJ =±1 to calculate the maximum and minimum probability since the correlahon
coupon type is P(l, = 0) = ( --=-)
N I I N ) cannot be ±t . The range of correlation is restricted to [ -.J3i7, .J3i7] ·

•1
,.
:. E[YJ :::; LE[I, l = N- N - -
N
(N -t)" .32

4.6 Order Statistics


. dtstn
Let X be a random variable with cumulattve · rtunc( JOn F.r (r)
. 'button · · We can derive
Joint default probability . .
the distribution function for the rmmmum yn = mrn
· (X 1' X 2' ... • X " ) and for the maximum
lf there is a 5?% probability that bond A will default next year and a 30% probability Z11 =max(X p
X 2' ... , / v\n ) of n liD random variables with cdf Fx(x)as
that bond .B wil l det:1ul~. What is the range of probability that at least one bond defaults
and what 1s the range oJ their correlation? P(~, ~ x) = (P(X ~ x )t => 1- Fr. (x) = (1- Fx(x))" ::::> fr. (x) = nf~. (x)(l - F:\. (x))" ~'

P(Z" ~ x) =(P(X :f, x))" => Fz. (x) =CF.r (x))" ::::> f z. (x) = nfx(x)(F,. (x))"-'
Solutio:: The nmge. ~f probability that at least one bond defaults is easy to find. To have
~e lar:.cst8 pro~ablllty. we can assume whenever A defaults B does not default;
~ h~;~·~; d~·.ta~hs. A does not default. So the maximum prob~bili ty that at 1east one Expected value of max and min
on . ~1 aults
)0% + 30% =: 80%. (The result only appl ies if P(A) + P(B) 51). For
IS

1
the ~-~,~~ .muml ' ·we can assum~ whenever A defaults, B also defaults. So the minimum Let X X ... X be liD random variables WJth . ·r
umJorm d ·1stribution between
• •
0• and I.
pro, ,aut ny t lat at least one bond defaults is 50~ r> 2> ' " • • h robability density functton and
o. What are the cumulative distributiOn functiOn. 1 e p th . ulativc distribution
To colculmc the con·espo ct· • expected value of Z, =ma-x(X" X 21 .... X , )?• What are e cum . X v · ... X)''
n mg corre1atton. let I, and I 11 be the indicator for the event
that bond AlB defaults ne ·t d · . the probability density
functton, · and expec' t cd value off" =mm( ,. ~\ ? · ' •· ·
. function
. '
l:.l/ ' I = Cl 5 £f I 1- 0 " x year an P 11 be their correlation. Then we have
varU.J=p.~ x(l - p_4 ) ==0.25,var(J )=0.21.
• · • •l - ·"·
8 ·l -d For uniform distribution on [O,Jj ·
Solution: This is a direct test of textbook know e ge. ·(
1
X . . . \' ) we
Fx(X)=x and fx(x)= l. Applying F.r(x) and fr(x)to Z, = max." 2• •• "

have
J A 511'lilar tJu~~tion: if ) ou randomlv put 18 b II . I'
hox~s . · a s rnto I 0 boxes, what is the expected nurnber of emp >

99
Probability Theory
- A Practical Guide To Quantitative Pinance Interviews

and E[ZJ= J.r/ f2. (x)dx= r


.bnx
"dx n [ II+
= n+l x
I]' = n+l
0
n
· I

Applying F.v<x) and f x (x) to r;, =min(XpX 2 ,-··,X,J we have


P( Y,, ~ x) =(P(X ~ x))" ~ F;~ (x) = 1- (1- Fx (x)t =1- (1- xY' (y,z) (z,z)
z
~ fr. (x) = nfx (x)(l - F.r (x))"- = n(l- x)"-
1 1

(y.y) (z,y)
1
y ------·----------
and EfY,,l = r nx(l - xY'- 1dx= r n(l-y)yn-1dt=[y"] -__!!__[y',... ''
1 1 1
] =-- .
1 1 o n+l 0 n+l ''

Correlation of max and min


Let X 1 and X 2 be llD random variables with unifonn djstribution between 0 and I, '
0 y z
Y=min(X.. X 2 ) and Z=max(X~:X1 ). What is the probability of Y~y given that
Z ~ z for any y, z e [0. l]? What is the correlation of Y and Z? Figure 4.7 Distribution of X, , X 2 , their maximum and minimum.

J I 2 _2
,\'olwion: This problem is another demonstration that a figure is worth a thousand words.
Using previous problem's conclusions, we have E[YJ= + =3, E[Z]=2+i-3.
/\s shown in Figure 4. 7, the probability that z ~ z is simply the square with side length 2 1
z. So P(Z~z) =/. Since Z=max(X.,X~) and Y=min(X.,X~ ), we must have 11-1 (l ) and r (7) = nzn- l =2z, we can
From the pdfs of Y and Z, fr. (x) == n(l-x ) =2 -x 17. w

Y~Z for any pair of X1 and X 1 . So if y>z, P(Y~y jZ$;z)=O. For y~z, that X, ~ r 2 2 1 E[Z2]- 3 dz=~ whichgiveusthe r2
alsoget E[I;,L]= .h2(!-y)idy=3- 4=6 and '-~~ -1 z 4' '
<llld xl satisfies r ~ )' and l ~ z is the square with vertices (y, y),(z,y), (z, z). and
2
(y. z), which has an mea (z- Yi. So P(Y ~ y n z ~ z) = (z - y) 2 . Hence l ( 1' 1 2 ( 2 ) .. _ _1 33
variances: var(Y) = E[Y 2
]- E[Y] = 6-
2
3
J =Is and var( Z) =4- ·3 - 18

P( y ~ y 1 z ~ z ) _ { ' ( =- J') if 0 5 z ~ 1 and 0 ~ y ~ z


1 2
Iz •
,ro calculate £(Y2L r
r- -.1'1 I -)dvdz To solve this equation, we
we can use £[YZ] = 11 Y.t.; d ,.t. - ·
0, mherwise
. 4 7 F 1 the figure we can see that when
need /(y, z). Let's again go back to Ftgure · · ron ..
Now let's move on to calculate the correlation of y and Z Osz~1andO~ y~z, F(y,z) istheshadowedareawtt pro · b babthtv
-
' 2 2- 2
F(y,z) == P(Y ~ y"' Z 5. z) = P(Z :f z)- P(Y ~ ynZ ~ z) =z- -(z- y) = q- y
corrt}', 7.):::: cov( }'.ll_ == E[tZ] - E[Y]EtZl
std( }') xstd(Z) JE[Y1]- E[Y f x ~ E[Z21 - £[2]2 :.f(y,z) = ,:Oz F(y,z) = 2 and E[Yl) = 1[2yzdydz =.(' z[y'J;dz =£z'dz = ~.
JJ • , wonder whether it is a coincidence for n =2.' h is
You may have no11ced that var(Y) var(Z) and •= ·h that is tru~ wi1hout rc~ortmg to
actually tru~ for all .mteger n. You may v.ant . 10 thmk
.
about " Y -
calculation. Hint: var(.t' = var(l x) for nny random vanable .\ ( , _ ~ )
1
~ 1- '/ '
100 'rvv 1-.
{
\1 )
~ 1 ,.:.
\
= -
I •l
·I f\2
101
Probability Theory
- A Practical Guide To Quantitative Finance Interviews

An allernative and simpler approach to calculate E[Yl] is again to take advantage of expected va Iue ('tOr .tt to tir.atl off is J·ust x. min. ff it goes in the• other
. direction, simply set x
sym metry. Notice that no matter x, s x2 or x, > X 2 , we always have yz =X1X2 10 1_ x. So the original problem is eqwvalent to the followmg. . .
( z '=' max( x" x2) and y =min(xwtJ ). ·
Wltat is the expected value of the maxtmUil!.Q. 500___
f_._ JID random .variables
. .with untform
distribution bet wecn-O.and 1?
:. £(Yl] = £! x x dx dr =E(X,]E[X~ ] =2x2 =4·
1 2 1 2
1 I I
. ~9 · \\,h.ch is the expected time for all ants to fall off the
Clearly the answer IS ~ mm, 1
50o-
1 cov(Y,Z)
Hence cov(Y,Z) = E[Yl]- E[Y]E[Z] =36 and corr(Y, Z) =../var(Y) x J var(Z) - 2. string.

Sanity check: That Y and Z have positive autocorrelation make sense since when Y
becomes large, Z tends to become large as well ( Z ~ Y ).

Random ants

500 ants are randomly put on a l·foot string (independent uniform distribution for each
ant between 0 and 1). Each ant randomly moves toward one end of the string (equal
probability to the left or right) at constant speed of l foot/minute until it fall s off at one
end of the string. Also assume that the size of the ant is infinitely small. When two ants
collide head-on, they both immediately change directions and keep on movjng at 1
foot/min. What is the expected time for all ants to fall off the string~ 4

Solution: This problem is often perceived to be a difficult one. The fo)Jowing


components contribute to the complexity of the problem: The ants are randomly located;
each ant can go either direction; an ant needs to change direction when it meets another
ant. To solve the probleru, let's tackle these components.
When two ants collide head-on, both immediately change directions. What does it mean.•l
The following diagram illustrates tJ1e key point:
13 1.
core co II"
JSJOn: __,;___H_.....;;.,_: Atier collision: ~~; switch label : ~
I li ' H ~

WIK·n an ant A collides with another ant B. both switch direction. But if we exchange the
ants' lu bd:-;, ifs like that the coll ision never happens. A continues to move to the right
and ~.~novcs to the left. Since the labels are randomly assigned any·way, collisions make
no dtflercnc~ to the r~sult. So we can assume that when two ants meet each just keeps.
on going in its original direction. What about the random direction that ~ach ant c~oo~~
On~e th~ collision is removed. we caiiuse S) mmctry to argue ffiat It makes no difteren~.
''luch dlr~:unn that an ant goes either. That meansi f ant is· p-ut at the x-th foot, the
an

~ th~ label of two ants that collide with each other• it's. like that the collision ne\'er
1
happ~ncJ.
hnt: If we swikh

102
103
Chapter 5 Stochastic Process and Stochastic Calculus
fn this chapter, we cover a few topics- Markov chain, random walk and martingale,
dynamic programming- that are often not included in introductory probability courses.
Unlike basic probability theory, these tools may not be considered to be standard
requirements for quantitative researchers/analysts. But a good understanding of these
topics can simplify your answers to many interview problems and give you an edge in
the interview process. Besides, once you learn the basics, you'll find many interview
problems turning into fun-to-solve math puzzles.

5. 1 Markov Chain
A Markov chain is a seq uence of random variables X 0 , X"···,X 11 , · · · with the Markov
property that given the present state, the future states and the past states are independent:
P{X,.,1 =j 1 X n = i ' X 11 - l =j 11-P
. ..
>
X0 =i0 } =p IJ = p!lX 1 =j 1 X n = i}
tH·
for all n, i0 , · • ••

i,, .p i , and j , where i, j e {1, 2, .. . , M} represent the state space S = {s,. S 1 , ... , \"tt} of
X.
In other words, once the current state is known, past hi story has no bearing on the future.
For a homogenous Markov chain the transition probability from state i to state j docs
not depend on n. 1 A Markov cha,in with M states can be completely described by an
M x M transition matrix P and the initial probabilities P( X o) •

p" P 12 Pt \t

P 22 P 1\f
. where p,, the transition
Transition matrlx: p ::: { P,,} = PJI IS

P111 Plo PM\f

probability from state i to state j.


•. (

Initial probabilities: P(X


0
) =(P(X0 =l), P(X0 =2), ... , P(Xo = \rl)) · L
,. 1
P(X,, ~ i) = ·
1
1

The proba bility of a path: P(X, = i"X2 = i"! .. ·, X" = i., I Xo;;: in)= P, • P..... .. · p, '

Tra nsition graph: A transition graph is often used to express. the tra~sition m~.~ri~
graphically· The transition graph is more intuitive than the matnx. and 11 ~mphasJzes

1 In th" h · (" e transition probabilitic!' do


we only consider finite-state homogenous Markov c ams 1• ·•
IS chapter, •
001
change over time).
--------------------------------------------
Stochastic Process and Stochastic Ca lculus A Practical Guide To Quantitative Finance Interviews

possi.b.le and impossible transitions. Figure 5 I h


transitiOn matrix of a Markov chain with four st~tes~ ows the trans ition graph and the
derived using the law of total probability by conditioning the absorption probabilities on
the next state.
Equations for the expected time to absorption: The expected times to absorption,
J.l" · .. , f..it.~' are unique solutions to the equations J..i, =0 for all absorbing state(s) i and
i = 2 3 4 ......
0
u J.l, =I + LPJ.1
m

9 1
fo r all transient states i. These equations can be easily deri ved using the
0.5 0 0.5 I
0.5
J05 < >
P=
0.5
0
0
0.4
0 .25
0.4
0 .25
0.2
2
3
j =l
law of total expectation by conditioning the expected times to absorption on the next
state. The number l is added since it takes one step to reach the next state.
0.25
0.4
0 0 0 4
0.4
GamblerJs ruin problem
Figure 5.1 Transition graph and transition
.. matrix of the Play Player M has $1 and player N has $2. Each game gives the wi.nner $1 from the other. As
~better player, M wins 2/3 of the games. They play until one of them is bankrupt. What
IS the probability that M wins?
Classification of states
Sta teJ· IS
· accessible from state i if th . . Solution: The most difficult part of Markov chain problems often lies in bow to choose
j { 3n such that p > 0). Let T _er~ IS a dtrected path in the transition graph from i to the right state space and define the transition probabilities P,1 's, Vi, j. This problem has
, -mm(n·X - ·1 x .
<~nly Jl state .i is accessible f Y . . " - J o = 1), then P(~ < oo) > 0 ) if and
., v
fairly straightforward states. You can define the state space as the combination of the
Irom j . and .J· is acccssrble
. ron1 state
from In f' · States i and J· commumcate
1 . if i is accessible money that player M has ($m) and the money that player N bas ($n):
a~.:ccsstble form state I. but they
state 4 ·
1
do tlgurc 5. 1·. state 3 and I communicate. State 4 is
no communrcate Since · . not accessible from
{(m,n) }={(3,0),(2,1),(1, 2),(0, 3)}. (Neither m nor n can be negative since the whole
state I JS game stops when one of them goes bankrupt.) Since the sum of the dollars of both
w~ sav: that sate
t
players is always $3, we can actually simpl ify the state space using only m:
r..rs recurrent . f f,
acccsstble fromj ( Vj, P(T, < 'l.>) ~ ; ;~;ry stat~j that is ac~essible from i, i is also {m} == {0, 1, 2,3}.
0
" < ) - 1). A state IS called transient if it is
00
not rccurn.·nt ( ] j P( . 1 ) The transition graph and the corresponding transition matrix are shown in figure 5.2.
' 1" < 00 > 0 and P(T1
r~~urrr.:nt. Statl!s I "> ··rld "
· ' - " -' ar~ a11 tra ·
' < o:>) < 1 ). In Figure 5 I only stat~ 4 is
· · ' "' Pon P~ ' Po 2 Po. 0 01
not acccsstole from4. nslent smce 4 is accessible from l/2/3, but t/2/3 are
I rG;I
/3 C@2
/3 &J
l p,~ Pu
Yc 0

~ ~J
p 1, p11
P = {P }=
l 2 3 IJ P~.l) p~ , P~'! P:•
Absorbing Markov "··ha1ns , .. A st·n · ·
state ( p _ 1 p _ () '..I. 1 IS called absorb· 0 · • • • . ~ ~
1/3 213 P~•J
. Po.• P:.: fl 2..•
' '' - ' v.f ~ i ). A Markov d · .
· · • • l'
" m:::- tl It rs tmpossibte to leave this
State an l I 1.f r·· m t'\ crv stat , · · , • . lam IS absorb.mg 1. f .It has at least one absorbin(l
\: J1 IS po~stble to go to a b
. 10 Figure 5.2 Transition matrix and transition graph for Gambler's ruin problem
4 IS an ahsorhin' . . . e
· g ~tate. The corr~spondinn M· ·k 0 a. s~rbwg state. In Figurr.: 5. 1, state
F...quatiOJ Js· t-1 or ahsorprion rob· . . e . <It ov ~ham 1s• an a ·bSorbtng · Markov chain. The initial state is X = 1 (M has $1 at the beginning). At state 1, the next state is 0 (M
0
state ,. u .
· · ~· ._,,,,_ are unique :thdttv: tfhe pr0 b• a bT
P solutiOJ;s 1
tty to reach a speci fic absorbing loses a game) with probability 1/ 3 and 2 (M wins a game) with probability 2/'J. So
0 equation s a - 1 . 1\0 =I I 3 and Pl ,2 = 213. Similarly we can get Pz.l == 113 and Pv =2 / 3. Both state 3
state(s) 1 ~ .... und u -,f. a
,
· • - · a, =0 for all absorbtng
L..I ' P.J for all transient s·tate~. t. -fhe"e (M wins the whole game) and state 0 (M loses the whole game) arc absorbing states.
· .
" equatwns can be eas1'I ~
To calculate the probability that M reaches absorbing state 3, we can apply absorption
Probability equations:
107
Stocha~til: Proccs-; and Studmstil: Calculus
A Practical Guide To Quantitative Finance Interviews
3 3
aJ =l, u\. - 0 , and a, = ~ ' p, a , al ="" p a
.) I ~ 1 ,1 1
E~ {7.l 2}, the game essentially starts over again. Now we have all the neccssari ly
J~O J=O information for P(A). Plugging it into the original equation, we have
Plugging in the transition probabilities using either the transition graph or transition P(A) = P(A IF= i2)P(F =12)+ P(A l F =7)P(F =7)+ P(A I F~ {7, 12})P(F ~ {7,12})
matrix. wehnve a, = 1!3x0+2 / 3xa2} => { a, = 417 = 1 X 1/ 36 + 6/36 X (1/36 + 29 136P(A)) + 29 136P(A)
"2 =113xa1 +2/3xl 02 =617
Solving the equation, we get P(A) = 7 113.
So, starting from $1, player M has 4/7 probability of winning.
This approach, although logically solid, is not jntuitively appealing. Now let's ll)' a
Markov chain approach . Again the key part is to choose the right state space and defim:
Dice question the transition probabilities. It is apparent that we have two absorbing states. 12 (A wins)
and 7-7 (B wins), at least two transient states, S (starting state) and 7 (one 7 occurs, yet
Two pla)'LTS bet on roll(s) of the total of ·
sum of 12 wi ll occur first PI B b two standard stx~face dice. Player A bets that a no 12 or 7-7 occurred). Do we need any other states? Theoretically, you can have other
playl'rs h·L'p rolling the d·. ayder ets that two consecutive 7s will occur first. The states. In fact, you can use all combination of the outcomes of one roll and two
tee an record the sums u f 1 1 . . consecutive rolls as states to construct a transition matrix and you will get the same final
probabilit y that A wi ll win? n I one Payer wms. What IS the
result. Neverthe less, we want to consolidate as many equivalent states as possible. As
Solutiun: Many of the simple 1M k . we just discussed in the conditional probability approach, if no 12 has occurred and the
conditional probability argumen! Ita~s ~:t cham ~roblems_ can be solved using pure 0
most recent roll did not yield 7, we essentially go back to the initial starting stateS. So
ddin~d as condit ~onal probability.: surpnsmg constdering that Markov chain is all we need are states S, 7, 7·7 and 12. The transition graph and probability to reach state
P:xn I - 1· I X - i X 12 are sho\\'0 in Figure 5.3.
I,· 1, · · ·, ./\v 0 = i0 } =. pIJ = P{X _ . .
11 - • ,. -
I X, = I}.
So let's first solve lhe problem usino con . .
pwhability that ·1 win. C d. . . 0
..
11• 1 - )

dihonal probability arguments. Let P(A) be the 7


6136 ®)I Probability to absorption statt 12

on tltontng P(A) fi a," =I. a7_ 7 = 0


on t 11e lrst throw's sum F, which has three
' !).
po..;sibk· outcomes F = F_ as== I / 36 x 1+ 6/36 xa1 + 29/36 x a_, :::>a~ -= 7113
12 ' - 7 and Fe {7,12}, we have
a1 := l/36 x 1+ 6/36 x 0 + 29/36 x a..
P(. 1) = P(.l l F == l 2)P(F = 12) + P( 'l IF - 7
Then WI.! tackle each com ' ~ )P(F = 7) + P(A I F e (7, 12} )P(F li: {7, 12} )
.. . ponent on the nght hand .d U . . . Figure 5.3 Transition graph and probability to absorption for dice rolls
(,Ill eastly see that P( F =
12) = 1136 _ Sl e. smg Slmple pem1Utat10n, "'e
is obvious that P( ,1 .~ _ I~)
• 1 -
1 · P(F - 7) = 6136, P(F ~ {7, 12}) = 29/36. Also il
L = 1 and P(A 1 F
Here the transition probability is again derived from conditional probability arguments.
starts 0\'1..'1' again.) To calculat, f( I c- li: {7, 12}) =P(A). (The game l:Ssentially
c t: A r = 7) W d f
thrnw·s totn l. ~hich a"ain has thr •e . · e nee to urther cond iti on on the second Yet the transition graph makes the process crystal clear.
.: possthle outcomes: E === 12 £ - 7
p, •I F . 7) p o
· - . an d E ~ {7, I '))
_,.
,. - ~ (A I F = 7,E =12) P £- ·
P( AIF - 7 E ( - 12 1f =7) + P(A I F = 7' E = 7) P(E = 71F 7) = Coin triplets
_ ) . - . ~{7.12})J>(£~{7, 1 2} ; F=7) Pan A lf . . . h · th xpected number of tosses such
· you keep on tossmg a fau com. w at ts e e . of
- I ( ..J II· = 7,E-=1 2)x l /3 6+P( ;l l f '-7 E 7 that you can have HHH (heads heads heads) in a row? What IS the expected number
, . - ' · = )x6 / 36
+ P(.-I rf = 7.£ e(7.12} )x29 / 36 tosses to have THH (tails heads heads) in a row?
- 1X l / 36 + 0 X 6 / 36 P( ..
+ :1)x 291-> 6 = i i36 +29136P(A) Soh11 · • • to choose the right state
0

lien: the · ·cond . . relies on th , · d /On: The most difticult part of Markov cham IS, agatn, d [!
. cquat1on space. For the HHH sequence, the state space is straightforward. We only neeb f?u~
rolls. II J. =7 and £ - 12 A . \,; 1.n ependence between the second and tl1c lirst states· S' (f' · · d ,,,henevcr a T turns up e ore
- · wms: tf F = 7 . '
and E = 7, A loses: if F = 7 and H! · or the starting state when no com 1~ tossc or
fH), II, HH, and HHH. The transition graph IS
108
109
Srochaslic Procc~s and Stochastic Calculus
A Practical Guide To Quantitative Finance Interviews

Solution: Let's try a standard Markov chain approach. Again the focus is on choosing
the right state space. In this case, we begin with starting state S. We only need ordered
subsequences of either HHH or THH. After one coin is flipped, we have either state Tor
H. After two flips, we have states TH and HH. We do not need IT (which is equivalent
to T for this problem) or HT (which is also equivalent to T as well). For three coin
sequences, we only need THH and HHH states, which are both absorbing states. Using
~~~~~a~~ ~-i, ~~;~~~at~o~:~~~~:he state wi II st~y at S when the. t~ss gives a T. Jf the toss these states, we can build the following transition graph:
the n~:xt toss is T othe . . H. At state H, Jt has 1/2 probabJ lJty goes back to stateS if 1/2
· • rwlse, 1t goes to state HH At state HH ·t 1 h 112 b b'J'
go~.:s bad to state s if tl , . . T .· . , ~ a so as pro a 1 uy
1l; nex 1 toss IS ; otherwtse, It reaches the absorbi ng state HHH. ~n 1/2 ~(J~AA A Ql
So w~ have the follmving transition probabilities: P.. ,. = _1, P. _ 1 o _ 1 l~@ (f) @ @ @ @)
f~, ., - ~· '-.Ja/~
1 1
p -- I n I d ''•·' - .\'.If - 2' • H.S - l'
• ''r( • · .1'"' · ' -· '·
'
r 111., · w 111 -"' ,- , an pHI/If IIIII/ -1
- • 1/2
w~ ar~.: interest~d in the expected numbe 0 f . . .
tim~: to absorption stan· g fi · r tosses to get HH~ wh1ch ts the expected Figure 5.4 Transition graph of coin tosses to reach HHH or THH
expcctt'd ti,;J~ to ·tbsorp' ,. U1 rohm state S. Applying the standard equations for the
' ton, we ave
We want to get the probability to reach absorbing state HHH from the starting state S.
J.l,, - l 'l" +j(. + t iJ ) = !4
.• - I' II I Jls Applying the equations for abso rption probability, we have
p,, r +J. u . . , _"
2 l!tl JIH = 12
. - 1" ,\

1 +
l + J.l, + f.J,,, I=:>
aHim =I, a'I'HH = 0 ar =O,arH = 0
)J!IU - I
JIHH =8 a~ :::.la +.la
· 2 1' 2 H as =s
I

.u1/1/(1 = 0 )
" ill/If =0 Q
T
::;;;la
2 I'
+I I I
"'i'aJ'H , aH = l ( IT +TaHH aH
I
== :r
So from the startincr state rhe _,
,. . expected number of tosses to get HHH is 14.
o ' a," 1 == 12 aI' + 2'1 a1'HH > aHH -- 12 a I' + 21 aHHH aIll! -2
Snllllarly for exp~cted time to . h T
gruph ~nd ~stimat~ the correspo ~~ac . HH, w~ can construct the following transition So the probability that we end up with the HHH pattern is 1/8.
n mg expected lime to absorption:
This problem actually has a special feature that renders the calculation unnecessary You
may have noticed that a, = 0. Once a tail occurs, we will al_:va.r_s get T!IH before ~!Hjof·
p.·' = I + .Lp
!
+L
.~ 2 fiT
l Ir fl' ·-- 8 1'he reason is that the last two ~ coins in THH IS · 1· h · tl e hrst two coms m
HH, w uc 15 1 .'.
1 sequence HHH. In fact the onlv way that the sequence reaches state llll/-1 before /HI~
p,' =l+.Lu
J. ru
j.ll'H/1
2 rr
/.. =J+.l.
=0
2 f.l,
, r ·11.,
+.111
-

+I
I
JlnrH
=>
lI
11
rJ

J.l"'
II
I' /HI/
- 4
-

=2
=0
·18
b t'
' ~
· ... H fi
e ore the first HH sequence and always end m TH Irst.
s
·
that we get three consecutive Hs in the beginning. Otherwise. we
0 1·r
alwl)'S bnve a 1
' · '
w · don't start the com
~ THH
.

Hipping sequence with HHH which has a probability of 1/8, we will always have
So !l·on, the startin!l stall'S. the ~x C' , . , before HHH. '
, p ctcd num.her of tosses to t~"Ct TuH . 8.
u . IS

Pan 8 Ke~.:p n· · .. p . d of tixed triplets for the


. ~ 11 • · . . tppmg n f<ur C\)in until eitht:r HHf! an C. (Ditlicult) Let's add more fun to the tnplet game. 1nste~ ·h . a
I:) lt: probability that you uct an IIHI/ . b. or THH occurs in the sequence. What two 1 . th · 0 wn tnplets. Player 1 c oases
. P ayers, the new game allows both to choose ei~ . t The players again
~:-~......__---._ __ __ _ su St:quencc before THH?~ nplet first and aMounccs it· then player 2 chooses a different tnp1e l.
0
1
·h chos ·~n
: Hint: Thi~ nrnbl . 1f ;, tos3 th . • ~ s The p ayer w ose c
~:m w..:~ n111 require til d . e coms until one of the two triplet sequences appear ·
bCI\Wettnn· 1/H/f

.
·
l' rawml! of a Marko ~h · ·
P•11h:m and a T! Ill pattem 1-1 . ~. . • v c arn. Just think about the relationship tnplet appears first wins the game.
. 0\\ Ccln we get 'in HliH
' sequence before a THH sequence?
f lO
111
Stochastic Process an<.l Stochastic Calculus
A Practical Guide To Quantitative Finance Interviews
If both. ~layer I and player 2 are perfec I
probnbtltty of winning, would you go fi t y rational and both want to maximize their Color balls
probability of winning'fl trst (as player 1)? If you go second, what is yow
A box contains n balls of n different colors. Each time, you randomly select a pair of
balls, repaint the first to match the seco nd, and put the pair back into the box. What is
,\'olulioll.· A common misconception is th
'.llhcr sequences. !'his misconception is oftat there is always a best sequence that beats the expected number of steps Wltil all balls in the box are of the same color? (Very
Sl'qucnces arc transitive: if sequence A en founded on a wrong assumption that these difficult)
s~qucnce Band sequence 8 has a hi I has ~.higher probability occurring before
;l·qu~~t:~ "' has a higher probabili~ le~/rob.ablltty occurring before sequence C. then Solution: Let N be the number of steps needed to make all balls the same color, and let
11

rans.tttvtty does not exist for this game. c~rnng before sequence C. In reality. such F;, i =1, 2, .. ·, n, be the event that all balls have color i in the end. Applying the law of
?.JuyLT 2 ~:an always ~.:boose another sequ o ~atter what sequence player 1 ch.ooses, total expectation, we have
l~e key, as v.·c have indiCitkc.i in Part Bc~ce wtth more than 1/2 probability ofwinning.
~-
a. c; lh..:~fi~l
·~ t'-"O
· coms
• of
- -laverj~
- Js 'to choose
' _ · o·r the s~encc
-·.. Iast t wo coms
- the E[N,] = E[Nn IF; ]P[F;] + E[N" I F1 ]P[F2 ) + ·· · + E[ Nn I F,)P[ F,,].
t.:uch pair of st.:yUcnces: • que.A!.~e. We can compjje the following table for
Since all the colors are symmetric (i.e., they should have equivalent properties), we have
P[~] = P[F;] =.. . = P[F,,] =1I n and E[Nn] =E[Nn IF;]== E[ N, I F;]= E[N,. j/·;,J. That
2's winning
Plaver 1 means we can assume that all the balls have color 1 in the end and use E[N" I F;J to
--HHH
ProbabiJit)
HHH h"'HH HTH IHHT
. rrTH tfHT
1/8
HIT TTT represent E[N,.].

J'HH
-
1t8) II
2/5 112 l1/JO 5/12 2/5 L/2 So how do we calculate E[N" 1 F;) ? Not surprisingly, use a Markov chain. Since we

HTH
- 1/2 1314 1/3 t/2 l/2 315 only consider event F; , color 1 is different from other colors and colors 2. · · · • n
N

,..I,.
HHT
"'
·-.....:.: l/2
~ -~ It
113 3/8 1/2 112 7/l2
become equivalent. In other words, any pairs of balls that have no color I ball in~olved
~re equivalent and any pairs with 8 color 1 ball and a ball of another color are eqUivalent
I-- [IH 112
~
1/4
.! ;>"'"' 1_.., 1/2 5/8 ( 2~ , 7110 rf the order is the same as well. So we only need to use the number of balls that have
7/10 f 2~ ·- 5/8 l/2 color I as the states. Figure 5.5 shows the transition graph.
!213) ./ 1/4 1/2
~ 7/ 12 112 1/2 3/8 1/3 I 112 315
HTT 315
F 1/2 1/2 1/3 l/4 1/2
,, 718
- rlT 1/2 Ius 5/ 12 3/W
1/2 ~15 1/8 It
Table 5.1 Player 2's winnin ' .
.., . g Probab,hty Wtth drffi .
As sho,,·n rn Table ). I ( erent corn sequence pairs Figure 5.5 Transition graph for all n balls to become color 1
· · you can , t~
c hOtces 3r~ 111av , ? ' con lrln the result
bt:SI s, · • \:r- can always choos, a
· \:ljll~nces
· s yourself), no matter what player l's Staten is the only absorbing state. Not.!_ce that then~ is.;!.~state 0_. otherwise it ~ill n~v~~
bold . • th·.t t P1nyer 2 can choo<-" ·" ·sequence
.- t0 1
lave better odds of winning. The reach F, · In fact, all the tra.rv•ition probability is com.litJOJlCd on Ft_Es well, whtch mnk\;s
1
· n Oil1<.:r to m· .· · "" 10 •esponse t 0 1, . ·
JriT Till . , <~XIIllll.c his odds of \\'i . s cho1ces are highlighted m
· 1 .md 1 HT. Ev~n in these cases nl·rung. player l should choose among HTH. the tr~~itton probability p
' 1.1 •1
I F.I
higher than the unconditional probability P,... l and
.
. P ayer -? has 2/3 pro ba b'llity
. of winning. • j F.-0 and p = l i n. (Wtthout
P• 1-1 IF1 Iower than P,., . I·or cxamp1e. P1.o 1 - 1.0 ..
1
conditioning each ball is lt'kcl)' to be the second ball, so color I has ll n probabtllty of
be. ' · ·· bbT · 1h· roblcm
l'hls " 'a u.•.l ,.fitcul!
problem ... ~ng , t~e second ball.) Using the conditional transJtton pro .a 1 .'t}. c P
.I - I
·Ulu ~'\-pi:1.·t~J
o\

N ,
W .. v ile. ntcre!>tCd rer.d
llltln.l( rinl~-P d .· . a er may find lh f II . , . . . essenttally becomes expected time to absorption with system equattons.
• n. - (Ma~. Jl)•J7). fl ~~ ..ara ox1~al Situations'' b , V C e 0 owmg paper hetptul: "Waitmg Tunc
p. 1 1.>3. In lhts section. we wi~l · . ·d~ombas. The Americ:an Suui.flidan. Vol. 5 I.
0 1
E{N, i F;]= l+ E[N,_,I f;]xP,.,_1 1r;+ E!N, I r ;Jx P..• IF;+ ElN,~~I r;J xP...•I I ~ ·
112 n Y IScttss the intuition.

113
Stochastic Proccs~ and Stol:hastic Calculus A Practical Guide To Quantitative finance Interviews
To calculate p'·'-' 1 F." 1et , s rewnte .
the probability
't/k =0, I, ... , to make the derivati on step clearer: as P(x~< +t =; - 11xk == i. F;),
Using these recursive system equations and the boundary condition z" =0, we can get
7.1 =(n -1)2 • 4
P(x.. , - ~i- l l x~ =i. l ·; )= P(x, =i, x"~ ' =i-l, F;)
P(x~ =i, F;)
5.2 Martingale and Random walk
::: P( F; l x~ +l =i - l, xk =i)xP(x.~-~, i-11 x* i) x P(x* ,·)
P(F; I x* - i) x P(x =i ) Random walk: The process {S, ; n ~ l} is called a random walk if {X,;i ~I} are liD

::
P(f,' !x,""1 =1' -J)x P(xk~ l -
.
I
II X11 ~< i)
{identical and independently di stributed) random variables and S, =X, + ··· X,, where
P(F; I x~< =i) The term comes from the fact that we can think of S as the position at time
n = l, 2, · · ·
"
~~ !x j(l~ i)_ n for a walker who makes successive random steps XP XP · ..
= n n(n -1) - ( n - i) x (i -I) If X, takes values 1 and -l with probabilities p and 1 - p respectively) S" is called a
. ~ . . iI n - n( n - I) simple random walk with parameter p. Furthennore, if p =t, the process S 1s a
.r hl: fir~t \.'quatlon
1s the I' ·
is simply the d fi . .
e Jmlton of condit'1 symmetric random walk. For symmetric random walk, it's ea'iy to show that
. app IC<Hion of Bayes' theorem· th th' d ~na1probability; the second equation
E[S~, ] =O and var(S,) = £ [S :J-E[S, )2 =E[S:]=n.
5
denve
-.... P( F• •x~ =I') =I.I ,~, we again •need
e to
lr uequation
' a pp rJes the Marko v property. JQ_ 1

th~.· balls ha\'l! different colo -t -·· Se_$.)mmetry. We have shown that if all ~ymmetric random walk is the process that is most otten tested in quantitative
h rs, t len we b·tve P[ F]
~ ~ prohabilityofendingina giv~n ' - - ' =P[0L= · .. =P[F1= l l n. What is mterviews. The interview questions on random walk often revolve around tinding the
1s. •simpl Y ·; • .o sc~ that ,.,..e l: cob1or. 1abeled as c' ·r 1 1· 0 f h --
t e balls are of color c? Jt first n for which S, reaches a defined threshold a, or the probability that Sn reaches
1 11 1
c i- I . . 1
can a el the color 0 f h
, . • - • · • • • 1 (even thoul!h they are · r: eac of the i balls of color c as a for any given value of n .
baIIs wJII . end v. ith col -. . . tn .act the same
co Ior) · N ow .rCs obvious that all
0 1 cJ wuh probabilit ' 11 Martingale: a martingale { z,; 17 ~ 1 } is a stochastic process with the properties that
probabilities of c 's wJ · h . ) n. The probability for c is the sum of E[ Znl]<ooforallnand £[2n•J 12 =ztJ) z11-J =Ztl - 1' ... .. z,= z,]=z . Thc propcrtyofa
' , . lrc gt\'es the result I·; 11. 11 II

Similarly we have P(F. I . martingale can be exte nded to E[Z.,;m> n iZ, =z",Zu-1= z"_" ... ,£, = z,] = :,, which
hasiccount' 1
x." ~ l ·-) ) = (i -1)/ n. For P( · 6
rng method. There arc n(n -l) . xk ., ='-I I x" = i), we usc a means the cond itional expected value of future Z 111 1s the current value Z".
11 halls In ord
. . ·· er ~~or one color 1 b· II poss1ble pe·rmL1t at'IOns to choose 2 balls out of
Asymmetric random walk is a martingale. From the definition of the symmetric random
\\ h1ch has· i chotces;
· to change
the first ball dneeds b. c0 1or, t he second ball must be color 1,
={S" + I with probability 1/2 . so E[S""',! S, = s~, , .. , , .)'l = .~·, } = s,,.
10 e another col h'
'
Su /'(x ":: . i . 11 . .) i(n - i) or, w tch has (n- i) choices. walk we have S
. .\, _, =--- "+ 1 SII -1 with probability 112
n(n-1) · 2 2

Apply ing the :xtl111.! . ••


Since £( •)211 +1 -
(1 + 1)]
1
I [( C'
= 2 .._1 + 1)2
11
+ ( s· 1)1]
l
( n
II -
+ l) - S
-
- n S - 11 is a martingale
•I - ' II t

pnn~oap 1L'S. we cnn get


as well.
Pt t:. 1 =i l x -:: i /•' ) _ ~n - i) x 2i
' . I - f' (.th, = i + l p·t = i.F; )= (n - i ) >< (i+l )
n(n-1 ) •
'. Even this step is not straiuhtforward. You need to plug in the ,·~
and try a few cas~
starting with
Plugging int(l /!l .\ I F.J , d . .. n(n - 1) ' =: n - I Th o I lta'lning Z l ... l cancel out.
' ' an srmplt tying E[A I F. ~ . , , · e panem will emerge and you can see that all tle tenns cot · .. • · ·
lnd ·t· d · 1 · If I' r( 'I ) - 11 then we
(II - i) ·... ]. )( / _ ' , j as £,, we have uc 100 again can be used for its proo[ !'ar(S,) = I ar(Z,I"' I. In ucuon s ep. a •• - •
• II( 11 - I ) + ( n ~ i)(i + I .
1
have r · · d pendent of ~
1·510
}L,.., + (n- i)(i - I)Zt-1 . , ur(S•• l= l'or(S +.T ) = l or(S ) ..- l ctr(.'t )=n + l smcc .t.,. e • ~·
Do not l'. • ... • ··• A rt 10 ' gale does not need to be a Markov
conrllse a martingale process with a Markov process. ma
PrOcess; a Markov process docs not need to be a martingale process, either.
I 14
11 5
Stochastic Process and Stochastic Calculus A . I Gu"de
Pract1ca I To Quantitative Finance Interviews

Stopping rule: For an experiment with a set of liD random variables XP X , .. ·, a .. 7th meter) to 0; then the problem becomes a
2 Let's set the curren t pOSitiOn (the I . 83 17 We also know that both S,. and
stopping rule for {X,; i ~I} is a positive integer-value random variable N (stopping time) lk 1h t tops at etther or - ·
symmetric random wa a s · g time is a martingale,
such I hat for each n > I . the event {N 5 n} is independent of X, ..1 , X,. , • · ·• Basically it . artin ale stopped at a stoppm
2
says that whether to stop at n depends only on X,X 2 ,-· ·, X, (i.e., no look ahead).
s; - n are mal1ingales. Stnce a m
h s
g
v +X + .. .+ X . Wlt
. h N being the stopping time) are
s. and S - N (w ere .v = A 1 ~
2
" • _ 83 p be the
the robability that It stops at a - ' P
Wald's Equality: Let N be a stopping rule for liD random _var~~les X ~k ··· and let ~_
.\ N

-- .. ·-
s. =: X1 + X~+· ·· +-X 1• • then EfSvl = E[ X]E[N]. -- martingales as well. Let Pa be
probability it stops at - f3 = - 17 ( Pf1 - 1 p a),
and N be the stopping time. Then we

Since it is an important-yet relatively little known-theorem, let's briefly review its


have } { p = O.l7
proof. Let /, be the indicator function of the event {N ~ n}. So SN can be writ1en as
£[S,]=pux83-(l-p())xl7=So=O -O => £[~]=1441
00 2
E[S ]- N]=E[p x832+(1-pa)xl7 2]-£(N]=So -O- )
S .. =LX,I,. where 1, =I
U•l
if N (!: n and 1, = 0 if N 5 n -I .
s a . d f the bridge (the I OOth meter
Hence the probability that he will make ldl toh thexpelelct:d number of steps be rakes to
From the definition of stopping n1les. we know that }11 is independent of X , X, ._,. • • • before' reaching the begmmng
· · ·ts 0· 17 ' an t·de e· 1441
. · 1 d of the bn ge lS · ·
reach either the begtnnmg or t 1e en
11 1

(it only depends on X"X 2 .···,X,_,). So E[X,!,]=E[X,]E[l.,]=E[X]E(In] and . metric random walk starttng
°
· t a ooeneral fJcase.
> ).aThe . . that ·tt st ps· at a
symprobabJirty
E[S. ] =Er tx..t.} t.E[XJ.)= ~£[ XJ E[I.,J =E[ x)t, E[ 1.. )= E[X ]E[Nj . 1
We can easily extend the solutiOn _
from 0 that stops at either a (a> 0) or f3 (
0
instead of -P is Pa = f3 /(a+/)). The expected stopptng
0
. . time 10 reach either a or -fJ
A martingale stopped at a stopping time is a martingale. is E[N]=aP.
- --- ~

Drunk man

A~ drunk n.1an is at the 17th meter of a tOO-meter-long bridge. He has a 50% probabilit~ Dice game
I 11 you are
'd h face value. If a roll gjvc.s 4. 5
pat t" c the game slops.
. What 1s the
ot_staggen~g forward or backward one meter each step. What is the probability that he
1
Suppose that ) 'OU roll a dice. For eac ro '
. If you get 1 2 or .>,
Will mak~ 11 t~ the end of the britlg~ (the 1OOth meter) before the beginning (the Oth
or 6. you can roll the dice agam. ·
meter)? What 1s the expected number of steps he takes to reach either the beginning or expected payoff of this game? the problem. A
the t:nd of the bridge? to so 1ve
· 1
. I w of total expectattOJ ' : alitv si nce the
Solution: In Chapter 4, we used the a I ·d '·- is to apply Wald s Equ ·b·lbility of
So.lmion: The probability pan of ~he problem--often appeariryg in different disguises- - is simpler approach-requi~ing more knowe~c~t: rolL the pr~ccs: has: 1/2 ~:~ and we /2
problem has clear stopptng rules. For t ic distnbuttOn \\Jth P . . .
umong . I he most popular martmgalc problems asked by quantitative interviewers.
lnter~sttngly, few people us ..· a clc1.1r-cut martingale argument. Most candidates cith~r .
St()pping. So the stopping ttme N .fl
0 !lows a geome r . X
d iacc value is Ef ::::I 7 I 2 · fht:: tota1
u~ ~~ra~kov. chain with t:-ro absorbing states or treat it as a special version of the have E[N} = 1/ p = 2. For each roll, the expccte
gamblt!r s rwn problem wJth P = 1/2. Th~::;e approaches yield the correct results in the . E[N]-
expected payoff is E[SN] = E[XI - 7/2 >< 2 =7.
end. y~:t a martingale argument is not only simpler but also illustrates the insight behind
lh~ prohkrn.

Ticket line . . kets. n of them have only. $5


waiting to buy ttc change to start
At a theater ticket oflice, 2n people me b'll The ticket seller has 110
~~"''ut"S
0
~ J~~~~~ ..r••ben
b~ ., ~ndGallager.
otlf G. applk.'illiuns of Wald's Equality. please reter to the book Disaete Stocllu~ti£·
bifls and the other n people have only $l 0 1 s.

I I6
117
. l G 'de To Quantitative Finance Interviews
A Prae11ca u•
Stochastic Process and Stochastic Calculus

with. If each person buys one $5 ticket, what is the probability that all people will be
able to buy their tickets without having to change positions? b

,\'olution: This problem is often considered to be a difficult one. Although many can
correctly formulate the problem, few can solve the problem using the reflection
principle.8 This problem is one of the many cases where a broad knowledge makes a
di fTc renee.
--------
-1 ..-.. .~
Assign +I to the n people with $5 bills and -I to the n people with $ 10 bills. Consider ····... .... ·..··..·"':'
-2
····... ...../
the process as a walk. Let (a,b) represent that afte r a steps, the walk ends at b. So we ···...
start at {0,0) and reaches (2n, O)after 2n steps. For these 2n steps, we need to choose n ··...
··....··
~h.~r>S us + I. so there are ( 2
l 2
n = n! possible paths. We are interested in the paths that
. .15 the reflection of the solid line
n ) n!n~
Figure 5.6 Reflected paths: the dashed ltne
have thl.! property b?! 0, '\10 <a< 2n steps. I~ ~asier jo_calwlate tht· _number .Qf
after it reaches -1
~ompl.\!mcru,paths.lhat$,LCh h =- l.- 30 < a< 2n. As shown i.n Figure 5.6, if we reflect
t.h~.: path across the line y =- I after a path first reaches - t , for every path that reachc~
(~n. (J) al step J n, we h~~e one corresponding reflected .P~th. {ha.tieaCF\es l2n,- 2) at Coin sequence d ber of coin tosses to get 11
step 2n. I or a path to reach (2n, 2) . there -;;e ·(n .:.·i)
·;t;ps of + 1 and (n + 1) steps~I. . . What is the expecte nwn
Assume that you have a fatr com.
211
So there are (
n-1
=
2
J
n!
(n-l)!(n+l)!
such paths. The number of paths that have the
heads in a row? . ds in a row. ln
ber of coin tosses to get n hea . H)
Solution: Let E[f(n)] be the expected num ,. =3 (to get the pattern HH . ·
· d the case when:: n . M kov charn
property b = I, .30 <a< 2n, given that the path reach.es (2 n, 0) is also (
211
Jand the the Markov chain section, we dtscusse . d t· 011 approach. Ustng the 1 ar A ah •ra l
n-1 For any integer n, we can canst·d cr an m uc t
_? £(/(2)]::: 6 and
£[/'(3)) -- 14 · n '"'
number of paths that have the property h?! 0. '\10 <a < 2n is approach, we can easy get that E(j(l))- -) "...1 _ As always, let's prove the
·15 th t Elf(n)) == 2 2· 3 S we onl)
[
n )
-l
?.n \ · 2n ) = ( 2n l _~(2n ) = _ 1 ( 2n '\
guess for the general formula
formula using induction. We have 5
a .:_. . ul 1'S trUe for n == 1,2, · 0
hown tne torm a ·
,.2 _ 2 The fol\owmg 1 ::.
d' a(lram
n- J n ) n+ l n ) n+l l n / ,,, 2 £[/ (n+l)]= 2 ·
need to prove that if Elf(n)] = 2 - ' r E.[J(n +1)}:
lienee. the .r.rQba?ility that all people will be able to buy their tickets without having to . holds tOT
shows how to prove that the equal JO0
chclJlg~o:
postltons IS 1/(n + 1).
P=l/:_. ~

P~I /2 ds in a row
n + l)H ) must be n hca
w (denoted as ( nH.
1
Consid('r n rand<l 111 \\a· Jk srart•%
· · ,. . · · ·
n. S = n. and rcachmg h 1n 11 steps: s, ""b. Denote N,(a,b) as the
at
. .
The state before (n + 1) heads m a ro l ?"+' _ 2 tosses to rc·teh •
t··d £[ f(n) ==- f (the new toss
numl)cr of po~~iblc paths from (0 ) (denoted as nH ). lt takes an ex pee c b.l· 't ' it will go to (n + l)rc . the
.. ' ,a to 111. b) an d ·'. (a. b) as the number possible paths from (O.a) to · U2 proba 1 1) t ·t w1l1 go to
I rJd' l that at M'mc step k ( ~ > o ) ,. )· , ·1 Conditioned on state nH. there ts a . probability t11a 1
· • • •'. ~ ( , tn other words. ,v (a. b) are the paths that con tau . There tS also a 112
Yields H) and the process stops.
' ' t~l. .30 • I .. II. The renee lion principle ays that if a. h > 0. then '\ I a. I> I = v (-o. h ) The proof is
IU UIII\' ~ ior 1i th path (() 11 ' t0 ( '· ~) h " . • •
• ' "· "~· ' cn.:tsaone-to-onecorrespondingpathfrom (0. -o) to (k.OJ.
119

I 18
Stochastic Process and Stochastic Calculus A Practical Guide To Quantitative Finance Interviews

swning sLate 0 (toe new toss yields 7) and we e 26• All the (i- 6) players before him went bankrupt; the (i - 4)th player loses in the
to reach (n +l) f-l. Sowehave n edanother expected E[j(n+l )] tosses
second toss (HT); the (i - 3)th player and the (i- 2)th player lose jn the first toss (1);
2
£f.((n +I))= E[F(n)] +tx I+ fx E[.f(n +I }] the (i -l)th player gets sequence HH with payoff 2 and the i-th player gets H with
·. "> f:[_l(n +I))= 2x £[F(n)]+ 2 = 2,H 2 _ 2 payoff 2.

G~n~.:ral Martingale approach: Let's use HH · · · H to explaLn . Hence, £[(x1 - i)] = 26 + 2 2 + 21 - E[i] =0 => E[i] = 70.
1
expct:h:J time 10 get an . n a genera approach for the9
. Y com sequence by exploring th . .
Imagme a gambler has $ 1 to b e stopping ttmes of martingales.
. et on a seq uence of n h d ( HH . . 5.3 Dynamic Programming
w1th the following rule· Bet . ea s ··· HI, ) m a fatr game
rI me the gambler bets .all sh'are P1aced on up to n consecullve . games (tosses) and each
Dynamic Programming refers to a collection of general methods developed to solve
. •. . . .
.tpp....u:s at the first game he w'lll IS money (unless he go
$ es ank rupt). l·or
b - example .1f II
sequential, or multi-stage, decision problems. 10 lt is an extremely versatile tool with
·st op:-;. PI·<lymg
. e1ther
. when , he 1I mve 2 and he will pu t a II $2 tnto . ' He
the second game. applications in fields such as finance, supply chain management and airline scheduling.
oses a game or whe h .
G ISt..' hl.: collects $2" (' ,.th b b. . n e wms n games in a roll in which Although theoretically simple, mastering dynamic programming algorithms requires
pro a 1l11y 1/ 2" ) N , . . . . •
h~fore each toss <:LP t.>W ~ambler . . . .~, . ow l~t s m.la_gme. mst,§ad.of ()QC •ambler.
_. v\l
extensive mathematical prerequisites and rigorous logic. As a result, it is often perceived
w11. h n h·.mk.1o11 of S 1 as - -well·- At! h . · and bets_Qfl· ~he_s~m~eg_uence of n heads
JOJOs_lue...g,ame to be one of the most difficult graduate level courses.
gnme and the total amount~f · er t e H h game, 1 gamblers have participatedm ih:
game is fair. the exn.•cted val monfeyh t~ey have put in th e game should be $i Since each
:ortu~ately, the dynamic progranuning problems you are likely to enco~nter in
. , ~"~ ue o t e1 r total b nk 11 · . · . mtcrv1ews- although you often may not recognize them as su~h-are ~dtmenta':Y
0~::nott: x, as the amount of mon . II h .a. ro ts $1 as well. In other words. tf w~ problems. So in this section we will focus on the basic Jogtc used tn dynamic
ey a t e parttc f
then (x, - i) is a martino tpa mg gamblers have after the i-th game. programming and apply it to several interview problems. Hopefully the solutions to
0 a1e.
these examples will convey the gist and the power of dynamic programming.
~~~- l.et 's add a stopping rule: the whole . .
~ hr:-t to g~l n he11ds in a roll !\ . game wdl stop tf one of the gamblers becomes Adiscrete-time dynamic progranuning model includes two inherent components:
So '' ~• ~·t'JI
1
haw E[(x - i)J = ()· •martmgale stop ped at a stoppmg . time is a martinl!alc.
11 t11e scquen - 1. The underlying d iscre te-time d ynamic system
ce stops after the i-th toss ( i ~ n ). the d)~namic stag~s ~ith dcc~s~on
. I •
(t- n + I) -th player is the fi . )
1 A programming problem can always be divided in!o a
required at each stage. Each stage has a number of states assoctated With lt. The decl~lon
I . ' trst player who • 11
t I\.' (r- n) players before him " b gets heads in a roll with payoff 2". So all
· \\\;nt ankrupt· tl (1· at one stage transforms the current state into a state in the next stage (at some stagc.!s and
tn a roll "ith pavofr 2"-1. . . ' le - n + 2) -th player gets (n - I} heads
)' n" •
I ' 1) \J r:> fixed <.~nd x -:; ;. 2") "" the
11-1 /-(h pla
) er gets one head wi th payoff 2. So the total
1
:>tales, the decision may be trivial ifthere is only one choice).
Assume that the problem has N + l stages (time periods). Following the convention~ ~e
. +-1 -1· .•. + 2' :::: 2" +1-?
Hence, F[(x ·- i)] = ' ) li d
', I -
_ 1 .
- - £f/l ::: 0;:;:>£[i] =2"+J _2
- · label these stages as 0. I, . .. , N -1, N. At any stage k. 0 ~ k ~ N -1. tbc state transit: Jon
rhh a_pproach can be .. . can he expressed as x = ((x u w ) where x .. is the state of systt!m at stagl! k: uk
sl!qu~nces '' iih o applll.:d to any coin senue
f/H1JT.I!II·- " . ar !lrnry nwn~~rof -·1· : nces- as_well as_~ice sequencesor an)'

IS the
k~J . /c' k, 4 ' •
decision selected at stage k, wk is a random parameter (also called di sturbance).
!!~lllbl. . ·. ". ~:can 'gam
a · usc a stopped ~ ~.:mcnts
m . · fo r cxamp1e, let's consider· - the sequen~a:
· --
f!HrT~~HsJOin. the game one by on ~ b ~rtmgale process for sequence HHTJHfl. The
unttl on , b
Sl!tjuence st .. , ~ gJm ll!r b~comes the f .
· t: etorc each t ) b .,
( ss to ct on the same sequcnc'-
. op:> alter lhe i·th toss th. c· - trst to get the sequence 1/HTTHH. If the '" Th' . . . • ·n , For up-to-date <h nmnic
9 lf .
••
~am blcr gets the HHTTHH wjth payot1'
\: 1 - ) )th g sect1on barely scratches the surface of dynam•c programnu g. .
ti~g~a1_nming
IS
topics. I'd recommend the boOk Dy11amic Progr ammillg and Optunal Ctmt
rol b. Profc:Gnr
>
n.. ~ou prdN mur··' U.ll...,, 'I
. ~ the
In " ~
'l:i .II li 'tho
.
~~o url'\.·n~o:t: of s • ut 1 I·1 ~ :tJ')pro·tch 1ease refer 10 lllnllln P. Bertsekas.
. . . . .
di ·cuss1on. we on\) cons1dt:r
~ r:_~ R~peatcd
1
, cquenl:e P·m ·r ' ·P ·'A Mart1ngale
.
I'rrww•illll
L .. ,
, Vol 8 n-; Ill E"p . Approach to the StudYl f oencra 1, x~, can mcorporate all past relevant 1nfonna11on. n our ::;
1
· · · o. (• ~c
6 ·· I980) .
, enment.s"
• PP l l71- 117o. b Sf
) 1uo-Yen Robert l c~:i
· · Li. The AnntJ.,.
Present in[!ormat1on
· by assuming Markov property.
120 121
.. ________________________.....................----------------------
Stm:ha:-tic Process and Stochastic Calculus A Practical Guide To Quantitative Finance Interviews

Basically the state of next stage x.h , is determined as a function of the current state x,. Dice game
current decision u" (the choice we make at stage k from the available options) and thl' You can roll a 6-side dice up to 3 times. After the firs t or the second !oil, if Y?u get a
ranuom variable w.. (the probability distribution of wk often depends on xk and u1). number x you can decide either to get x dollars or to choose to conlmue rolltng. ~ut
once vou 'decide to contmue,
·
you forgo .1u1e number you JU
· strol led · If you gel to the. thtrd
2. A cost (o r profit) function th at is a dditive over tim e. ron. ymi1Tl JUSI get-X do1fais if the third number is X and the game stops. What IS the
1 ·\t:~ pt lor the last stage (N), which has a cost/profit g "' (xN) depending only on x, . the game worth and what is your strategy?
cust!> at all other stages gk (xk> uk, wk) can depend on xk , uk, and wk. So the total Solulion: Thts• •
IS •
a stmple dynamtc • •
programmmg 1 strategy game
· A'-
l- -
all-dvnamic
·--:-- .
. . h h ti 1 t·tge und work backwards. tor
N-\ programming questions the key 1s to start_~1t t e tna s' __ . ,
- . -- - ' ... --- - - ~ th. first two rolls It becomes a
cusuprofit is R ~ (xA )+ L g4 (x~.,ut , wk,l} . this quest10n, It 1s tne.. stage where you have torgone c d · h have a i/6
j ·' simple dice game with one roll. Fa_c~~s 1, 2, 3, 4, 5, an 6 eac
Th\! gunl of optimization is to select strategies/policies for the deci sion sequenl~ probability and your expected payoff~~§~
- 1h · t after the second roll, for
n• fun*,- ... 11 . ,*}that minimize expected cost (or maximize expected profit): Now let's go back one step. Imagine th~t you are. at e po:~ted a off of $3.5 or keep
which you can choose either to have a thtrd roll wtth an expf .. p Y than 3 1·n other
· k h f: ce value 1 1t IS 11ugcr ·•

the current face value. Surely you w1l 1 eep .t e a ,et 1 2 or 3, you keep rolling.
\\Ords, when you get 4, 5 or 6, you stop rolhng.. When Y~~! J/6x( 4 +S+6) = $4.25.
So your expected payoff before the second roll ts 3/ 6x ·
. are at the point after tht: ftrst roll,
Dynamic programming (DP) algorithm ~ow let's go back one step further. lmagme that you . d yoff $4 ? 5 (when
r . . d roll wtth expccte pa ·~
lOr wh1ch you can choose etther to have a secon S 1 will keep the face
The. c.l yn.amie progmnuning algorithm relies on an idea called the Principle of face value is 1, 2, 3 or 4) or keep the current face v~lue. tu~c y ~o~ou stop rolling. So
Optamah tv: If It*-= r111 • • 11 *} · h . . .
dynamic·, value if it is larger than 4.25; In other w~rds, when y:u 7~x(S ~ )=$14/3.
1
0
~ " • • • • :. _, 1s t e optunal policy for the ongmal
program mmg problem, thea the taj l policy "• = {u "'· .. . u *} must be optimal for tht> your expected payoff before the first rollts 4 I 6 x 4.25
6 . .
I I ' N- 1
. \' I . . . d namic prooramming- gtvcs us the
t<lll suhprobkm £{g, (x )+ "" g (\· . )} Thts backward approach-called tail pohcy m Y . . . c • $l 13
'. \ ~ ~ . .(•ll, .llk . •1 at the mtlla1stage, 4 ·
... T.J strategy and also the expected value ott 1e game

DP algorithm: To solw tl " b . . . . v' . .


_ 11:: a:;1c ptoblcm J~.(x11 ) ; min E{gN (x,.,) + L gt( x~ . u 1 .1'tl.·
• -- IT World series
.. . Ia in in the World Series finals. In
f • ( ' - -

~-arl w1th J •. (x~) - g (x }. and , . . . . . . . ·: . . L·


· - _ . _:_ go backwm w mm tm tzmg cost-to-go functwn .I; (.\J r· I he Boston Red Sox and the Colorado Rocktes are P Y g . ·mltm of 7 g'an1cs and
.l,( xt ) - min l!{g ~ { 11 --:--
) . - - - · there are a m,lxt
,.l •·• • ~ · t ·u , + .l;..,C/(:rl. uk,l1·i H}.k = Q, ... ,N-L Then the J,(\ , 1 case you are not familiar with the World enes, . h. You have $100 dollar~ to
S
lhc fi rst team that wins 4 games claims the champiOnS tp.
gen\!rtH~.::d 11-om lhi!\~Jgorith;n is the ~pccted opti~lal cost. -
~~a-~~ a double-or-nothing bet on the Red So~ . . •l ol· How
r\ltlmugh the algorithm looks CO! I' . - . .. - . ic - - ot the cocrtCS as a \\ l t:.
U01(' · d. ·d · l game n ·' ·
progrum min~ pt·oblems
the !in.d SH;ue 'whi ·11.
"" '
untcrtuint)) tirst and th. .
:e I I llp lCated. _the I!){UJttOn is straightfonvard. for dynal11 r
Slloul~ start wnh optimal policy for every possible state o.
~.; 11<.ts t 1e htgh 'st •
l:
.
amount of mformation and least amou .1
nt ul
onunately you can only bet on each Ill lVI ua
'
much should you bet on each game so that 1 t e
exactly $100, and if Red Sox loses, you lose exactly$ ) · 0
· · the •vbolc series, you wm
·f h Red Sox wt ns
Q?
v •

. • ~.:n \\·ork backw· d d · t11e 1:11 · mes and the


Pl>lt~ic:s unJ ~:ost-to-•'o fun . . . ·<.1r towar s earlier stages by applymg . . ed So:< has won t ga
N • : : - ~ 1ton~ until you reach the · · · 1
tl1ltJa stage. .\ulut~<m: Let (;, j) represents the state that the ~ ff h. h can be negative when
ow kt s u~e ~e\ cml ~:xample . I 0. h R k' · ') be
oc 1es has won} games. and let .f(t,J our
net payo · w tc
" know that there may be
s s ow ho\>v. the DP algorithm is applied. - I 0 f the game. \\C
we lose money at state (i j). From the ro cs , . that whene,·er the
be ' ' - d . ide on a strateg) s 0
tween 4 and 7 games in total. We need to ec
l23
I :!2
..
S1ocha:-.tic Process and Stochastic Calculus
. 1Gu1'de To Quantitative Finance Interviews
A Practtca
s~.:ri~:s is over, our final net payoff is ei ther +I 00- when Red Sox wins the
championship-<)r - 100-when Red Sox loses. lo other words, the state space of the Red Sox Red Sox
final stage includes {(4, 0), (4,1), (4,2), (4,3)} with payoff /(i,j)=JOO and -
wins 0 1 2 3 4 wins 0 1 2 3 4
f(0.4), (1,4), (2, 4), (3,4)} with payoff f(i ,j)= - 100. As all dynamic programming
qu~stions, the key is to start with the final stage and work back wards-even though in ..
;.
0 100 ~
0 8~5 -100
i :2
this case the number of stages is not fixed. For each state (i , j), if we bet $yon the Red ~ 1 100 ~ 1 7~~ 1-100

Sox forth~ next game. we will have (f(i, j) + y) if the Red Sox wins and the state goes
:=: a:
~

-5 2 100 Q 2 104 ~00


to (i ·I I, j), (lr (.f(i. j) y) if the Red Sox loses and the state goes to (i, j +1). So ~ ..
'Q
eo
-8• .!3 ~~s~ ~-~ 1-2• 100
clearly we have :>
e
\,;
3 2• ~100 2
0
()
3

4 -100 -100 -100 -1 00 4 -100 -100 -100 -100


I

f(~ +.1 . J) = f(~, ~)+ Y~ ==:> {f(i, j) =(f(i+ 1, j)+ f(i,


j + I) )12.
/(1, /+ 1) .::: f(t,j)-yJ .v=(f(i+1,j)-f(i,j+l))!2 1
Red Sox
Red Sox

bets 0 1 2 3 4
wins 0 1 2 3 4
4
For examplt:. we have /(3. 3)=/( , 3)+ /(J, 4) = IOO -I OO =0. Let's set up a tabk 0 0 3 1 . 2~ 62.5 87.5 100 0 131.2~ 31.2~ 25 12.5

Ci ~ ~

2 2
with the columns r~presenting i and the rows representing j. Now we have all the
:i :i
~ 1 -31 .3 100 g 1 31.2~ 37.5 37.5 25
0 37.5 75
~ a:
information to fill in /(4, 0), /(4, J), /(4. 3), /{4, 2), /(0, 4), /(1, 4), /(2. 4), e
2 -62.5 -37.5 50 100 0 2 25 37.5 50 50
/(3, 4). as well a:; /(3,3). Similarly we can also fill in all j(i,j) for the state· wh~re
~
Cll
0 'Q
~
e
f0 12.5 25 50 100
3 -87.5 -75 -50 0 100 3
"3
i .;:= :\ or .i == 3 as shown in Figure 5. 7. Going further backward, we can fill in the net v I 8 4
payo ffs at every po!'sible state. Using equation Y=(J(i+I, j)-f(i, j+J))/2. we can
4 -100 -100 -100 -100

Figure 5.7 Payoffs and bets at different states


-
also calcuJate the bet we need to place at each state, wh ich is essentially our strategy.
lf) ou are not ac(;ustomed to the table format, Figure 5.8 redraws it as a binomial tree. i.!
format 100
4 you should 4
be familiar with. If you consider that the boundary conditions are
(4,0)
j ( , O): /( . I),. /(4, 3), /(4, 2), /(0, 4), /(I, 4), /(2, 4), and /(3, 4), the 100
~IIH.k·rly mg ass~:·t ctther inc reuses by l or decrease by J after each step, and there IS no 87.5
(3,0)
(~.1)
100
,. . . then
tnh:n.·st. , probkm
, 1. . thl.! .10 bt:comcs a ·s,·,nple b'lllomta
. I tree pro bl em and lhe het we plncc 15
~.tc~ tun~ ~ th~
. . 62.5 (4.2)
(3.1) IUU
ddta dynamic hedging. In fact, both European options and Amencan
< (10)
(2,0)
opt tons ca n b~ so l\ l.!d nun1er'1 " II . .· d . 50

<
31.25 37.5 tUl
(3.2)
C" Yusmg ynam1c pmgramming approaches. (2.1)

10~0) 0
( 1.1) (2.2)
0
(J~J) - 100
·31.25 -50 (3,4)
-37.5
(0, I ) (2.3)
( I .2) -100
-62.5 -15 (2,4)
(0,2) (I ,3)
-1 00
-87.5 (!A)
(0,3)
-100
{().-$)

Figure 5.8 Payoff at different states expressed m a binomial tree

125
»

A Practical Guide To Quantitative Finance Interviews


Stta:hastic Process and Stochastic Calculus

Dynamic dice game Dynamic card game


. d d 52 cards (26 red 26 black). The
J\casino comes up with a fancy djce game. 1t allows you to roll a dice as many times as Acasino offers yet another card game With the stan ar one (Drawn cards are
you want tmh:ss a 6 appears. After each roll if 1 appears, you will win $1 ; if2 appears,
1 cards are thoroughly shuffled and the dealer draws cards o;e ~ytime .you like For each
you will win $2; ... ; if 5 appears, you win $5 ; but if 6 appears all the moneys you ha\'~ not returned to the de~k.) You can ask the dea~e~ to~~~:u :se $!. What is tl~e optimal
won in th~ game is lost and the game stops. After each roll. if the dice number is 1·5. red card drawn, you Win $1; f~r ~a_ch black car araoff a~d how much are you willing to
you can decide whether to keep the money or keep on rolling. How much arc you slopping rule in tenns of maxtmlZlng expected P Y
willing tu pay to play the game (if you are risk neutral)? 12 pay for this game?
. b d'fficult by many interviewees. Yet it is a
Solution: /\ssuming that we have accumulated n dollars, the decision to have another Solwion: It is another problem perce1ved to e 1) t the number of black and red
roll or not depends on the expected profit versus expected Joss. If we decide to have an simple dynarnic programming problem. Let (b, r represen
extm roll. uur expected payoff will become cards left .m the deck, respecttve
. 1Y. BYsyrrunetry • we have .
I I I ., 1 I l 5 ds le'i- red cards left =h- I
- (II -+ I) + - (11 + 2) + - (n + J) + - (n + 4) + - (n + 5) + - x 0 = - n + 2. 5 . red cards drawn- black cards drawn = blac k car · .1'
6 6 6 6 6 6 6 keep on playing. If we ask the
At each (b, r) , we face the decision whether to stop or . h
. b- If we keep on got ng, · there IS -
b+r
We haw another roll if tht: expected payoff ..?_ 11 + 2.5 > n, which means that we should dealer to stop at (b , r), the payo ff ts r.
6
keep rolling if th~ money is no more than $14. Considering that we will stop rolling . in which case the state changes to
probability that the next card will be black- . ..
v. h~n 11 ~ 15, the maximum payoff of the game is $19 (the dice rol Is a 5 after reaching - ·u b red-·in whJch case the state
the state n=I..J). We then have the following: /(19)=19, .f(l8)=18, /(17)= 17. (b-1, r) -and - '- probability that the next card Wl e .
b+ r . ected payoff of drawtng more
/(16) =16. and /(15) =I 5. When n $14, we will keep on rolling. 50 changes to (b , r -1). We will stop if and only tf the exp . .
. I s • cards is less than b- r. That also gives us the system equauon.
ELf (n) Ins 14] = 6LEff(n + i)l. Using this eq uation, we can calculate the value lo~
13
·-·
Elf(n)j recursively for all n =14. 13, ···, 0. The results are summarized in Table 5·: .
b _!._[f(b,r-1)])·
E[f(b,r)] =max ( b-r, -E[f(b-l,r + b+ r ·
)]

•Sine~ £f./"(0)] -·
- 6· 15· we are Wt
·11·mg to pay at most $6.1 5 for the game. b+ r
the boundary condttiOns
..
.r - ,
j "(O ) - ()
As shown in Figure 5.9 (next page), using . for E[f(h. r)1 , \ VC can
II ILJ 18 17 16 15 j (h, 0) = b, Vb, r = 0, 1, ... '26, and the system cquatton
14 13 12 II
· f band r
UU)t) 17.00 16.00 I 5.00 rccurswely calculate E[f(b, r)] for all patrs 0 '
14.17 13.36 12.59 11.85 11.16
. F:[ {(26. 26)} = $2.62.
8 7 6 5 4 3 2 0 The expected payoff at the beginning of the game lS ' · ·
10 5
(nJ ·~ 9 91
· 9.34 8.80 8.29 7.81 7.36 6.93 6.53 6.JS -
Table 5.2 Expected pa ff f th
yo 0 e game when the player has accumulated n dollars

l! I hr.l: If Y~• dccid~ hl have another roll . ' hi(!h.:r ,.


·
[I r American optiOns.
f:,ssct!fi u.Jl\
, .
\ "OU

II~~~ lhe llfll(llltll be for~: th~ 11 A. h · the expected amount you have aHer the roll should bt: ·r-. 6 .y tion as the one o
app..l1\, ~~~ \\hen the amountm\l"d · more~ 1-none", 1 •
· s t c number of do 11 ars ·Increases. vou risk losml!. ou probably have recognized this system equa )
1
o11ar reaches a ccrtam
• · number. you should
·' - decide whether you want to exercise the option at slate (b. ' ·
stop rolling.
127
12t.

A Practical Guide To Quantitative Finance Interviews

5.4 Brownian Motion and Stochastic Calculus


In this section, we briefly go over some problems for stochastic calculus, the counterpart
of stochastic processes in conti nuous space. Since the basic definiti ons and theorems of
Bro-wnian motion and stochastic calculus are directly used as interview problems, we' ll
.t-u~· Prn..;.•ess <~nd S!Ocha~tic Calcu lus simply integrate them into the problems instead of starting wi th an overview of
Number of Black Cards Left definitions and theorems.
2 3 4 6 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 • J
2 3 4 5 6 7 8 9 10 1\ 12 13 14 15 16 17 18 19 20 21 'i' .ll 11 •
4 5 6 B 9 10 11 12 13 14 15 16 17 18 19 20 21 11. ~ , Brownian motion 1
3 4 5 6 7 8 18 19 20 <I :l :
9 10 II 12 13 14 15 16 17 A. Define and enumerate some properties of a Brownian motion?
0 2j 0 !101 0 ~5 1.34 2 3 5 6 7 18 19 <• ;· ~ I
8 9 11 17
So~ttion:
10 12 13 14 IS 16
(lJii D'lC iJ&.1 l DO 1 44 ~.07 3 4 5 6 7 8 9 10 11 12 13 14 15 16 TI1is is the most basic Brownian motion question. Interestingly, part of the
I' IT fllJ ;l 54 II 71f I 1' 1.55 2 15 3 4 5 6 det.mition, such as W(O) = 0, and some properties are so obvious that we often fail to
t• 0711 o4s OSfl os1 123 I s s 2.23 3 4 s s e 9 10 11 12 13 14 15 16 17 1*
l 025 a~ 056 o 1 1.o 7 8 s 10 11 12 13 14 15 115 ,. recite all the details.
111 6 1 134 1.75 2.30 3 4 5 6 7
D 1t 0.22 0 35 0.49 11< '6 6 0.86 I II
1.4 3 1.84 2.36 3 05 4 5 6
8
7
9 10 11
10
12
11
13
12
14
13
15 A continuous stochastic process W (I), t;::: 0, is a Brownian motion if
8 9
ll •o o~ o ,., 0.43 ose o.7s o.ss 1 21 I 52 1 92 2 43 3. 10 4 11
5 6 7 8 9 10
liOQ
cIJI'j o •• o ·2e o 39 o 52 o.66 o.8...) 1 04 1.30 1.61 2 00
• W(O) =O;
1)11 0:1«1 035 046 0 59 0.74 0.91
"' Ql" u:r~ 0 32 0 42 0.54 0 66 0
. 2.50 3.15 4 5
1.12 1.38 1.69 2 08 2 57 3.20 4
6
5
7 8 9 \0 11
• The increments of the process W(t1) - W(O), W(t 1 ) -W(r,), ... , W(tJ-WU.. J,
6 7 8 9 10 11 ' l.
D(J? 1114 (1 22 0:!0 0
~ .81 0.99
39 0 49 0 60 0.7J O
120 1. 46 1.77 215 2.63 324 4
5 6 7 8 9 10 I. ' 'VO $ l l ~ 12 ~ ··· ~ t, are independent~
D.Cfl 0
13 :; :m 0.28 ~
o.Js 45 o.s5 o.s7
89 l.06 1.28 1.53 1.84 with distribution
2.22 2. 7o 3. 28 4 o 3 s e 7 a
normally distributed
OOrJ o 13 t n 25
0
0 33 042 051 06
80
° 0
9s 1.13 1.35 1 60 191
2.29 2.75 3.33 4.06 5 6 7 ~ • Each of these increments lS
QQB . • I 0.73 0.86 1 02 1.20 1.42
012 18 o 24
c 031 .4 o.s?
0 39 0 7
t .67 1 .98 2.36 2.61 3.3s 4.09 s e W(ti+I)- W(tJ - N(O , '••I -t,) .
!:a$ 0,. 0 11' 02'., 029 036 0 067 0 79 093 1.08 1.27 148 1.74 2 OS 2 42 2.87 3 43 4 13 5 6
Some of the important properties of Brownian motion are tl1c following: continuous (no
JUmps); E[W(I)j ~ 0; E[w(I)' ~ t;
·4 4 0 53 062
~
. 0
II~ 0 11 C!<! 0 2:/1
01~ II~ D~:;
)2d .,._
A4• 0 .41 049 058. 06.73 0.85 ow 1.15 1·33 1.55 161 2.11 248 2.93 3.48 415
J
W(t)- N(O,t); marting"l< property
~
On!. n t, 0.32 039 0.46 . . 7 0.78 090 1.04 1.21 1.39 1.61 187 2 .17 2.54 2.99 3.63 4'iJ • •
CO)
DO$ 1111) ·~ ~ 1Q 0 '"
... 0...~• ~ •.>7
0.43 0.54
G.S l 063
0. 073 0.84 096 1 IO l.26 1.45 1.67 1 93 2.24 2.60 3 ().1 357 ~ "",.
'" I £[W(t + s) IW (I)]= W(t); cov(W (s), W(t )) s, VO < s < 1 ; and Markov property (on
Ollli G 14 0 II 024 0 "" 0 3;," 0 4 1 0
59 0 68 0.78 0.89 1.0 1 1. 16 132
. 1 51 1. 73 1. 99 230 2.66 309 ~•t til
o~"
u
0 0. o23 o 2s .4B 0 55 0.63 o 72 0.83 c 94 1 07 continuous space).
~ 0'1 2.'5 2 72 '1: )
0 ...
... D 13 !1 1d 2 2

~ o~:.e
0 33 0 39 ·J 45 0 52 1. 1 1.38 1 .57 1.79 .>
Thete are two other important martingales related to Brownian motion that are valuable
04~
o,..
t3 o a7
• J.22 o.-<""' 032 0·3t e:
..... , oO.S6
e c o 68 o 77 o 8 7 o ·99 1. 12 12e 1 .43 1.s 2 1.85 z ll 2 4i '• '- I!'
.. •..... 025 43 0 9 on
Oa2 0 .92 IO 1.68 1"0 2 162 4: ; :.
~
o.G4
11 01111 0 111 1 0.30 035 041 047 . 4 1.17 1 .32 1 46 " tools in many applications.
a
lUI! ll •:: ,e o 2c o 24 o 29 0 053 o.so o.ss o 77 o .e6 0 97 1.08 1 22 1 3 7 1.54 I 7~ MIV
' "' l > ·2-'
_ _...._.::..:::::...£.;·~
ll ::.1 ~ C? .01,'1 OlS 01!1 f.IZJ U.. 3~ 0 39 0 45 0.5 1 05 7 0.64 072 081 •.. 26 1 42 •,.59 178 ~1)1 I • Y(t) = W(t / -I is a martingale.

•~ oc :
. - .. 28 0:,2 037 043 . 0.90 1.01 l.i3
• Z() { } · an)' constant and W(t) is a Brownian
Fogure 5.9 Expected payoffs t d. ' " o.s. o." o 68 o." o.es 095 ' ·'" "" '-'' ' " I =exp A.W(t)- 11t 2t , where). 15
a tfferent states (b , rj
motion, is a martingale. (Exponential martingale).

AB . . . ed .
since it i!> a Wiener
rJ' (/)
1 1
rowman motion is often denoted as B Alternatively 1 IS denot as .
ptoces.s. J h' . . . '. I . th t rOU get fam i,Jiar wtth both.
n t IS section. we use both notations mtcrchangeab } so a )
129
l
p;

Stoc:h;htic Process and Stochastic Calculus A Practical Guide To Quantitative Finance Interviews

We' ll show a proof of the firs t martingale using Ito's lemma in the next section. A This approach is better demoostrated m· p·tgure 5·)0- When we .have 81 >0 and
sketch for the exponential martin~a_le is the following: 2
B - B <- B which accounts for 1/8 of the density volwne. (All 8 regiOnS separated by
£[ Z(t + s)] =E[exp {A (YII(I)~!v (s)) -t A, 2 (1 + s)} J
1 I I' )
x= 0, Y =0, y = x, and y = -x have the same density volume by symmetry.
=exp{-UV(t)-fA·t}exp{-y-i 2s} E[ exp{,ZW(s)}]
=Z, exp{ -tA-2s} exp{t 4 2s} =Z,
0.15 .
B. \Vhat is the corrdation of a Brownian motion and its square?
.~
.\olution: The solution to this problem is surprisingly simple. At timet, B, - N(O,t). by 1/)
c
~ 0.1
symmetry, Ef B,J = 0 and E[B;'] =0. Applying the equation for covariana
Cov(X, Y) = E(XVJ- E[X]E[YJ, we have Cov(B, , B/) =E[81J] - E[B,]£[8,2 ] =0-0 =0.
So the correlation of a Brownian motion and its square is O, too.
0.05

C. Let B, be a Brownian motion. What is the probability that B > 0 and B < 0?
1 2

~ol~uion: A standard solution takes advantage of the fact that B


1
- N(O, 1), and B2 -IJ
Js Independent of Bl, which is again a nonnal distribution: B - 8 - N(O. l). If
2 1
81 = x > 0' then for 8~ < 0, we must have 82 - Bl < - x .

f>( Bl > 0. fl: < 0) =c P( Bl > 0, fl~ - B, < - Bl)


s,
_ f'
- j,
I
Ji;e
_,~ , l r·.f I ,
-(.\" ~ &e•,l '/ldy::
r[
~
r 1 . .
2n e -lr 'r.I 'J~d.xdy
Figure 5.10 Probability density graph of (61. Bz-81}

r
= c:l~r ~ ~ rdrd(J = 7I 4Jr - 3I 2n [-
··· 2;r
0

? e
_,J ll ]Y.• = .!_
8
-fr 0 Stopping time/ first passage time _ ·ach either -I ur I?
But do \\c really ne 1tl · · 8 Brownian motion to rc
. r. ,
el tc llltegratton step? If we fully take advantaoe of the facts that A. What is the mean of the stopping ttme ,or a . ._
and B.- R1 arc two liD \'(0 I) o .. . d
be roved by applynlg 1\o ~
-J ' • • the answer is no. Using conditionaJ probabJllty <111 So1Utiun: As we have discussed, B;' -I is martingale. It can P
m cpcndl.'ncL'. "·~ can rd(Jrmulat" th -
~..: e equatton as
PI il1 "> 0. B, < 0) == P(B O lem.ma:
. I> )P( 13,- Bl < O)P(j B~ - Bl 1>1 Bl D
=l 12xl l 2xL2=1 18 8( B2 - I) l El(B2
D( 8 2 -1)
,
- t) dr == 2BdB dt +dt == 2B,dB,.
cJ(B;, - t)= , dB+ dt+- "'B 2
I
1 ' -

aB, I at 2 o '
. {i·R-Ior-Jl. At
. 1 Let T =mm · ' -
?llh ) · \tO, q So t: (t'xp'.i. JJ(·)']. iabl• So d(/3; -I) has no drift term and is a martmga _e. l' " A martingale stopped at
.\ c ts th~ moment generating function of normal random var' ·•
1
N(O. , 1. ' ' . . . • pertv sull app tes.
conttnuous time and space. the rollowmg pro ~

130 }31
A Practical Guide To Quantitative Finance Interviews
!:itocha~tic Process and Stochastic Calculus
h .h r oo and E [ r ) = x x \1. ~ rf) .
a stopping time is a marting_aJ~! So s;-Tis a martingale and E[.BJ. - T]= sg- 0=0. essentially the expected stopping time to reac eJt er x o - ¥ • '

- 2- 2N(x t .roo) =1 the expected value of r x IS oo.


The prohability that B, hits I or -I is I . so BJ. =I => E[T] = E[ B; J::::: I . Although we have P( r.r 5 oo) - '

B. Let W(1) be a standard Wiener process and r., ( x > 0) be the first passage time to
HVnJ
y --------------------- ------------
----------------*:
I
level x ( r, =rnin{t; W(t) = x} ). What is the probabil ity den sity fu nct ion of r, and the I

//
ex pected va lue of r., ?

Solution: lhis is a textbook problem that is elegantly solved using th~ reflecli~m. I
I
'
I
principle, so we will simply summarize the explanation. For any._W.ien~!:_f?ro~_Qg!hs. I

that reach X before I ( f~ ~ I), they hay~ ~qual probability ending_abQVe X Or below X rll
timet,. P(r.$1JV(I)~x)==P(r.• ~1,W(t) $x). The explanation lies in the re!k~ticm
principle. As shov\'11 in Figure 5. JJ, for each path that reaches x before I and is at a k,e)
Y nbon.' x at time t, we can switch the sign of any move starting from r, and the
reOected path will end· at 2x- y that is below x at time 1. For a s tandard Wiener proces..;
(Brownian motion), both paths have equal probability.
P(r ::; 1) =P(r 5: t, W(J)~x)+ P(r,. ~ rJV(t)~ x) = 2P(r.. 5 r,W(I) ~ x)

=2P(W(f) ~ x)~2 _!_ e -~..:n, dw f


· .J2m
. rocess and its reflected path
Figure 5.11 Sample path of a standard Weiner P

. P(
.. rT<;,t
) Ir
=2 ., &ie_ . I
". '~dw==2 [,r, .J2; e-··'l 2dv=2-2N(x 1Ji). 3 · ·
l Suppose that X js a Brownian mottOn w
. .
-·ith no dnft, t.e. JX(
. .
t) = dW(t). If X sturts at 0,
·n i e
S? What if X has <.In 1 m, · ·
\\b(lt is the probability that X hits 3 before hltttng ~ ·
Tak~ the derivative with r~o:spect to I , we have
clX(t)==mdt+dW(t )? " . beth~ probability that the
t: V ~= riPfr. S t} _ dP·:r, ~I) d(x i J/) - r'- 1~, (. • ·
ootution: A Brownian motwn 1s a 111
· artingale.

Let p, · t. · is 't
d at a stopp1ng tm~ •
.. d! - d( ·I r) d ::: 2N '(x I J() x ~ t -.v 1 ::::::> X~ , 'V X > U. Bro\~nian motion hits 3 before -5. S.1 ~ce a matttngale stoppe .. lk Jf \\C
,\ VI I 2 l 2m P, =SI S . Similar to random. \\a · .
h om part .'\. it's ea ~ t0 1 . 1, li I martmgalc we have 3~ + (-5)(1 - ~)- 0 ==> ~ h babilit): that 1t stops at 1.1
~Y s ) O\\ t hll th~ e:xpl.!cted stopping time to reach either a ( a> ' . p > 0 ). t e pro . -n
or .. t1 ( P> 0 ) i~ again E[r;]-- afJ' · ·rh c · 1 1el r is have stopping boundaries (a> 0) and - {J (
. .
· . · e to reach ctther a or 1'
ed toppmg um
expected first passage tune to e' ·
Instead of -fl is Pu = fJ /(a + fJ). 1 he expect s
IS again £[ N] =ap. P( ) be the probability
a martingale. Let I. x . I (!Cr a
I I. When X has drift m the process is no longer · 1 Although X 1s 0 0 00 -
I" ~ tll'line .Ifi ll
"" ..... II I
•.
r'
· •
I hell PI . ) .1f
r sr
d
an only if \4f t) ? .T .
.
Taking the dcrivauve 0
f PI <n
·, -
r , • . . _
that tht! process bits 3 before h1ttmg -5 w en
=
h X ."C at ume ·
II l th r~'lft ou \ I I! d .
• •' can envc the probability density function of .\/ (I) .
133
A Practical Guide To Quantitative Finance Interviews
Stochastic Process and Stochastic Calculus

maningale process, it is stiJI a Markov process. So P(t, x) =P(x ) is actually independent


oft. Applying the Feynman-Kac equatton . 4. we have

mP,(x)+ li2Pv (x ) =0 for -5 <x<3.


Ito's lemma . L X (t)
We also have boundary conditions that P(3) =I and P( - 5) =0 . . of the chain rule in ordmary calcu 1us. e1
Ito's lemma is the stochastic counterpart X)dW(t) and f(X(t),t) be a
mPt(x )+ I 12 P.u(x) = 0 is a homogeneous linear differential equation with two real roots: . fy' dX(t ) - fJ(t X)dt + y(t, •
be an lto process sat1s _ mg - ' f(X(I) I ) is an Ito process satisfying
r1 =0 and r. =-2m. So the general solution is P(x) = c, e0 ·' + c2e -2"'.1 = c, + c~e·~, . · twice-differentiable fllilctwn of X(t) and f. Then '
App lying the boundary conditions, we have
c ~ c.e -
' , II 1 j=
c. -e e -e
I!J;" /( ..(,, , I Om ) e -
I Om ]
df= of +/)(t, X)-
( ar
ar 1 y2(t ,X)-2
!1 +-
ax 2
0
Ox
dt+y(t, X ) afJx
2
/J
j dW(t) .

{l '1 T r , < '' ., -~'0 ::;> ' :.:::> P(O) = c1 + c2 = -<i


c = I /(e-ow -e Jn., ) el 0"' - .::
" "'
of of I 2 X) a2f
Driflrate = - + fJ(f, X)-+-r (t, 3x2
A diff~rent and simpler approach takes advantage of th e exponential martingale: at ax 2 o
Z(t)=exp{A.W(t) - tA. t}. Since W(t)=X(I)-mt , X(t) - mt is a Brownian motion as
2

well. Apply ing the exponential martingale, we have E[exp (ti(X -ml)-t.A?r)]=l for r: ·
Wh t . the mean and vanance of z ? Is
I •
. and Zl -_ "' B1·
A. Let 81 be a Brownian motJOn a . ts
any constant A.. To remove the terms including time 1. we can set It= -2m and the Z1 a martingale process?
eq uation becomest ~~xp(=-2~n.:r) ~_: I. Since a martingale stopped at a stopping time 1 ~ . bout o Since fr is
. t) which is symmetriC a ·
• eiOm -I Solution: As a Brownian mot10n, B{ - N(O, ' an 0 and variance
amarunga k:.w~have P,exp(-2m x 3) +(l- ~) exp(-2mx-5) =1=> ., ...(,"' . about 0 and has me
e 10
-e a constant at t, z, ==.JiB, is symmetnc
~ N(O ,
2 12
/J< var(B,) = t . More exactly, Z, ) · . Applying Ito's
D. Suppo~l.' that X is a generalized Weiner process dX = dt + dW (t)) where W(l) is a value 0 it is not a martmga1c.
Brownian motion. What is the probability that X ever reaches -1 ?
Although zl has unconditional expected ) alz I ·I 2Bdt +JiJB,.

azI dB+- azl dt + 12 x ___!-Jt


~2
=,t

I
lemma to z =JiB ) we have dZI = as I o/ v. I I ' d not 0

Svlutivn: lo solw this problem, we again can use the equation £[exp (-2mX ) :: I I I I • ! I .. B I IS
'l'ty t • the dnft term 2
all the cases that B1 -:1:- 0, w h.ICh has probab1 1
I

pr~::vious
prohll'm with m =- I. lt may not be obvious si nce we only have c~n~

from the ror
1 ocess ·
app~~~.:nt boundary· -·! · To apply the stopping time, we al so need a correspon?~n~ zero. s Hence, the process Z == vfr:Bt ·IS not a martinga e pr
1
pn::,lll.\'l' boundary. To address this problem. we can simply use +oo as the posJllH:
hounJar) and the equation hccornes
. I ~ a martingale process'!
B. Let W(I) be a Brownian motwn. Is W ( )

' l.t1 \' bt' anlt•'IYOC~5.S gi,enb} equation dX(l) -= P(t .X)dl l- y(t , X}dW and f (x) bcafunctionod
l~lm:..• function l'(t.x) ~ E[j(X ) v _ . . . . . h~ rarti•
r ..., , - ·'I . then J (t . x) ~~ a mart in ga le process 1hat sat •sfie;) 1 ~:
"'. . ti' ~~ I a~ II
utll ..., nt1:tlcquation -- P(t .x)~~ - · ( ·) V . T _ f( r l ior
it . A~ r I ••~ --::- =0 and term .mal condlliOil
')

cJS
. .
,, ( . X J-
. roci!SS ·r
' and onlv. if the
) JW(I) i~ a martmga1e P
X. I 1 -

A generahzed
. W1.ener process uX.1.
= a(x •r )dl ... b(x, l c
drift term has coefficient a(x. I) = 0.
135
1)4
Stochastic Process and Stochastic Calculus

Solution: Applying Ito's lemma to f (W(t), 1) =W(t) 3 • we have of = '~w )1 Chapter 6 Finance
awe!) - (' ·
cY c:f It used to be common for candidates with no finance knowledge to get hired into
Bt - 0, oW(t)l = 6W(t), and df(W(I), t) == 3W(l)dt + 3W(t)2 dW(I). So again for the quantitative finance positions. Although this still happens for candidates with specialized
knowledge that is in high demand, it's more likely that you are required, or at least
cas~~ W (t) :1:0, which has probability I. the dri ft term is not zero. Hence W(I) J is not a expected, to have a basic grasp of topics in finance. So you should expect to answer
mart~ngale process. ' some finance questions and be judged on your answers.
Besides classic textbooks, 1 there are a few interview books in the market to help you
prepare for finance )nterviews. 2 If you want to get prepared for general finance problems,
you may want to read a finance interview book to get a feel for what types of questions
are asked. The focus of this chapter is more on the intuitions and mathematics behind
derivative pricing instead of basic finance knowledge. Derivative problems are popular
choices in quantitative interviews-even for divisions that are not directly related to
derivative markets- because these problems are complex enough to te$1 your
understanding of quantitative finance.

6. 1. Option Pricing
Let's begin with so me notations that we will use in the following sections.
T: maturity date; t : the current time; -r == T- t : time to maturity; S : stock price. at time t;
r: co~tinuous risk-free interest rate; y: continuous dividend yield; a: an~ual~zed asset
volatt!ity; c: price of a European call; p: price· of a European ~t~t; (: ~r~.ce of .an.
A~lencan call; P: price of an American put; D: present value, at I , ot tuture dt'vldcnds, K.
stnke price; PV: present value at 1.

Price direction of options


How do vanilla European/Amerkan option prices change when S, K. r ' CJ, ,., or D
changes?
Solution·· Tile payoff o f a ca .1S max(S - K •0) c.u
,,.1d thepavoffofa put is max(K - S.O).
AE 11 · J· 1·11ne whtlc
• • ••
an Amcncan
opt' uropean option can only be exercised at the . exp1ratJon · · 1 •,e ·an figure out tu.ll
L..,

Jon can be exercised at any time before matunty. IntuJtlVC Y " ~ . . " .,
the price of a European/ American call should decrease when the stnkc pnce mcn.:a~\;s

I ~orb . end /nvestnrcmts by Z"i Bodie. Ale:-;


as•c financt: theorv and financial market knowledge. I rccomm . b John C Hull is a
Kane and A1an J. Marcus. ' . . . . c: ml Other Derwot1ves Y ·. . ,
class· for denvatwes, Optwn.t , rutures 0 . 1 1 and derivative pncmg. I d
•c. f you want to gain a deeper understanding of sJOchastlc ca cu us
rtcomm1 d • d II) b'-' Steven E. Shreve.
: F' en ~toclrustic Ca/CJJiulfor Finance (Volumes 1an J
10 Ad ced and Quantitative
F:· or example, Vuult Guidi! to Filrunce Interviews and Vuult Guitle vltn
'""n<·e Interviews.
136
A Practical Guide To Quantitative Finance Interviews
Finance

you pay K now instead of Kat the maturity date, which is lower in present value); and " - S and S = 0' then C(A.S) ~ A.C(S) + (l- A.)C(O) = A.C(S) since C(O) = 0.
Let .), - 2
the third component is the value of the put, which is often considered to be a protection
against fall ing stock pnce. Clearly the second ~hethlro corripo.nents arebOlhpo·sitive. c
Sot he l·.uropean t:ail \hould be wor1h more than its intrinsic va lue. Considering that the
corn.:sponding Ameri can call is worth at least as much as the European call, it is worth
more than its intrinsic value as well. As a result, it is not optimal to exercise the hC(S t)+( l-A)C(S2)
American call before maturity.
C(AS,+(l-A)S2)
Argument 2. Le t's compare two different strategies. In strategy I, we exercise the call
4
option at time t (I < T) and receive cash S- K. Alternatively, we can keep the call,
short the underlying stock and lend K dollars with interest rate r (the cash proceedings
from the short ~ale, S, is larger than/(). At the maturi ty date T, we exercise the call if it's 0
in the money. close the short position and close the lendi ng. TabJe 6.2 shows the cash
tlow of such a strategy:
Figure 6.1 Payoff of a European call option
It clearly shows that at timet, we have the same cash flow as exercising the call, S- K.
But at time T. we always have positive cash flow as well. So this strategy is clearly . C(S - K) If it is not exercised until
ben~r than exerc~sing the call at time 1. By keeping the call alive, the extra benefit can be
If the option is exercised at time t, the payoff at 1
15
' · J
d . ·k ·utral
. E- [ -rrc("1 ) un er ns -ne
realized at matunty. maturity, the discounted expected payoff ( to 1) 1s
_e ' r
,.,
·1· · also have £[S, ] =S,e ·
measure. Under risk-neutral probab1 1ties, we
Cash flow
I
T
So E[e-'rC(Sr)] = e-" £[ C(Sr )] ~e-rrc( £[s,.]) =_e-rrc(errs,).
Sr ~ K Sr>K
.-£!.111 option 0 0 Sr-K where the inequality is [Tom Jensen's inequality. - -rr ~ [ , c; )]
Short Stock s ___ - ") <e-r-rc(errs,) ~ e 1:- C(., .
-- ,._-Sr -Sr Let S ::. e'' S and A. = e-rr, we have C( A.S) =C('1 t
~
-

Y < r under the


Lend K R1 r -K Ke"r Kerr =
.'
·Smce the dtscounted _,., -
payoff e E[C(Sr)
1 · _
s no less than C(S,) .:_or an. 1 -
1
-- b f re expiration.
·- • •
i ota! S ·K .. . . . I t xercise the option e o .
.._ Kerr -Sr > 0 Kerr
Table 6.2 Payoff of an alternative strategy without exercising the call
K>O
- ruk 'utral measure, 1t 1s never opttma 0 e
- - . - - . l a convex functwn o
i Should point out that the payoff of a put IS a so
. f the stock pncc.
. . k ll .
non-dividend paying stoc. · 1"'
BUt ·tt ·ts often optimal to exercise
· an American put on acrty that f (},S) , -< 1·• P(~')
' ·
In fact '
Argum:nt. 3 · L~t'.s us~ _a .mathematical argument relying on risk-neutral pricing and difference is that P(O) == K so it does not have the prop ly to American puts.
.J~nsen s 10 ~~uahty.-Jt f (X) is a convex function~ 5 then E[f(X )] ~ f(Ef X]). From '
P(J..S) ~ AP(S). So the argument for Amencar
. 1 calls docs not app
. , II option for
F~gure 6. 1, n· s. ~bviOus that th~ payofT (if exercised when S > K ) of a call option . . .
.. f
1 cxerctse o an
Amcncan c<~
.
.
. h before an__ex·
.
SHmlar analysis can also show that ear Y _ 'bl' for the wne ng t _
(. (S J- (S- K) ts a convex function of stock price with property po:sst )
d.lVI·dend-paying stocks is never opt1ma
· I except
_,_ __
C(J.S, + (I- J..)S~) < ).C(S,) + (1 - 2)C'(S2), 0 <A.< I. dividend date.
-
. k with strike price $8? is
· ·d d paymg stoc . $90 j<: pnced
··~ :: "-'lime S -:. A 1.11 our d iscu~sion Ot l1 , 1. · B A European put option on a non-dJVI en ·tock with strike pnl:c ~
~ W ISe, the ca ll surely should not be exercist:d.
s . .
~ .lunct~nn
· ·· ·
} (.\ ) is t·onve); if and only if/().x ! (I ·- A.)y)s;J.j(x)+(I-J,)j(y),O<.i.<l.lf
. .
currently pnced at $8 and a put optton °~ . .
the same s .
th se two options?
at $9. Is there an arbitrage opportunity extstmg m e.
.,l
i \.\ ' .. U, 'fix, th.. f( X ) is ~.:onve:-: .
141
Finance A Practical Guide To Quantitative Finance lntcrvi~w~

Solution : In the last problem, we memioned that the payoff of a put is a conv_ex function av
in stock price. The price of a_p_ut o.Q_tio~ as a functiou of tb~ strike price ts a co~ dO=dV--dS
function as well. Since a put option witl1 strike 0 IS worthless, we always have as 2
av
P(O) + ?..P(.K) =A.P(K) > P(A.K). av av 1 2s2a v)dt +O'Sav dW(t)--(pSdJ+aSdW(r))
=<a;+ pS as + 2 a as2 as as
For thi s specific problem, we should have 8/ 9 x P(90) = 819 x 9 = 8 > P(80). Since the 2
put option wjth strike price $80 is currently price at 8, it is overpriced and we should av 1 1s2 a v )dt
=(-+-a as2
short it. The overall arbitrage portfolio is to short 9 units of put with K = $80 and long 8
01 2 . . . ·i ce it has no diflusion term. lt should have
units of put with K = 90. At time 0, the initial cash flow is 0. At the maturity date, we It is apparent that this portfoho IS nsk-free ~ ~ h
have three possible scenarios: . - r V- ov S)dt. Combining these resu lts we ave
risk-free rate of return as well . dO- ( as
Sr ~ 90, payoff= 0 (No put is exercised.)
~~v
av av av +.!.a2sl ~=rV,
90 > S'l' ~ 80, payoff= 8x(90-Sr) > 0 (Puts with K = 90 are exercjsed.) ~ )dt = r(V- ~ S)dt ~ at+rS as 2
2
(av +.!_0"2S2 fJ oS)
at 2 as u
s, < 80, payoff= 8 X (90- ST)- 9 X (80- s/') = s1 > 0 (All puts are exercised.) d'1fferential equation.
which is the Black-Schotes-Merton . . ·e of the 9is_c.a.unted
The final payoff~ 0 with positive probability that payoff > 0. So jt is clearly an uation is a specta1 c.ls
. l . b .d
arbitrage opportunity. Th~ Black-Schole~-J\:1.erton diff~rent~ eq Fe nman-Kac theorem builds the .n ge
Feynman-~ac ~?-~o~~~--- Tl~e dJsco_u:~~nd ~ial diilercntial equations and applies to
between stochastic differential equatJO p

Black-Scholes-Merton differential equation alllto processes in general: . _ {J( X)dt + y(t , X)dW(t) and f(x)
· b uatton dX(t)- 1• ·
Let X be an Ito process gtven Y eq _,\1 ,,f( Y ) IX =x], then V(l,x) ts a
Can you write down the Black-Scholes-Merton differential equation and briefly explain · V(t x) - E[e · 1 '
how to derive it? be a function of X Define functlon . ' .-fl. t'al equation
. fiJes the partial dt eren t
martingale process that sat1s
Solution: If the evolution of the stock price is a geometric Brownian motion.
~+/3(t,x)av +_!_y2(t,x) a~V2 =rV(t,x)
2
dS = JiSdt +aSdW(t), and the derivative V =V(S,t) is a function of S and t, then
applying Ito's kmma yields: at ax 2 -~ -
- .. V(T )-j(x) forall x.
and boundary condttJOn ,x - - {J(r X)= rS and
( av s av 1 2 a2v av .
IV J
"_X
' = -a,+ J1 -as +-cr S -;::-:;-)dt + crS-dW(t) where W(t) is a Brownian mouon. "'dW(I) Let ,, -
, '
2 cs· as ' Uoder risk-neutral measure, dS = rSdt +a.),K equation · becomes the Bl ac k-Scholes-
. d Feynrnan- ac
The Black-Scholes-Merton differential equation is a partial differential equation that r(t ,X)=aS, then the dtscounte "/ i/V .
av o ~ t ,...~ ~2-= ,v.
.
should be suh:;ficd by V: .av av _1al s2 _
. :. . . ._ + rS -+ a2v == r v .
Merton differential equatiOn -+rS-+~v • ~(· 2
ol as 1.. w
C.t as 2 as 2 •

To derive the Black-Schoks-Merton difter~ntial equation, we build a portfolio with two


components: long one unit of the derivative and short ()V unit of the underlying stock. Black-Scholes formula ,·th continuous dividend yield Y
. an calls and puts v.t
as The Black-Scholes formula tor Europe
rh u fl · av ,.. ~.(d)
en le port oho has value I I = V - -S and the change of n follows equation IS'
as .
C=Se-\'rN(d .)-Ke-rrN(d 2) and p=: Ke
., -rrN(-d )-Se·· 'Jr - 1
2
'

H3
I Finance
I A Practical Guide To Quantilative Finance lnlerviews
2
d - ln(Se-yr I K)+ (r + a 12)r - ___:
Jn(S_ I ___.
K)+ (r-
. .:. --...:_ ....,..;.y+
_a_~ 12)r
~_ Under the ri sk-neutral probability measure, the drift of stock price becomes the _risk-free
where
1
- a-h - a$ interest rate r(t) : dS =r(t)Sdt + aSdW(t ). Risk-neutral measure allows the optiOn to be
_ ln(S I K ) +(r- y -a 2 !2)r -d _ 1 priced as the di scounted value of its expected payoff wi th the risk-free interest rate:
d2 - r - ' a-vr:
avr
V(t) = E[ e- j' ''")<!" V (T) S(t)]. 0,; t ,; T, where V (T) is the payotT at maturity T.
N(x) is the cdf of the standard nonnal distribution and N '(x) is the pdf of the standard

normal di stribution: N(x)= [, ~ e->'212 dy and N '(x) = ~ e-x 212 . When r is constant, the formula can be further simplified as V(t) = e-rr E [V(T)\S(t)] ·
-v2~ v 2ff Under risk-neutral probabilities, dS = rSdt +aSdW(t). Applying Ito's lemma, we get
r c_tll~undcrlyl_f2g asset js a futures contruct then yield y ::- r. If the underlying asset is a
foreign currency, then yield y =,.,,where
1

'i is the foreign .risk:free interest rate. - d(ln(S)) = (r - a 2 I 2)dt + adW(t) => lnST- N(ln S + (r - a /2)r,0'
2 2
f) ·
. - -- 2
So Sr = se<r-u 12lr+q..fic, where e _ N(O, t). For a European option, we have
A . What are the assumptions behind the Black-Scholes formula? (r-q7/2}r+a..fic - K 'f Se(r-a212)r..,a!ft > K
V(T) ={ Se ' 1 .
Solution: The original Black-Scholes formula for European calls and puts consists of the 0, otherwise
equations c=SN(d,)-Ke-rrN(d2 ) and p= Ke- rr N(-d )-SN(-d, ), which require the 2
1 ,
followjng assumptions: se<r-o·t2>r+u..fic > K => £ > ln(K I S)-(r -a / 2)r =- d 2 and
I . The stock pays no divideods. [0,. ) l ( "' v a~
<r-~ 12)r+a..fic K) l e-'212 de
2. The risk-free interest rate is constant and known. \ / E[V(T) IS)= £[ max(S7. - K ,O) IS)= [ d
2
( Se - J2;
3. The stock price follows a geometric Brownian motion with constant drift I' and 1_

4
volatilityo-: dS=pSdt + aSdW(t ). ·../

· ! here are no transaction costs or taxes; the proceeds of short selling can be fully
= Serr
r: &
d2
1
-~ e
-(c-!ia)" /2
~
dc - K
[ _
r;:::-- e
Jl ...;2tr
l
-c 12d£

mvested. .J Let i = e - a .Jr , then d £ = d i , £ =-dl :::=:> e~ = - d2 - O'.j; = -d 1


and we have
5. All securities arc perfectly divisible. v
6. There arc no risk-ti·ec arbitrage opportunities. v Se'r fl 1 e- (-:·..fiq/ 12dc =Serr
lr~l -:]'2;
LJ2;d,
_J_e- i:l t2di =Se'rN(d,) ,

K[ _!_e-~' 2 de = K(l-N(-d 2 ))= KN(d2)


8
· ~ow can ym~ dcr~ vc the Black-Sl:holcs formula for a Eu ropean call on a non-dividend Jl &
pay •ng stock usmg nsk-neutral probability measure? Ke -rr N(d2)
:. E[V(T)] = Se'r N( d, )- KN(d 2 ) and V(t) =e ·trE [V(T)] -- SN(d)-
1 •
Solwion: The I3lack-Scholcs formula I' E
stock is · or a uropean call on a non-dividend pay•ng . . .· that t -N(-d1) == N(d2) is the nsk-
From the derivation process, It IS also obv ious ·
neutral probability that the call option finishes in the money.

~ European call option on a non-


C. How do you derive the Black-Scholcs formula ~a n differentia] equation?
dividend paying stock by solving the BJack-Scholes-: er10
Finance A Practical Guide To Quantitative Finance Interviews

Solution: You can skip this problem if you don' t have background in partial difTerential For European calls, the boundary condition is u0 (Sr) =max (S,.- K,O).
equations (PDE). One approach to solving the problem is to convert the Black-Scholes-
Merton differential equation to a heat equation and then appl y the boundary conditions S=exp(x-(r-0.5a 2 )'r) . When X =lf and r=O, Sr =eY'.
to the heat equation to derive the Black-Scholes formula.
2
Let y=lnS (S=eY) and i=T-L then oV = -oV DV =oV dy =~BV and u(S,r)=u(x , r)=
t
&a (rnax(evt -K,O)exp ( (x-'1')
2a2r
}
'II
' at ar · as ay dS s ay
a v =av rav '~==av(J_avJ=.:_!_av +J_ av (av) =.:.!.av +-1 o2V
1

~ (e~" -K)exp(-(x2a-;)r }'1'


2

as 2
t
as as) as s ay S1 ay s as ay S 2 ay S 2 8/ ·
6
=
& a JnK
l

Th e BIack -SchoIes- Merton d.Juerential


rr aV oV I 2
, 8 V , .
-+rS-+-a- 1s- --r ~ == 0
equation
2

a, as 2 as 1 'I' -X dl{l II' :x+ea .Jr X ( ( x- 'I' ) \J = e-&21 2 and when


Let s- - - then dE= a~' e =e ' e P za2r
1 2 )av
8v ( r --a 1 1 -o V -rV = 0.
1 -a-h'
can be converted to -- ~+ -+-a
vr 2 8y 2 &/ ln(K /S) -(r-a /2)r --d
2
Vf=lnK, E= 1 - 2

Ler II = etf v ' the eq uation becomes - Ot~ +(r- .!.a2) au+]_ a J fiu =0. avr
or 2 ay 2 a;/ :. u(S , r) = [ :odl ( se<r-q2 12)T+u .fi'T'&- K ) &1 e- cl/2 d E
Finally, let
ou _fJu (.
x=y+(r-~a'}'= Ins+ (r -~ "')f
I 1 )2u .
and r=f , then : =: and

E[V(T) Is] in question B. Hence, we have


. tl the same as the equation for
Now, it's clear that the equation for u(S, r) IS exac Y
V(S ) _,r u(S r)- SN(d)- Ke n 2
,I =e ' -
_, A'(d. )

of- OT + I -2a ) fu· • WhiCh transforms the equation tO I

as well.

. . ent rice at $1 that pays no dividend.


D. Assume zero 1nterest rate and a stock wtth curr . p an exercise the option and
When the price hits level $H ( H > 1) for the fi(S\ ttme you c
. ou I 2 0 u r:or heat
2
So the original equation becomes a heat/di f:ft s· receive $1. What is this option worth to you today?
1 •on eq uat1on- =-a -r ·

. 011 l l (')- u l or 2 ax solve the problem by assuming that


equatiOn-= -a -
Solution: First let's use a brute-force approach to . der rJ·sk-ncutral measure:
or 2 ax2 ' where · u == u(x, r ) ·ts a f unction of time r and space van·able x· the stock price follows a geometnc ro
· B wn·an1 motton un
d(ln S) =- -+ aldt +aJW(f).
with boundary condition u(x,O) == uc,(.r). the solution is dS=rSdt+aSdW(I). Since r=O, dS==aSdW(t)~ •
When 1 = 0, we have S0 ::: 1==;. ln(S0 ) == 0.
u(x,r)==& fun(IJI)exp( (X - 1f1)20 7
2,rra 2a 2 r ) 1/f.
J l
7 OU l a'u . h initial condition II, (IJI) = j(IJI) is
TI le fun damental SOlutiOn to
heat equa t"on
I -Or -- - - wrt
2 iJ/

~exp{-(x -IJI r .' 2t}.


ft TI'~ log is token to ~Oil\ ~rt the !,tComctri
rs used 10 com~:n th ~ cq t. :-
[3 · . . .
c rownran lllOiron to an anthmt'lic Brown •an mot1on; r - .
. · - {- f u(x, t)::: £ ..
'

'
p(x :: :r ~"o =lf! )f(ljl)dlfl , where p(x, =x Ix.
-
- IJI )
==
..{i;;
{F .
. . . .
· 1 [)em·uttw!.' b}
~ ua ron 1rom a backwa d · · d't on at . (! to The M(lthematic.~ ~ mancta
=
r 0 (the boundary,..,. d"t· r cquatron to a fornard equation with initral con ' 1
wn I lOll at I =- T ::::> r -= 0 ).
For detailed discussion about heat cquatron. please re er
Paul Wilmott. Sam Howison, and Jeff Oewynne.
146 147
Finance A Practical Guide To Quantitative Fin:Jnce Interviews

B . .
2 .
Solution: Under nsk-neutral measure dS=rSdl+aSdW(I). Apply Ito's lemma to
Hence, InS= -+a 1 + aW(t) => lnS+tcr
· / = W(l ) ts
2 •
a rowman mot1on.
. a
dV =( -oV
as
S oV _!_ a2V a1s2)dl + av aSdW(I)
r +-+
at 2 as-' ~('
Whenever S reaches $H, the payoff is $1. Because the interest rate is 0, the discounted 1 CN

payoff is also$ I under risk-neutral measure. So the value of the option is the probability
V=S: ( l 1 2 2s2)dl --l aSdW(t)=(-r+a.2)Vdt-aVdW(l)
that S ever reaches $H, which is equivalent to the probability that InS ever reaches = -srrs +O +2 s3 a s2
In H . Again we can apply the exponential martingale Z(l)=exp{A.W(I) -fA- 11} as "e
. . well and we can apply Ito's lemma to
did in Chapter 5: £[ Z(l)j = £[ exp {,! InS :+a't- t,! ' r}] = 1.
So V follows a geometric Browman motton as
lnV :

To remove the terms including time t, we can set 4 =a and the equation becomes
J
E[ exp (InS) =I. The Let P be the probability that In S ever reache s In H (usin.g -<t:.
as the negative boundary for stopping time), we have
Pexp(ln H)+ (1- P)exp(-oo) = Px H ==I=> P =1I H.
1 -'•"•tr
-e · · r.
Discounting the payoff by e-rr , we have V =e E [r 1
-rr 1 ] -
So the probability that Sever reaches $His 1/H and the price of the option should be - -'t
$1/H. Notice that S is a martingale under the risk-neutral measure; 8 but InS has a
negative drift. The reason is that InS follows a (sym metrical) normal distribution, but S
itself follows a lognonnal distribution~ which is positively skewed. As T ~ co, although 6 2 The Greeks .
the expected value of Sr is l, the probability that s,. ~ 1 actually approaches 0. · • h
artial derivatives of t e o~ '
f on price wtth
All Greeks are first-order or second-or e~
d
h. sed to measure the nsks-~as_ we as
II
lt is si mpler to use a no-arbitrage argument to derive the price. In order to pay $J when respect to different underlying factor~, w~tc Talre ~oHowing Greeks for a dcnvatJve fare
the stock price hits $H, we need to buy 1/H shares of the stock (at $IIH). So the option . returns-of the fimancJa
potenttal · 1.denvattve. 1e
should be wo;th no more than $1/H. Yet if the option price C is less than $JIH routinely used by financial institutions: . of . ,_Df
~~~I: H ~ CH ~I), we can buy an option by borrowing C shares of the stock. The ~2j· Th t 0==- of ., Vega·. v == -:"I ; Rh o. p - VI~,
tmltal mvestmcn_t Js o_. Once the stock price hits $H, we will excise the option and retum M v
Delta: uA = VJ
as ; aG mma· • f = -
OS']. ; e a. 0

v~~ oa
the stock ~Y. ~uy1~g ( shares at price $JI, which gives payoff I- CH > 0. That means '~e
have n? mthal Investment yet we have possible positive future payoff, which 15
contn~dH:~ory to thl· no arbitrage argument. So the price cannot be less than $1 /H. HenCl~.
the pnc~ IS exactly $1 /H. Delta
. . . ld . D. =e '~ N(d, )
For a European call with dtvtdend yte y.
E. Assume a non-dividend paying stock follows a geometric Brownian motion. What is . . . ld . ~=-e- .r [J - N(dl)]
For a European put \\~th d1vtdend Y'e Y·
the value _of a contract that at maturity r puys the inverse of the stock price observed at
the maturrty?
. k'> How do
. n on a non-dtVI"dcnd paymg stoc
o 0

A. What is the delta of a European call opuo


•0
tl In~\\~~ r~cogm~c that. SIS a m~rtingale under the risk neutral measure. we tlo not nc~d the assumption d" "dend paving stock has a cl~an
0

you derive the delta?


. " • ·• · . o 0\\ ~ a g~:ometnc Brownian motion. S has two boundaritS for stor.pino · 0 and fl. The bounda~ 11 a non- tVt , • k b . tr ,i.ltlfl!'
Solution: The delta of a European. ca. onthough. many make the Jntsta e Y ~.: c
=
cunu 1t1on<; :.re 1 (CIJ o and /(// 1 1 U · 0 I . 1' ~· h H tS
"' · !ttn~ t •e martmgalc. the probabilily that it will ever reac es .
expresston: 6 = N( d 1). • For the denvatlon.·
p >. H • ( l - ,. I ' u- s -I ..j I' I I II ,

1.:19
148
Finance A Practical Guide To Quantitative Finance Interviews

N(d1) and N(d2 ) as constants in the call pricing fonnula c =SN ( d 1 ) - Ke-' r N(d~) arKJ
simply taking the partial derivative on S to yield N (d 1 ). The derivation step is actual~·
more complex than that since both N(d1) and N(c/2 ) are functions of S through dl and ...
:;=N(d1 )+Sx ~N(d1 ) - Ke-rr ~N(d1 ) . F , ....··..
0
= W days-
d 2 . So thecorrectpartialderivativeis 0.9
----- 1= 1 month ....··
.··.. ~
Take the partial derivative with respect to S for N(d1) and N(d ) 9:
0.8 1
I
.. •• • ... •• ,= 3 months .·
2
0.7
j_ N(d 1) = N '(d1)~d1 = - 1- e-i/1212 x l = 1 e - d,212
as as & sa.[; sa..J2;;
0.6 j
-·-·-·-·-·-·-·---·-·-·-·-·- ·- ·- ·- ·-.::·
j_N(d2) = N'(cl,)j_d2 =~e-dit2 x I = e (d,-uJi)l/2 .19
dj 0.5 ~ • .' I
• I •
as - as & saFr Scr../2Jrr 0
••
'
... I '
J I
i•
/ I
=
l
e- rl1: i2 ea../rd1e-c
2 rt2
= l e-u,z 12 x-e
S rr .'' II
S cr .J?:;; S cr.J2nr K ,•
.:
I
I
0.3 r .•
••
I
I

~N(d., )=§_errN(d1 )~Sx~N(d1 )-Ke-rr J_N(d,)=O.


,: I

So we have Hence, the 0.2 . ••• .· I '


as - K as as - :
.•
I
I

ac cancel out and -oc =N(d ). .··.• ,. I

last two components of- ...· .·· ;


,'
as as 1
0 •...
.... ....... ·· _,, ,"
95 100 105 110 115 120 125
75 80 85
Spot Price
B. What is your estimate of the delta of an at-thc-rnoney call on a stock without dividend?
What wil l happen to delta as the at-the-money option approaches maturity date? an call option with respect to S and
Figure 6.2 Variation of delta of a Europe
Solution: For an at-the-money European call, the stock price equals the strike price;. =
T. K 100. r= 0.05, a= 0.25.
S 1-' d (r + cr~ /2)r r cr r . F. re
=n.::o 1 = ..r;. -= (-+-)vr>O and 6 =N(d ) > 0.5. As shown lO •Jgu ~
.
European call opt Jon on
GM stock and dc~iuc
fUM t ·k
a r a 2 1
C You just entered a long posi~tion or a h ·sk from the fluctuation 1 s ol: °
6.2, all at-the-money call options indeed have t. > 0.5 and the longer the maturity, the to. dynamically hedge the position to your hedge. the price of GM u eli~in~t~/ a~t~~- ha~
price. How will you h~dge the c~ll op~JO~~r hedging position?
hight.:r the 6 . As T - 1 ~ o, (!_ + ~ )J.; ~ 0 ~ N(d 1
) = N(O) =0.5, which is also sudden increase, how WJll you rebalanc Y
(J -
shown in Figure 6.2 (T == lO days). The same argument is true for calls on stock with
continuous dividend rate y if r > y. · L'"''(dt ) is a monotonously
ln(S I K)+(r-y+cr 2 '' 2)r and 6 -= e -rr
Solution: Since d, = cr~
Figure 6.2 also s~ows that wh~n Sis large ( S >> K) 6 approaches 1. Furthermore, th.: st d i::)L\ i ·
shoner ;he matunty, lhe faster lhe delta approaches' 1. On the other halid. if S is small increasing function of d" we have -J r :\ ' ( 1) shares of stock :::::> '
6 hort 6 ::::o e lv c ' · ~ f GM
• £; which we s
(S << K ), approaches 0 an.d the shorter the maturity, the faster the delta approachesO. One hedging method is delta hedgmg, or ~ . delta-ncutr-dl. Since 6 s~are:s 0 . '
ke the portlo110
for ~ach unit of call optiOn t? GM option. we also need to mves1 -rr V(d._ ) for each
m;
· · cash (1f the option
d.
J - uJ"; => N'(d, ) = ~(/' 11: \"(/) iJd 1 _Od1 stock costs more than one umt 0
9
, ·e need to lend $Ke ' -
. K I , , ' ' ·-- . BI· k S holes fonnu 1a, w
oS oS pnce exactly follows the ac - c
ISO 151
Finance
A Practical Guide To Quantitative Finance Interviews
unit of option) in the money market. If there is a sudden increase in S , d , increases and
What happens to the ganuna of an at-the-money European option when it approaches its
6 increases as wel l. That means we need to shon more stock and lend more cash maturity?
( Ke_,., N(d2 ) also increases).
Solulion: From the put-cal{ parity, it is obvious that a call and a put with identical
The delta hedge only replicates the value and the slope of the option. To hedge the characteristics have the same gamma (since r =0 for both the cash position and the
curvature of the option, we will need to hedge gamma as welL underlying stock) . Taking the partial derivative of the 6 of a call option with respect to
N'(d 1)e- vr I - IIUr
S, we haver= .[; ' where N (d,) = ~ e
1
I.

D. Can you ~stimate the. vaJue of an at-the-money call on a non-dividend paying stock? Su r v2~
Assume the tnterest rate 1s low and the call has short maturity.
So for plain vanilla call and put options, gamma is alw~ys positive.
Solution: When S=K. we have c =S(N(d1 ) -e-'' N(d )). In a low-interest Figure 6.3 shows that gamma is high when options are at the money. w~ich is the stock
2
environment, r ~ 0 and e-rr~ I, soc~ S( N(d,) - N(d )). price region that 11 changes rapidly with S. If S << K or S >> K (deep 1n the money or
2

We also have N(d1) - N(d2 ) r·-


=
z/2;
1- e-lf2x
1
dx,
out of the money), ganuna approaches 0 since 6 stays constant at l or 0.
The gamma of options with shorter maturities approaches 0. much faster than options
with longer maturities as S moves away from K. So for deep m-the-money ~r deep out-
r a 1 r a of-the-money options longer maturity means higher gamma. In contrast, •f the stock
w here d 2 = (---)"1/ r and d, = (- +-)fr . prices are close to the,strike price (at the money) as the maturity nears, the slope of d~lta
a 2 a 2
for an at-the-money call becomes steeper and steeper. So for options close to the stnke
For a small r , a typical a for stocks (< 40% per year) and a short maturity (< 3 months). price, shorter-term options have higher gammas.
both d~ and d, are cl~se to 0. For example, if r = 0.03, a= 0.3, and r =l / 6 year. then As r ~ 0 an at-the-money catllput has r ~ co ( 6 becomes a step function). This can
d)= - 0.02 and e-l t"!.Ji =0.98. be show~ from the formula of gamma for a European call/put with no dividend,
r = N '(dl).
:. N(d)-
1 N(d ) -
2
I (d a.Jr
-12; ,-d1)=J2;-::::.0.4a.JT-t =::>c :::: 0.4aSfr. Sa../r ·

In practice, this approximation 1·s ·d b .. · ·d s


When = K , d I . (r
1lrn
= - +-(5) r
-.../1:-+
O ::> limN 1 (d)~-:]2;J . Thcnumcratoris 11-fi;;
J 2tr
volatility of th . usc Ysome volatthty traders to estimate the 1mphe r-+0 a 2 r->
(I

an a1- c-money opt1on.


. . .
yet the denominator has a hm1t hmS(5vT I 0
~ · so
r ~ 00· In other words, When I ':""" T.
(The approximation e- 112x 2 - r . ., . , r-+0 · .
. . _,.. - caust:s a small overestimation since e- 1-' 2·'·- < ,1: but the kes hedging at-the-money options
approxtmat1on -e · K ~ -K cau. delta becomes a step function. This phenomenon. ~a ,. .
opposi te etlects cane 1 d h:ses ~ small und~restimution. To some extent, the {\\'0 difficult when t -+ T since delta is e>.1remcly sensttlvc to changes 111 S.
e out an t e O\-crall app . . ~.
' rox•matlOn ~s .~.atrly accurate.)

Gamma

Fora Furopean eall/put with dividend yieldy: f= N '(d,)e-rr


S0 afr.
Finance
-
A Practical Guide To Quantitative Finance Interviews

N'(d,)~o. Hence, 8~-rKe-'' . When s~K ' e has large negative value and the
smaller the r' the more negative the 8.
Gamma of Call/Put Options
0.1
Theta of Call Options
0.09 1 --c= 10days I 0 r.-
..--~~-~-------~------
----- •= 1 month I .... ·~~..
,,
'
r
0.08
.......... •= 3 months ····........ ',',
0.07
-5 ··. ···.... ' ',
··.
··. \ \
0.06 ;
···\
-10 I \"•.
ro \ ··.
E \\ ··........~ ........ ..... .
E 0.051
ro
(.? -15.
I \ I
I

0 04 1 ,'
f
~
Q)
I
,' I .c
1-
--~~··· .... ......... j -20
0.03r ..···,, i.. .·.. i
. ·- ..
•••••• ·• II
0.02 • I t=10days
•••• •
..·
.•

,
I
I
-25 f r----- •= 1 month

: :L --.
0.01
.·· .· , /
.......... •= 3 months
0 I.. ·· __ ,,.
~~"

I.
75 80 85 95 100 10 5 110 115 120 125
Spot Price - -- ------L

75 80 85 90 95 100 105 110 115 120 125


Fi~ure 6.3 Variation of gamma of E .
=
K- 100, r 0.05, a:::: 0.25. a uropean call option with respect to sand T. Spot Price

Theta Figure 6.4 Variation of theta of a European call option with respect to Sand
T. K = 100, a= 0.25, r =0.05
For a European call option: 0 =_ SN '(d, )ae-yr
2~ + yS'e-yr N(d,) - rKe-'' N(d.;)
A. When will a European option have positive theta?
For a European put option: 0 = _ SN '(d,)ae-yr Soluli?n: For American options as well as European calls on non-dividend paying a:isds,
2~ - ySe- yr N(-d,)+rKe-~''N(-d1 ) ~heta IS always negative. But for deep in-the-money European puts. their valuts may
When there is no d' . mcrcase as t approaches T if all other factors remain the same. so they may haw positive
~·v '(d tvtdend, the theta for a E
0 ...:;-·· · ,)_rKc:-'' · ' . uropean call option is simplified to theta.
2J; ;\ (d2 ), Whtch is alwav · ·
S << K . (
N d2)-:::. 0 and V '(d ) _
"s negattvc. As shown in Figure 6.4. when
A put option on a non-dividend paying asset has e= SN 'ir)O' + rKe_,., N(- d2). If the
2 r
· ' - 0. Hence. 0 ~ 0· Wh en S>>K, N(d1 )~I and
put option is deep in-the-money ( S << K ), then N ' ( d1 ) ~ 0 and N ( - dl ) ~ l. lienee.

154 ISS
Finance
A Practical Guide To Quantitative Finance ln!erviews
0-:::: rKe-'' > 0. That 's also the reason why it can be optimal to exercise a deep in-the- smile for the Black-Scholes pricing model?
money American put before maturity.
For deep in-the-money European call options with high dividend yield. the thela can be Solution: Implied volatility is the volatility that makes the mod~l option price ~qual. to
positive as well. If a call option with high dividend yield is deep in-the-money ( S >> K }, the market option price. Volatility smile describes the relationshtp between the 1m~lted
volatility of the options and the strike prices for a given asset. For currency opll?ns,
N ( d,):::: N ( d 1 )-:::: I, N'( d1 )-:::: 0, so the component ySe-·\( N(d1 ) can make 0 positive.
implied volatilities tend to be higher for in-the-money and out-of-the-money. oph~ns
than for at-the-money options. For equity, volatility often decreases as the stnke pnce
B. You just entered a long position for a call option on GM and hedged the position by
increases (also called volatility skew). The Black-Scholes. ~odel assu_mes that .t~~ .~s.sct
price foll ows a lognormal distribution with constant ~~lati~tty. In reaht~, volatllllt~~ are
shorting GM shares to make the portfolio delta neutra I. ( f there is an immediate increase
neither constant nor deterministic. In fact, the volat1hty IS a stochastiC process ttself.
or decrease in GM's stock price, what will happen to the value of your portfolio? Is it an
arbitrage opportunity? Assume that GM does not pay dividends. Furthermore, there may be jumps in asset prices.

Solution: A position in the underlying asset has zero gamma. So the portfolio is delta- B. You have to price a European call option either with a constant vol~tility ~0% or by
neutral and long gamma. Therefore, either an immediate increase or decrease in the GM · "butiOn
drawing volatility from a random d1stn · Wit ~n1of 30o/c0 · Whtch optiOn would
· h a me_.
stock price wiJI increase the ponfoJio value. The convexity (positive gamma) enhances be more expensive?
returns when there is a large move in the stock price in either direction.
Solution: Many would simply argue that stochastic volatility ":'~kes_ the stock pril:c
Nevertheless, it is not an arbitrage opportunity. It is a trade-off between gamma and • IS . more va 1ua ble when the volatility ts drawn. fromf a
theta instead. From the Black-Scholes-Merton differential equation, the portfolio I" more volatile so the call pnce
'
random distribution. Mathematically, the underlytng · argume~ t. ·IS thatd the
. . pnce ,o·ulta
. fi h . av av t , oV
satJsJes t eequatton - +rS-+-a 2S·--=0+rS6+-a
2
t ..
2S·f =rV. Foradeta- European call option is a convex functiOn · of volatiltty
. an . . as a . is res!he
1
0/ as 2 as 2 2 c(E[aJ)~ E[c(a)], where a is the random variable representmg volat•hty and ' ·
2 2
neutral portfo lio, we have E>+.!.a S f =rV This indicates that gamma and theta often .
call option price. Is the underlymg argument correct.? Ies correct in , most.- but,.. not all
2 a·c cc .
have opposite signs. F~~ example. when an aHhe-money call approaches maturit~­ .
cases. If the call price c is always a convex functJon °
f a , then -aa
·- 2 2: 0. -()a 1s the
gamma . ~ large and pos1t1ve, so theta is large and negative. Our delta neutral portfolio
1

has POSitive .gamm~ and negative theta. That means if the price does not move. the Vega of the option. For a European call option,
passag~ of time wtll result in a lower portfolio value unless we rebalance. So the
ponfoho does not provide an arbitrage opportunity.

Vega
a2ci·s called Volg,a. for a European call option,
The secondary partial derivative -::;---2
for European options: u =~ = ep :: Se-Fr frN'( 1)
0 <7

C(J 00" 'I 2


s~
2oc -- - e x p(-d2 12) -d,d1
--- u dld2 .
At-the_-mon~y options are most sensitive
than e1 ther m-th~-mo 1p)· 0
to volatility change so they have hioher vegas
. ' . 0
oa ~ 1
a a
1 t' 1 e
. ~.: : r ou -o -t 1e-money opt1ons. The vegas of all opttons decreas . ne call options. both d, and d7 art:
as ttme to expiration becomes h ( r . · · re u Is always positive. For most out·of-the-mo Y .. , S dd > 0
. . . to change .n volatility.
sens1t1ve . s Orter v r -+ 0) smce a Long-term opt1on JS mo . . both d 1 and d2 are postll\ c. . o ' ~
1 negattve; for most in-the-money ca ll opttons, th ticallv we can
.111 n1ost cases and c is a convex functton
. of a when dd, ' - > 0. But eore -.

A. Explain implied volatility and volatility smile. What is the implication of volatility
a2 c: 0 when the option is close to hcing
have conditions that d , > 0 and d 2 < 0 and oa1 <
156
157
Finam·c- A Practical Guide To Qu~~ntitative Finance lnlcn•il'ws

at-the-money. So the function is not always convex. In those cases, the option with should also have a good understanding of pricing and hedging of some of the commnn
constant volatility may have a higher value. exotic derivatives- binary option, barrier option. Asian option, chooser option, etc.

C. The Black-Scholes formula for non-dividend paying stocks assumes that the stock Bull spread
follows a geometric Brownian motion. Now assume that you don ' t know the stochastic
prOl:\.!ss followed by the stock price, but you have the European call prjces fo r all What are the price boundaries for a bull call spread?
(continuous) strike prices K. Can you detennine the risk-neutral probability density
function of the stock price at timeT? Solution: A bull call spread is a portfolio with two options: long a call c, with strike Kl
and short a call c2 with strike K1 (K, < K 2). The cash flow of a bull spread is
Solution: The payoff a European call at its maturity date is Max(S.r - K , 0). Therefore

under risk-neutral measure, we have c = e_,, r (s - K)j, (s)ds, where


7
f,. (s) is the
1
summarized in table 6.3.

Cash flow TimeO


Maturity T
probability density function of S, under the risk-neutral probability measure. Taking tht'
Sr ::; K 1 K, < S.r < Kl s7" ~ K2
first and second derivatives of c with respect to K,10 we have

;~ - f! a~ r (s- K)/.;, (s)ds


Long c1

Short c2
-c,

c2
0

0
Sr-Kl
0
Sr-K1

-(S. K~ )
-rr r a(s- K) r
=e JK DK ~s. (s)ds-e-'r(K-K)x l Total c2 -c, < 0 0 Sr -K~ K2-KI

=~ - r- f ._, (s)ds Table 6.3 Cash flows of a bull call spread.

and -r·c - - (j ( -ac


tK l aK cK ; -
I . r: r f. (s
- e-'· cK '!\ - s,
)d
s =e-rr f ..., (K ) .
Since K < K
I 2,
bounded by K - K
the initial cash flow is negative. Considering that
the price of the spread, c, - c1,
.
JS
the

bounded b) e
,
final payofT is
_,, ( K - K ).
' ·1
2 "
Besides, the payoff is also bounded by K2 - Kl Sp so the price is nlso bounded by
Hence the risk-neutral probability density function is f.. (K) = e'' fi e., . K2
~, o}(-

6.3. Option Portfolios and Exotic Options


:~. addi.tio~ to lhL· pri\:ing an_d_ prop~rties of vanilla European and American options. you Straddle
__ a)_ b~.: expect~d to he f<lmliJar wnh the construction and payoff of basic option-based
'.'·~.dtng stratcg.H~s-co,·cT~d call. protective put, bull/bear spread, butterfly spre-ad. Explain what a straddle is and when you want to purchase a straddle.
stradd le. etc J·urthl:mlorc it·,. · ·· ·ou
· • . ou are upp1ymg for a derivatives-related pos1t10n. Y· .. . bo h . II option and a put option with
Solwion: A straddle includes long posttiOns 10 1 a ca k Th ayoff of a long
the same strike price K and maturity date Ton the same stoc · to~kp rice moves. In
It
I o ~.:.alcuktl.:: the d~\ tJvcs r , · 1 · · d f ·t · straddle is I Sr - K I. So a straddle may be used to bet on large s p I "J't , Jf an
int~gml "ho~< lint its - ~:{lUI~~ lle LctbOJ7. in1egral mle, a fonnula for differentiating a e 10' t . . fi0 r making bets on vo att I ~ .
• :- .m~ uncttons olthe differential variable:
1 ~racttcc, a straddle is also used as a tradmg strate.gy ld b much higher than the
I
- - f.' • 1 , • (' ·o r"~'f(···-
,. -) oh
?- dx -F { (bt ; ) . .:)- - /(a(:),.:)~
~
Investor believes that the realized (future) volahhty shou
·•mplted
· volatility of call and put opttons,
.
e t , ddle for ~xample,
t"t: ,, , ( ·-)d.r •: he or shc Wt'll Purchasc as ra ·
. ~ ~

158
Finance A Practical Guide To Quantitative Finance Interviews
12
the value of an at-the-money call or put is almost a linear function of volatility. If the and the stock price S is close to K, 6 is extremely volatile and small changes in the
investor purchases an at-the-money straddle, both the call and the put options have the stock price cause very large changes in 6 . In these cases, it is practically impossible to
price c:::::; p : : :; 0.4a,S.Jr, where a, is the implied vo latility. lf the reahzed volatility hedge a cash-or-nothing call option by delta hedging.
ar >a,, both options are undervalued. When the market prices converge to the prices We can also approximate a digital option using a bull spread with two calls. If call
with th.e realized volatility, both the call and the put will become more valuable. options are availabl e for all strike prices and there are no transacti?n cost.s, we ~an lo_ng
l I 2£ call options with strike price K - & and short 112£ call opttons with stnke pw.:c
Although initially a straddle with an at-the-money call and an at-the-money put ( K = S ) K + £ . The payoff of the bull spread is the same as the digital call option if Sr. $ K -£
has a delta close to 0, as the stock price moves away from the strike price, the delta is no
(both have payoff 0) or Sr ;:::. K + & (both have payoff $1 ). When K- £ < S.r < K + & ,
longer close to 0 and the investor is exposed to stock price movements. So a straddle is
not a pure bet on stock volatility. For a pure bet on volatility, it is better to use volatility their payoffs are different. Nevertheless, if we set £ -4 0, such a strategy will exactly
11
swaps or variance swaps. For example, a variance swap pays N x (u; - Kvar ), where.\' replicate the digital call. So it provides another way of hedging a ~igital. call option. Th.is
hedging strategy suffers its own drawback. In practice, not all strtke pnces are trade~ 10
is the notional value, a; is the realized variance and Kvw is the strike for the variance. the market. Even if aU strike prices were traded in the market, the number of opttons
needed for hedging, 1/2&, will be large in order to keep £ small.
Binary options
\~h.at is the ~rice of a ~inary (cash-0~-nothing digital) Europeim call option on a non- Exchange options
diVIdend paymg stock 1f the stock pnce follows a geometric Brownian motion? Ho" How would you price an exchange call option that pays max (S J .t - S7.2 • 0) at maturity.
would you hedge a cash·or-nothing call option and what's the limitatior1 of your hedging
strategy? Assume that S and S are non-dividend paying stocks and both follow geometric
1 2
Brownian motions with correlation p .
Svlulion: A ~ash-~r-nothing call option with strike price K pays $1 if the asset price is
abo.ve '.he Strtk~'~nce at .the maturity date, otherwise it pays nothing. The price of the Solution: The solution to this problem uses change of numeroire. Nu~eraire t~e~ns.:·;
0 1100 unit of measurement. When we express the price of an asset, we u.sua ly use d'cfr.,ocant
P IS Cu = e N (d2) rf the underlying asset is a non·dividend paying stock. As we . es it is often cas1er to usc a 1 1cre
currency as the numeraire. But for roo de1mg purpos ' . . h 1·t · .1 alwws be
have discu_ssed in the derivation of the Black·Scholes formula, N(d2) is the probabilit} asset as the numeraire. The only requirement for a numcralre IS 1 at mus ''
thar a vanilla call option fin.sh
1 es m· t he money under the n.sk-neutral measure. So ·tts.
. positive.
dtscounted value is e-n N(d 2 ). I S (price of S1 at maturity dateD
The payoff of the exchange option depends on bo t 1 1".1 • • .•

Theoretically, a cash-or-nothin~ call option can be hedged using the standard delta d , geometric Browman motJOn~.
and s ./.2 (price of s?. at 1), so it appears that we nee t\H)
h d . cc I
e grng strategy. Since 6 = ~=e-n N '(d ) a long position in a cash-or·
cS 2 SaJ; , ciS, = f.l1S1dt + a,S,dW,,~
nothing call option can be hedooed bY s1lOrtmg
· e_,., N·,( d, ) ·
shares (and a nsk-free dS2 = Jt1 S2dt + 0"2 S 2dW,.2 •
. th ~ rob tern to just on~ gcometnc
money market position) Stch h·d , . - SaJ'! K'
is large and · . · ' 1 a e gc works well when the d1fference between Sand
' 1s not c 1ose
· to 0 · But\\"))
. en th e optton
· · ·
ts approaching matunty T ( r - ~ 0) . ' .
Yet if we use S as the nwneraire, we can convert e P
. ( _ · o) =S (s~ J ol
max - - 1. 1·
Wh
en
Browman motion. The final payoff IS max s1 .~ 8r.r ' rI s,, /

"
)J; -+ o=> o -+ ~~~ '"L .
•• l·or dctailt-d discussion aboul volatili sw ed
ro Know about Volatilit\ S"aps'' t> . Kty. ~ps. please refer to the paper ''More Than You Ever wanr " -r:::: · r
be approximated by a po,rtfolt'o 01• } ddresl 1111 1 ~ Demererfi. el al. Th~ paper shows that a variance swap can - s~K and r-+O=>In(S / K)-+O ~ d: -)(r / u+ 0·5a "2tr Su"r
s1ra es· With propc.;r ~
we1g· 1liS ·mversdy proportional to 1/k-.'
!61
160
Finance
A Practical Guide To Quantitative Finance Inte rview~
Sl and S 2 are geometrical Browian motions, 1 =~2 is a geometric Brownian motion as
I
6.4. Other Finance Questions
well. One intuitive e:-<planation is that both Jn S1 and In S2 follow nom1al distributions. Besides option pricing problems, a variety of other quantitative finance problems are
so In f =In S2 -In Sl follows a nonnal distribution as well and 1 follows a lognormal tested in quantitative interviews as welL Many of these problems tend to be position-
specific. For example, if you are applying for a risk management job, prepare to answer
distribution. More rigorously, we can apply the Ito's lemma to I= s2: questions about VaR; for fixed-income jobs, get ready to answer questions about interest
sl rate models. As 1 explained in Chapter I, it always helps if you grasp the basic
rv _ -s~ of =J_ ci.f _ 2S2 elf rl 1 _, knowledge before the interview. In this section, we use several examples to show some
,wl s::. 'cs s 'as 2- s3}as 2 = 0• aSoS =-s2
1 2 1 , , 2 I
typical interview problems.
1 1

df = !, dS, + :, dS, + i:;;,( dS, )' + ±:;;,( dS, )' + ~~~' dS,dS, Portfolio optimization
You are constructing a simple portfolio using two stocks A and B. Both have the same
_ s2 d s2 s s s expected return of 12%. The standard deviation of A's return is 20% and the ~tandard
- -p~ S t-a~ SdH~.J +112 S2 dt +a'l-idW 2 + a 2-l.dt- pa a S2 dt
I I I sl t, J s l I 2 s deviation of B's return is 30%; the correlation of their returns is 50%. How wiJJ you
=(,u1- f.'l + al2- pala2) fdt - a I. fdW1.1 +a2fiU~Aw, l I allocate your investment between these two stocks to minimize the risk of you r portfolio?
Solution: Portfolio optimization has always been a crucial topic for investment
= (P2- f.JI + a ,Z - pa,a!)fdt + )al2- 2pa a +
I 1
~1 x fiaW
l · t ,.l
management firms. Harry Markowitz's mean-variance portfolio theory is by far the most
well-known and well-studied portfolio optjmization model. The essence of the mean-
To make f = S2
S1
a martingale set
' fl1
_ 2
/-11 + <7, - pa1a2 =0 and we have E ___!_:3_ =-S1 • [S ] variance portfolio theory assumes that investors prefer (l) higher expected rct11ms for a
given level of standard deviation/variance and (2) lower standard deviations/variances
s s,,l s. for a given level of expected return. Portfolios that provide the minimum standard
and s'.2 is a martingale under the new tn deviation for a given expected return arc termed efficient portfolios. The expected return
•.I easure. The value of the exchange option using and the variance of a portfolio with N assets can be expressed as

Sl as the numeraire is c. == i:[max[ST.l _


· s~·. , I, 0
JlJ . . . wh1ch ts JUSt the value of a call opuon
. J.lp::: Wlfll

N
+ W2J.i2 + ... + WNflN ::: WT fJ

var(r,) =""a~w 2
~ I) w w1 = w
~ I I +""a
1
Lw
with undedying asset price s = sl "k . . te l ; ... /
I

s ' strr e pnce K =1. Interest rate r = 0 and volatilit)'


I ' where wi' 'Vi= I, ... , N, is the weight of the i-th asset in the portfolio; P,, 't::li = I,· ... N, is

C.,. =Ss2- N(dI ) - N(d~ ) , where


the expected return of the i-th asset; cr,2 is the variance of i·th usset's return;
I a'J = Ptj cr.a is the covariance of the returns of the i-th and the j-th assets and P" is their
I j

correlation; w is an N x 1 column vector of w, 's; J.1 is an N xI column vector of Jt, 's;


of the exchange option
L is the covariance matrix of the returns of N assets, an N x N matrix.
.
SJnce . .
the optimal portfolio mimm1zes ·
the vanancc of tf lC 1·eturn. for a. given. level
. .
of
expected return, the efficient portfolio. can be fiormu 1ated as the followmuo optllllll.aUon
problem:
Finance
A Practical Guide To Quantitalive Finance Interviews
min wrLw
Mathematically, it is simply the (negative) first or fifth percentile of the profit
,. ". 1 1. , where e is an N x 1 vector w)th all elements equal to 1 13
., 1 w p=f.i" , w e= i · distribution.
As a percentile-based measure on the profit distribution, VaR does not depend on the
For this specific problem, the expected returns are 12% for both stocks. So J.l, ·1s a1wavs
shape of the tails before (and after) probability J-a, so it does not describe the loss on
12% no matter what w,.. and wH ( w..~ + W 11 =l) are. The variance of the portfolio is • the left tail. When the profit/loss distribution is far from a normal distribution, as in the
cases of many derivatives, the tail portion has a large impact on the risk, and VaR often
var(rl' ) =a~w~ + a~w! + 2pA.naAO'HwAwH does not reflect the real risk. 15 For example, let's consider a short position in a credit
A A + aH2(1 -wA )2 + 2P.. . a,,a wA( I-wA)
--alw2 18 11
default swap. The underlying asset is bond A with a $1M notional value. Further assume
that A has a 3% default probability and the loss given default js 100% (no recovery).
Taking the derivative of var(r,) with respect to wA and setting it to zero, we have Clearly we are facing the credit risk of bond A. Yet if we use 95% confidence level,
VaR(A) =0 since the probability of default is less than 5%.
ovar(r )
':l..., " =2a:,wA- 2a~(l -w,.~)+2pA ' Ha..,aH(I-wA )-2pA.8 a,.....
U\1 A Av H A
w =0 Furtheonore, VaR is not sub-additive and is not a coherent measure of risk , which
l
means that when we combine two positions A and B to fonn a portfolio C. we do not
=:> w _ ... a , - p :1.11 O'a
.I H _
0.09-0.5x0.2x0.3 6 always have VaR(C) ~ VaR(A) + VaR(B). For example, if we add a short position in a
a ~- 2P,,./Ia,.: a/l+a;- 0.04-2x0.5 x 0.2x0.3+0.09 =7. credit default swap on bond B with a $1M notional value. B also has a 3% default
probability independent of A and the loss given default is I00%. Again we ha~e
So we should invest 617 of the money in stock A and J/7 in stock B. VaR(B) = 0. When A and B fonn a portfolio C, the probability that at least one bond wtll
default becomes 1-(l-3%)(l-3%)z5.9%. So VaR(C)= $1M >VaR(A)+VaR(B).
Value at risk Lack of sub-additivity directly contradicts the intuiti ve idea that diversification reduces
risk. So it is a theoretical drawback ofVaR.
Briefly expJain what VaR is. What is I . .
the risk of derivatives? t le potenttal drawback of usmg VaR to measure (Sub-additivity is one property of a coherent risk measure. A risk measure p(X) is
Solwion: Value at Risk (VaR) d 1 considered coherent if the following conditions holds: p(X + }') ~ p(X) + p(Y);
two important aspects of risk an s ress test--or more general scenario analysis--a~ p(aX)=ap(X), \ta>O; p(X)~p(Y), if X~Y; and p(X+k)=p(X) - k for ~ny
V R. management In the F: . l R' k AA d'b k II
a IS defined as the followin . y AR . · . mancra 1s !"''anuger Han oo . constant k. It is defined in Coherent Measure of Risk by Artzner, P., ct al., MathemallcaJ
that there is a low, pre-specifieJ· b b. ~ the maximum loss over a target horizon such
1
Finance, 9 (3):203-228. Conditional VaR is a coherent risk measure.)
G. pro a dlty that the actual loss will be larger.
tven a confidence level a e (0 J) h
f ' · t e VaR can be implicitly defined as
a = 1,.,,(xf(x)dx, where x is the dollar fi . . .. . Duration and convexity
A . pro It Ooss) and f(x) IS tts probabilrty dcilStty
. unctton. In practice, a is often set to 95o/,0 l o . • • 1 dP h p · th. price of the bond andy
1n financial ri sk managcml:nt . , • . or 9.9Yo. VaR Is an extremely popular ch01Cc.: T he duration of a bond is defined as D =- p dy , w ere 15 c
5tnce It summ 'trtZ" tJ • k to a stngle
.
< es te ns dollar number. l d! I' .
is yield to maturity. The convexity of a bond is defined as C = p d.t ' · Applymg
u The (·. - Jl,. 8
r.o
optimal weights have closed 11 I .
rm so Ut1on I
. e + yr 1p , where ..<
w• "' . u:
6P
Tay l or•s expansion, 1:1P 1 , h A is small -:::: -D~y.
u. f - 8 D
== _ _....._
pz - Dlly+2C fly-. w en uy : p
r= 8- . . ,--!
. A= e 'I:-'e>O .
l-1 • D . - ,. .. J.l. (_ :::. p 'l IJ.J > 0, D == AC- 8 1
For a fixed-rate bond with coupon rate c and time-to-maturity T:
Fmancial Risk Manu"er Handb k b .
f ·· " Y Philr J .· ·
aspects o n,~ m:ut;•gcm~:nt. A classic book f, v'PPe. Ollon IS a comprehensive book covering diiTcrent
(I(;

or aRtS Value at Ntsk, ' also by Philippe Jorion. Iss . v R b · ating the Jail risk.
tress test rs often used as a complement to a Y es11111
164 165
Finance
- A Practical Guide To Quantitative Finance Interview~

Ti~Di ci=>D-l- yi=>D-l- Ti:::> Ct ci=> C-i yi=>C-l-. Cash flow Year 0 Year 0.5 ... Year 4.5 I Year 5 J
1
dP
Another important concepl is dollar duration: $D = - - = Px D. Many market
dy
Short 3 fl oating-
rate bonds
300 -150~ ... -lSOr, -300-ISOr,
\
participants use a concept called DVOI : DVO I = dP , which measures the Long 4 bonds with 15 ... \5 400 +I 5
-400
1O,OOOx dy 7.5% coupon rate
price change when the yield changes by one basis point. For some bond derivative_s, 30 - 3001;, 115-ISOr,
Total -100 15 -ISOr. ... J
such as swaps, dollar duration is especially important. A swap may have value P = 0, m •
which case dollar durat ion is more meaningful than duration.
. . the same as the dollar duration of the
When n bonds wi th values P,, i =I , ··· , n} and Durations D; (co nvexities C; ) form a The dollar duration of the mverse floater t$s D Since the yield curve is flat.
portfolio. the dura tion of the portfolio is the value-weigh ted average of the d urations of ~ )' e\J · $D =4x$D .,-3x fifK•''''s: ' . ,
port10 10 as w · "''w'" fu·'. · worth $lO}
75 (after the payment of
n p n p n
the compo nents: D = I . . . !. . D, ( C =
t= l p
L......!...C,
p
' '· I
), where P = L _r:. The dollar duration of
1•1
'o = 7.5% and the floating-rate bond IS. always 0 5 .nd the dollar durationl 6 is
$3.75, the price of the floating-rate bond ts $1 00) at year . 'a
II

the portfolio is simply the sum of the dollar durations of the components: $D = l:)D,. d(103 .75 /(1 + y/2)) 103.75 =lOOx O.S -= 48.19.
t ool
$Djloa11ng =- dy =0.5x(l+ y/2)1 1+y l2

100 2r c12
where T is the maturity
What are the price and duration of an inverse floater with face value $I 00 and annual The price of a fixed-rate bond is P = ~ (1+ y /2)' + (l + y 12)u '
coupon rate 30%- Jr that matures in 5 years? Assume that the coupons are paid
semiannually and the current yield curve is flat at 7.5%.
. f h fixed-rate bond is
of the bond. So the dollar duratlOn t e 1' °
Solulion: The key to solving basic fixed-income problems is cash flow replication. To $Dfl.ted =
dP (2' t 1
-d = 1 + y/2 ~ 2 (I+
c/2 lOOT -)= 410.64.
y/2)' + (1 + yl2)u .
price a fixed-income security \-vith exotic .structures. if we ca n replicate its cash flo\v
y - 1498 and the duration of the inverse floater tS
using a portfolio of fundamental hond types such as fixed-rate coupon bonds (incl uding So $D1 = 4 x$Dfi.,h"- 3 x$D1t...t~ms -
nv(J.n:~ "'
zero-coupon bonds) and floating-rate bonds, no-arbitrage arguments give us the
foiJowing conclusions:
Price of the exotic security = Price of the replicatin g portfo lio
Dollar duration of the exotic security~ Dollar duration of the replicating portfolio
To rep~icate the described inverse floater. we can use a portfolio constructed by shorting Forward and futures , h 'cc of the underlying as~~~
3 floatmg rate bonds, which is worth $100 each, and longing 4 fixed-rate bonds with a d forwards? It t e pn ·t ··h·tstlc
What's the difference between futures.an and the interest rates are soc • ~ ·
7. 5o/~ annual coup?n r~tc, which is worth $100 each as well. The coupon rate of a d . th tnterest rates,
is strongly positively correlate wt r , rds? Whv?
n oatt~g-~ate bond. ts adJ usted every 0.5 years payable in arrear: the coupon rate paid at · f t es or lorwa · "
which one has higher pnce: u ur . d tracts· f(jrw:.ml
1 + O.:>y ts determmed at 1. The cash flows of both positions and the whole portfolio arc standardszc con ·· .~
summarized in the following table. It is apparent that the total cash flows of the portfolio exchange-traded 'bl · Futures ~ontntct~
Solwion: Futures contracts ar: ents so they are more tlcxt e. e contract n:nn.
are the same as tl1e described inverse floater. So the price of the inverse float is the price contracts are over-the-counter agreem ct , are settled at the end of th
of the replicating portfolio: P.... Y'\1 . ; $100. ~ wards conta s
are marked-to-market da1··-Y,. .or

coupon bond.
. fa six-lllonth zer(•
16 • • nd is the same as the duration o
The initial duration of a tloatmg rate bo 167
A Practical Guide To Quantitative Finance Interviews
Finance

If the interest rate is deterministic, futures and forwards have the same theoretical price: The Cox-Ingersoll-Ross model keeps the mean-reversion property of the. Vasicek modeL
F = Set r+u- ylr. where u represents all the storage costs and y represents di vidend yield But the diffusion rate a~R(u ) addresses the drawback of Vastcek model by
for investment assets, convenience yield for commodities and foreign risk-free interest guaranteeing that the short rate is positive.
rate for foreign currencies.
No-arbitrage short~rate models
The mark-to-market property of futures makes their values differ from forwards when
interest ra tes vary unpred ictably (as they do in the real world). As the life of a futures Ho-Lee model : dr = B(t)dt +adz
contract increases, the differences between forward and fu tures contracts may become The Ho-Lee model is the simplest no-arbi trage short-rate model where B(t) is a time-
significant. If the futures price is positively correlated with the interest rate, the dependent drift. B(t) is adjusted to make the model match the current rate curve.
increases of the futures price tend to occur the same time when interest rate is high.
Because of the mark-to-market feature, the investor who longs the futures has an Hull-\Vhite model : dR(t) =a (b(l) - R(t) )dt + adW(I)
immediate profi t that can be reinvested at a higher rate. The loss tends to occur vvhen the . '\ t the Vasicek model. The difference is
interest rate is low so that it can be financed at a low rate. So a futures contract is more The Hull·White model has a st~cture. Slffit ~ul~-Wl ' te model to make it fit the current
Vtl luable than the forward when its value is positively correlated with interest rates and that b(t) is a time-dependent vanable m the lt
the futures price should be higher. term stmcture.

Interest rate models


Explain some of the basic interest rate models and their differences.

Solution: In general, interest rate models can be Sl!parated into two categories: short-rate
models and forward-rate models. The short-rate models describe the evolution of the
instantaneous interest rate R(t) as stochastic processes, and the forward rate models
(e.g .. the one- or two- factor Heath-Jarrow-Morton model) capture the dynamics of the
wh?le forward rate curve. A different classification separates interest rate models into
arbttrage- frce models and equilibrium models. Arbitrage.free models take the current
term structure-construc~~d from most liquid bond s-- and are arbitrage-free with respect
to the Cl.trrent market pnccs of bonds. Equilibrium models, on the other hand, do not
necessanly match the current term structure.
Some of the simplest short-rate models are the Vasicek model, the Cox-l ngcrsoll~Ross
model. the Ho-L~.·~ model, and the Hull~ White model.
Equilibrium short-rate models

Vasicek modd: c/R(l) == a(b- R(f))dt + aclW(I)

Wh~n R(t) >b. the drill rate is negative~ when R(t ) <h. the drift rate is positive. So the
VJ~Jcck !no<.ld has the desirable properly of mean-reverting towards lono-tcrm averag~
b. ~~~~~nth Wt~stant volatility. tl1<.· intcrl!st rate has positive probabilitv ofbcing negative.
whtch JS undc~mable. "

J
Cox-! n~~rsoii-Ross model: c/R(t ) :: a (h - R(t)) ctt +a R(u) dW (I)

169
Chapter 7 Algorithms and Numerical Methods
Although the percentage of time that a quant spends on programming varies with the job
functi on (e.g., quant analyst/researcher versus quant developer) and firm culture, a
typical quant generally devotes part of his or her time to implementing models through
programming. l11erefore, programming skill test is often an inherent part of the
quantitative interview.
To a great extent, the programming problems asked in quantitative interviews are similar
to those asked in technology interviews. Not surprisingly, many of these problems arc
platform- or language-specific. Although C++ and Java still dominate the market. we've
seen a growing diversification to otherprogramining languages such as Matlab. SAS. S-
~L~~..and R. Since there are many existing books and wehsites dedicated to technology
interviews, thi s chapter will not give a comprehensive review of programming problems.
Instead, it discusses some algorithm problems and numerical methods that are favorit~:
topics of quantitative interviews.

7. 1. Algorithms
In programming, the analysis of algorithm complexity often uses asymptotic analysis
that ignores machine~dependent constants and studies the running time T(n) -the
number s> f primitive operations such as addition, multiplication, and comparison-as the
number o{lnputs n -... oo. 1
Three of the most important notations in algorithm complexity arc big- 0 notation, !2
notation and e notation:
0 ( g(n)) = {f (n) : there exist positive constants c and 11<1 such that 0 5 /( n) 5 c~ ( n) f(lr
all n ;;:: n0 }. It is the asymptotic upper bound of f(n) .
.O(g(n)) = { /(n): there exist positive constants c and nu such that 0 5 c:g(n) ~ /"(n) tiu·

all n ~ n0 }. It is the asymptotic lower bound of f(n ).


0(g(n) ) = { f(n) : there exist positive constants ' •· "2· and n . sw.:h llmt
c,g(n) s f(n ) s c g(n) for all n ~ 170 } . It is the asymptotic tight hound of f(n).
2

Bcs .tdes notations, it is also important to exp1am


·
two concc
pts in ahwrithm comph:xi tv:
~ ·

1 • d .. ltu:tiull IIJ Alxorithm" hy Thuma~ I I.


If You want to review basic algorithms, I h1ghly rccom~~n 111 ~101
Connen Charles E Leiserson Ronald L. Rivest and Chflord Stem. 1 1 C~\ers
• _ all the thcorics di:)CU)o.'\cd in

1h·IS section
' and includes
· many' algorithms
. frequently appeanng
· 10
· rn· terv1cws ·
p ..

Algorithms and Numerical Methods


- A Practical Guide To Quantitative Finance Interviews

Worst-case running tim e W(n): an upper bound on the running time for any n inputs. · ch · store the sum of i and 1· first, then extract i's value and assign
mat hemat1c approa 15 10 . • · h [! 11 ·
it to j and fina lly assign j's value to i. The implementatiOn IS shown m t e o owmg
Average-case running time A(n): the expected running time if the n inputs are
code?
randomly selected.
~, .. : l! SW 'j-
' : ... &i '-..-
1 &j ) {
For maoy algorithms, W(n) and A(n) have the same O(g(n)) . But as we will discuss i i + j ; -- (~ lid j

in some problems, they may well be different and their relative importance often - ;, ... n.s .. --;·~ - ·~ lu
j = i j i .1 t:J
depends on the specific problem at hand. vol ~ l
i i - j ; ! I
: 'I n -:<: ~ l ) ' ::>

A problem with n inputs can often be split into a subproblems with n I b inputs in each
subproblem. This paradigm is commonly called divide-and-conquer. If it takes .f(n) l . . .
An altemative so \utton uses bitWise XOR (
") ·tion b taking advantage of the fact
unc y
~
primitive operations to divide the pro~lem into s_uhpr<?ble~.s and to merge the soluti~ns
that X 1\ X = Q and 0 " X = X:
of the subproblem$, the -running time can be expressed as a recurrence equatiOn
r(
T( 11 ) :-: t•T (nIb) ~ n ). where t J ~ l . h > I' _a~'.d I (~~)'Z. ~ :.. v ~ ic s wap(int &i , Lnt & j) {

i i " j ;
The master theorem is a valuable tool in fincliru.l, the tight bound for recurrence (j
i; j/ ; i
.
..:quatron T(n) : := aT(n l b)+f(n): If f (n)=O (flog.
~1 1~'
€) for some constant&> 0· j j A

. ;· ' j
1 i i A
j ; I .I ' .....
T(n ) =-
. .
e(
nlog,a). since f(n) grows slower than n 11 ~··' . If f(n ) = 0 (nlog,o log" for
- . - .
n)
some k ~ 0, T(n) ....: nhl log ' ' n) , since f (n) and nlog.., a grow at similar rates~ If
1
e( 11

- - - ·- . - Unique eleme~t§.._~ , . the unique elements


f(n)=O(n t- "-: )for some constant £>0, and aj(n l b)~ cf(n) for some constant
10
. write some code to extract .
If you are given ~orted arr,ay. can yo~ . ll 1, J , ). J, 5, 5, 5, 9, 9, 9, 9}. the uruque
from the array? For exampte, tf the array 15 •
c < 1, T(n) .., 8(/(n)), since f(n) grows faster than n 10g ho .
elements should be (1, 3, 5, 9J. .~ , 1 \ ~ < Whenever
Let's use binary search to show the application of the master theorem. To find an rra ' with elements Go~ a, ... - a,,-1· . .
Solution: Let a be an n~element sorted a ) .. ·s different from sts
element in an array. if the numbers in the array are sor1ed (a, ~ 0 1 ~ ... ~a,), we can usc . the sorted array' Its va 1uc I .
we encounter a new element a, 10 ·ily extruct the umqut!
binary search: The algorithm starts with a If a = x the search stops. If U . this property we can eas
-''' ·!!' l•lllj ,
previous element ( a, -:t a,_J ). smg . he fol lowing function: 3
a., .• 1 > x, we only need to search a 1, ... >CtL 2 j· If a <x we only need to search . . C•+ 1s shown as t
II/ -1 ' 11I 1j S
elements. One implementation tn ( T .. r . ir.t. nJ I
al•• ~ IJ •· · · •a,· Each time we can reduce tho numb~r of elements to search by half after ... ~;mr I , t·,.... <c 1 .1 ;:-; !'J T > V·ect a.r<T > m.qu~ "" J '
ch i J
making one comparison. So we have a = l, b = 2, and f(n) =1. Hence. vec~ c r<T>vee; ' '
t I ... t~L ..,.,ed
l.l
!( n) =I:\ ( log, 1 o ) .
o n · log n and tht· bmary s~arch flas complexity 0(1ogn). vec .reserve l n) ; I rescrv•-t t
1

vec . pus h_ba c l< (a [OJ );


f or( -.l .-.= 1 ; '
~<n,
• -1 ~i 1
I l
Number swap . F thcr problem::;.. the alaorillunlt
10
arl!
2 some iotplementatsons. or o
How do you swap two integers. i and j , without using additional storage space? This chapter uses C++ to demonstrate . mmefld. though. as
described using pseudo codes. . . . . n for swapping two .mtegers· It rs not reco ·
Solwivn: Com~aris~n and swap are tht: basic operations for many algorithms. The most Th~ following is a one~line equrvalent tunctJo
~omr:non tcd111q~tc fur swap uses a temporary variable. which unfort unately is forbidden it lacks clarity. . . { i - =-j = ( i .. -j l - j ; I : . . n· unique and uniquc_copy.
•::~rJ swap l i r t &i l 11 &Jl
m th1s problem smcc thc t~mporary variable requires additional storage space. c\ simple :; I should point out that C ,_ STL has genera1a
lgorithms forthisbasrcopcrauo ·
173
Algorithms and Numerical Melhods

A Practical Guide To Quantitative Finance lntcrvic\\:.

vec. p~ ~ n_ t, L k(J/i' l ; purposes. Here let's discuss three such algoritluns: insertion sort. merge son rtnd 4uick
sort. - ~

c; Insertion sort: Insertion sort uses an incremental approach. Assume that we have sorted
subarray A[ l, ... , i-1 ). We insert element A, into the appropriate place in A[ I, ... , i-1 ].
which yields sorted subarray A[I, ... , i]. Starting with i =I and increases i step by step
Horn er's algo rithm to n, we will have a fully sorted array. For each ste~ the expected number of
c~mparisons is .i L'f and the worst-case number of compansonsls i. So we have
Write an algorithm to compute y=
Solwion: A nai"ve approach 1 1 h
Ll
'"0
+A x+ A
1 2x
2 +A '
3X
,
+ · · · + A,,x . A(n) = e[fi i•l
/2J =0(n
2
) e[i> J
and W(n) =
r=l }
2
= 0(n ).
.
1 1 1 ca cu ates eac component of the polynomial and adds them
up. w liC, takes O(n ) number of multipJjcations. We can use Horner's a!oorithm to Me rge sort: Merge sort uses the divide-and-conquer paradigm. It divides the arr<~y into
reduce the number of multi li · . 0
two subarrays each with n I 2 items and sorts each subarray. Unless the subarray is small
P cat1ons to O(n). The algonthm expresses the original
polynomial as y =((((Ax+ A )x A ) ) ) . enough (with no more than a few elements), the subarray is again divided for sorting.
" , _, + 11-1 x + ·· ·+ A2 x + A1 x + Ao and sequentmll: Finally, the sorted subarrays are merged to fonn a single sorted array.
calculate B, = A," B,,_, =B,x +A • • • B _ x +A
mu ltiplications. ,,_'1 ' o - 81 o· We have y = B0 with at most n The algorithm can be expressed as the foiJowing pseudocode:
mergesort(A, beginindex, endinde.x)

Moving average ifbeginindex < endindex


then centerindex - (beginindex + endindex)/2
Given a large array A of len th
an!>rh~r ;:un!:Y- contain in thg ~n,l can you de~elop an efficient algorithm to build merge 1 <- mergesort(A, begin index, centerindex)
( 81. .... B, ~ NA~ 8 = ( g e n e ement movmg average of the original array
~- ._ 1
, A,_,.I+A,~o-:,+···+A,)!n,'tli=n,···,m)? merge2 <- mergesort(A, centerindex + I, endindex)
Solwion: When we calculate th . merge( merge I, merge2)
• ~n reuse the previously com :t:v•ng ~verage of the next n c~nsecutive numbers. w~
The merge of two sorted arrays with n/2 elements each into one array ~ak\,;.·. (·)(nl
subtract the first number i11 tl p _movmg average. Just multtply that average by n.
have the new sum o1·v,·d· taht movmg average and then add the new numbcr.~1nd you primitive operations. The running time T(n) follows the following recursive lunctwn:
· mg t e new su b 11 · 1 ·
the pseudo-code for calcul 1. 0 , _m Y Yle ds the new moving average. Here JS
a Ill.-:- t1lc movJng average: T(n)={2T(n/2)+0(n), ~ n>I _
S== A[IJ + ... + A[n]; B[n) =S/n; 1, if n =1
for (i=·n l- 1 tom) { s- S . .
A.pplymg . a = 2· h -- 2· and ·/"(IJ) =0Uz). we have
- - A(J~n] + Afi]; B[i) == S/n; } the master theorem to T(n) wtth
/(n)==E>(n 10gba log0 n).
So T(n)=0(nlogn). For merge sort. A(n) and If('1) .m: the
Sorting algorithm
~me its T(n).
C'ould you . 1· . . - hod It choo~es ont· df the
cxp alll three sort ing al . I
anal) tc: th~ complexit , f h . gont uns to sort n distinct values A" .. -~ A, and Qurcksort: Quicksort is another recurs1ve sorting met · . h . Tho "JC'r rt.mts
· ) o eac algonthm? I
e ements, A, , from the sequence and compares a II 0 thcr values Wit 1t. s - .. .
. . _ e clements larger !ban .I an:
Solution: Soning is a fu d smaller than A are put in a subarrav to the left of A,· t1105
s~ • a~ental pr?cess tba.t is direct)v or indirectly implemented ill
11
111Cllly pmgrams. a . , . • . . h •n repeated on both subarray:.
vanet\ of sortrng al . h "' t Put m a subarray to the right of A, . The algonthm IS t e
· gont ms have hcen developed for differcn (and any subarrays from them) until all values are sorted.
174
17S
A Practical Guide To Quantitative Finance Interviews
Algorithms and Numerical Methods

ln the worst case, quicksort requires the same number of comparisons as the insertion running time is 0(n log n). For a sma II n, such as n =52 in a deck of C<Jrtls..ththe
sort. For example, if we always choose the first element in the array (subarray} and . . t ble For large n we may want to use a faster algon m
complextty E>(n logn) tS accep a . 1 A[,J] ... Afn) the Knuth shuffie uses the
compare all other elements with it, the worst case happens when A" .. ·, A, are already known as the Knuth shuffie. For n e ement.s ' , t '
sorted. In such cases, one of the subarray is empty and the other has n- 1 element. Each

step on Iy reduces the subarra y size by one. Hence, W (n) = 0 ( ti) =0( n 2 ).
following loop to generate a random pennutation:
for (i=l ton) swap(A[i], A[Random~._n~
- . . -
. . .
- - .. be from the discrete uniform distnbutlOn betv.·een
where Random(L n) 1s a random ~~ -r- -
.

To estimate the average-case running time, let's assume that the initial ordering js i and n. -- · I th . first
random so that each comparison is likely to be any pair of elements chosen from - l . f E>(n) and an intuitive interpretatiOn. n l: .
A1 , ···,A,.. If we suspect that the original sequence of elements has a certain pattern, we The Knuth shuffle has a camp exity o . . fb . h sen as the first card sinl;c the
d h al probability o emg c 0 .
step, each of the n car s as equ . niform distribution between l and n; m ~1le
can always randomly p\..'rmute the Sl!quence first with complexity 0 (n) a~_explained illl
card number is chosen from the dtscrete u d nts has equal probability of ht:mg
t~e nl!x't P!ohlcm. J...,et AP and A,, be the pth and qth element ( 1~ p < q ~ n ) in the final second step each of the remaining n - 1 car s e e~e
1
h ordered sequence has I In!
sorted array. There ar~ q- p + 1 numbers between Aq. The probability that A
AP and ,
chosen as the second card; and so on. So natura y eac
1 probability.
and A,, js compared is the probability that A, is compared with AP before A,,..,..... or
.-1•( 1 is compared with either Ap or A (otherwise /i and A are separated i.nto The characters in the file can be read
</ ' f' " B. You have a file consisting of characters. H do you pick a character so that
different subarrays and wilt not be compared), which happens with probability f h file 1 ·s1 unknown. ow
sequentially, but the length o t e b bTt of being chosen?
2 every character in the file has equal pro a 11
y .. . md character. we
P(p, q) - - -- (you can again use the symmetry argument to derive this probablity}. . h racter If there I S a sec( d
q - p+ I
Solution: Let's start with pickmg the ~.rst c a and ·replace the pick with the_ secon
keep the first characte r with probabJl~ty 1 ~ d haracter we keep the pick (trom the
The total expected number of comparison is A(n} = LL P(p, q) = LL _2 + 1~
11 q-1 II 11-l (
character with probability 112. If there IS a t tr cl the 'pick with the third character
1(= 2 , .... lj-1 , .... q p ) b .l 1.ty 2/3 and rep ace 1 other
= 0(nlgn). first two characters) with proba l . .
0 until the final character. n
with probability 1/3. The same process _Is coftnunu~. llave scanned n characters and tht:
h . pJck a er we
Although theor~t~cally, quick~rt can be slower than merge s<_?.rt if! the worst ca~ i~ is words let C be the character t at '"e n h bah1'1"1tV
often as fast as, tt· not taster than. merge so11. ' " . .. _ and t c pro •
T of keeping the ptck IS I
(n+ l)th character exists, the probabl It)' n+ . ,
. . . I ·tion. \VI: ~an ~•tstly
Random permutation h tcr
. S -I= . U<-ifl"
I "'
stmple muuc
of switching to the (n + 1)11I c arac n+ r
1:>
'f rc are 111 characters.
bTt of being chosen 1
t tlc
A. If you have a random number generator that can generate random numbers from prove that each character has 1I m proba 1 1 y
eithl!r di~crctc or continuous uniform distributions. how do you shuffle a deck of 52
caro~ ~o that C\'~ry pennmation is equally likely?
I f'i
Sol~ilivn: A simple algorithm to pl!rmute n elements is random permutation by sorting. II Search algorithm . . d the maximum of n numtX
b 0 th the tmmmum an
assJgns a random ~umber to each card and then sorts the cards in order of their assigned A. Develop an algorithm to find .,
randlllll nut~\bers. Ry. symmetry, cwry possible order (out of n! possible ordered ·
usmg no more than 3n/2 compans · · ons . ·
, . .. 1 compuns~n:, to idcnllh'
. . :,
sc::quc n~.:\.·s) 1
equally hkely. The complexity is detennincd by the sorting step, so the f numbers. tt takes n . kc~ at most Jn/-
'i
S~lution: f or ru1 unsorted array .0 ':n
of the array Howe~rer, •!_~~c- separate th~
euhcr the minimum or the maxJmU . . um and the ma~tmum . l!er one in group
J If "~. u~ _the. conu~ uous unit(1rm Ji:.tribution, tht:oretica llv any two random numbers havt: zero comparisons to identifY bo.!!!.. the truntmt' J·n each pair and put the 5013
rrohilhlllt) of bcmg C:lfU=ll. • ~ - . - compare
- the elemen s
e•cments to n/2 pairs, l77
Algorithms and Numerical Methods A Practical Guide To Quantitative Finance Interviews

A and the larger one in group B. This step takes n / 2 comparisons. Since the minimum the grid) or a k that makes A L.J < x < Ak+,,J and then we search left along the row k + 1
of the whole array must be in group A and the maximum must be in group B, we only A towards A
need to find the minimum in A and the maximum in 8, either of \.Vhich takes n 12 - 1
r.
trom t•l ,J k•'·' ··. Using this algorithm, the search takes at most 2n steps. So
comparisons. So the total number of comparisons is at most 3n/2. 5 its complexity is O(n).

B. You are given an array of numbers. From the beginning of the array to some position, Fibonacci numbers
all elements are zero~ after that position, all elements are nonzero. If you don't know the Consider the following C++ program for producing Fibonaccj numbers:
size of the array, how do you find the position of the first nonzero element?
int fiLi) nacci ' i nt n)
So!urion: We can start with the 1st element; if it is zero, we check the 2nd element; if the
i f (n <= V)
2nd element is zero, we check the 4th element. .. The process is repeated until the itb .. ••-1 L . 0i
1
step when the 2 /h element is nonzero. Then we check the ~~th element. If it is r ,__ ~' 1;
2 e ......
2' +2 1-1 retu . iibonacci(n - l}tFibonacc J n- 2'. .. 0 (

zero, the search range is limited to the elements between the th element and
2
the 2' th element; otherwise the search range is limited to the elements between the l ute Fibonacci(n). how long will it take
[f forsome lat:ge n, it .takes I00 seconds to comp d? Is this algorithm efficient? How
1 1 2' ..:..2' I to compute F1bonacct(n+ l ), to the nearest secon ·
2 - th element and the rh element. .. Each time, we cut the range by half. This
2 would you calculate Fibonacci numbers? .
method is basically a binary search. lf the first nonzero element is at position n, the . . efficient recursive method to calcu 1ate
algorithm complexity is 0(1og n). Solution: This C++ functiOn uses a rather ~ d . the following recurrence:
Fibonacci numbers. Fibonacci nwnbers are de Jne as
Fo:; 0, F; = 1, Fn = Fn-1+ F,_2, Vn ~ 2
C. You have a square grid of numbers. The numbers in each row increase from left to
right. T~e numbers in each column increase from top to bottom. Design an algorithm to . (l + .JS) - 1- "5
II ( {;)"
. which can be easily proven
find a g1ven number from the grid. What is the complexity of your algorithm? F, has closed-formed solutlOn F,, == 2., J5
Solution: Let A be an n x n matrix representing the grid of numbers and x be the number using induction. From the function, it is clear that
we want to find in the grid. Begin the search with the last column from top to b<2!.!2.!U:
A,_ , ... ·, A..... If the number is found, then stop the search. If A,, .• < x. x is not in the grid T(O) =1, T(J) =1, T(n) = T(n -I)+ T(n- 2) + 1. . bers as wdl. For a
f~ Fibonacci num · ·
S .
~ o the running time is a propertJ ona
1 to a sequence o
and the search stops as well. If A,... < x < A.. s... • then we know that all the numbers in c
rows 1,·.. · .i are less than x ;nd are eliminated as wcJI.0 Then we search the (i + l)th row n T(n +I) ~ J5 + 1. [f it takes I 00 seconds w comput
large n, (l-J5) ~ 0, so T( ) 2
from right to left. If the number is found in the (i + t)rh row, the search stops. rr n JS+! -16.,
'• , a > x, x is not in the grid since all the number in rows ; + 1 and above are 1arger than
· T(n + l):::--T(Il)- -
Fibonacci(n), the time to compute Fibonacci(n.... J) IS 1
x. If A , ~ x > tl,.,_, . we eliminate all the numbers in colunms j + J, .. ·,n. Then we
can search along column from A,.,_, towards A,,_, until we find x (or x does not exist in scconds.7

: ~hght adjust~ent needs to be made ifn is add. but the upper bound Jn/2 still applies. 7
1
can he 0, which means x < .4, . . in which case we can search the first row from right to left. rp "" ..[s + 1 is called the golden ratio.
2
179
178
a
Algorithms and Numerical Methods
A Practical Guide To Quantitative Finance Interviews

The recursive algorithm has exponential complexity e((~ JJ +


1
which is surely
A more efficient approach uses the divide-and-conquer paradigm. Let's define
I

T(i) = L,A[x] and T(O) = 0, then V(i,j) = T(j)- T(i- 1), V'l::;; i::;; j::;; n . Clearly for
inefficient. The reason is that it fails to eOective)y use the information from Fibonacci
an xcl
fixed j, when T(i -1) IS . . . •
_mmi!?Ized! . ·mized ·~ So
V(.ILl.}. ·IS maXJ . the maximum
numbers with smaller n in the Fibonacci number sequence. If we compute F , F;. ···,F,
in sequence using 1he definition, the running time has complexity G(n).
0 2.- .end.mg a t j . ·s) v·IYI:ll<. -- T(J.)- Tmon where Tffiltl. = min(T(l),- .. , T(J -I)). If• we 0(
subarray keep)
track of and update Vrna.\ and Tmin as J. increases, we can develop the followtng n
An algorithm called recursive squaring can further reduce the complexity to 8(1ogn).
algorithm:
Since [F.·~•
F,,
F,, ]==[' ']x[ F,, F,,_,] and [F2
F,,_, I 0 F,,_, F;,_2 F; f"o
F.]=[1 1] , we can show that
I 0
T = A[.IJ·' Vma.\: = A[l]·' Tmu\. = min(O,T)

[ F,,. , F,, ] =- ['


~ ~~ I 0
I]"using induction. Let A= [I 0I], we can agatn· app1y he d..de-
l
t tvl
For j == 2 ton
{ T =T + A[j];
11 1112
and-conquer paradigm to calculate A" : A11 =JA'' xA '
if n js even . The If T - Tmin > Vmax then Vmas = T - Tmin ;
l
Acn-l>/2 x A(n - l) /2 x A, if n is odd
If T < Tmin, then Tmin = T;
multiplkation of two 2 x 2 matrices has complexity 0(1). So T(n) =T(n I 2) + 8(1).
Applying the master theorem, we have T(n) = 0(1og n). }

Return V . ; . · d ·
Maximum contiguous subarray "'ax
. C++ function
The following is a correspon dmg that returns v max
and indtces 1 an J

Suppose you have a one-dimensional array A with length n that contains both positive given an array and its length:
en , .
1 •~ &_ ,
; .;

.. 5j)
and negative numbers. Design an algorithm to find the maximum sum of any contiguous j !1 1 maxS uba r r~yC~ uclc AI] , ;~

subarray A[i,j] of A: V(i,j)-:: IA[xJ, 15.i$j5.n.


.'Cwt C1oubll? T - A t 0 L Vmax=A. I 0 ] ;
Solution: Almost all trading systems need such an algorithm to calculate maximum run- dout:..leo Tm.1.. n •·' ' · 0 '
= rn-;~'0 'f );

up or maxi mum drawdown of either rea l trading books or simulated strategies. Therefore t· r ( l :. k= l; k< Jen ; -tl:)
this is a favorite algorithm question of interviewers, especially interviewers at hedge
fu!lds and trading desks. - - --
--~
T+ =A [ k ] ;
The most apparent algorithm is an 0(17 !) algorithm that sequentially calculates the ~ T - Tr~ n > Vma>o
I { IJr:i• .)( ':'" - "'
~:m- .
I
]'"' k• ; ·
''
~k·ll ;,J ;:
1
V (i, j) ·s lrom scratch usiog the following equations: u (k " .. JJ?
it ( T<Tmi n; {-:·min = 1' ; .:

wh~n
I

V(i, i ) = A[i] j ==i and V(i,J)= LA[x] ==V{i,j-J)+A[j] when j> i.


t.; ?'•.!L u rn Vrnax;
As the V(i,j) 's are calculated, we also keep track of the maximum of V(i,j) as well as
the corresponding subarray indices i andj.
Applying it to the following array A, r ( - 5 . cI -1. 0~ ;
J .JtJ A[ )=· l. 0 , 2 .0,- ..... . 0 I 4 • c I - 3 . CI :2 . 0 , ~' · I

tn i ..- 0 , 0;
Algorithms and Numerical Methods
- A Practical Guide To Quantitative finance l nlcrvi~\'S

A[ll. , i, j) ; Solution: The key to this problem is to realize that p e (0, \) can also be expressed as a
will give v;,a,. =9, i =3 and j =6. So the subarray is [4.0,- 3.0, 2.0, 6.0]. binary number and each digit of the binary number can be simulated using a fair coin.
First, we can express the probability pas binary number:
p =O.p p
1 2
... p" = p 12-' + p2 2-2 +···+ p, 2-", p, e{0,1}, 'rli =I, 2, ··· , n .
7.2. The Power of Two
Then, we can start tossing the fair coin, and count heads as I and tails as 0. Let s, e {0, \}
There are only 10 ki nd s of people in the world-those who know binary, and those who
don't. If you happen to get this joke, you probably know that computers operate using be the result of the i-th toss starting from i =I. After each toss, we compare P. with s, ·
the binary (base-2) number system. Instead of decimal digits 0-9, each bit (binary digit) If s, < p ,, we win and the coin tossing stops. If s, > p, ) we lose and the coin ~o~..;i~g
has only two possible values: 0 and l. Binary representation of numbers gives some stops. If s = p we continue to toss more coins. Some P values (e.g., 1/3) are mflmtc
interesting properties that are widely explored in practice and makes it an interesting
topic to test in interviews. series when' expressed
'' .
as a bmary num ber ( n -4 <X> ) · I n t)1ese ca"CS
~ ,
the ·probabilitY• to
reach s ~ p is 1 as i increases. If the sequence ·IS t~Jnl'te, (e.g., l/4=-0·Ol) and we reach
the fin~l s~ge with s, = p,. , we lose (e.g., for 114, only the s~~uence 00 wil~ he
Power of 2 classified as a win; all other three sequences 01, 10 and 11 arc classl!!cd as a loss}. Such
How do you determine whether an integer is a power of2? a simulation will give us probability p of winning.
Solution: Any integer x ~ 2" ( n ~ 0) has a single bit (th_~__('! + l)th bit from the right) set
~~ . I.. For example, 8 ( = 2' ) is expressed as 0· . . 01 000 . 1t is ·;is~-eas~ to-;e; .that 2" - I Poisonous wine
has all then bits from the right set to l. For example, 7 is expressed as 0·. -00111. So . . hd rt , Twenty hours before the party,
You' ve got 1000 bottles of wmes for a blrt ay pa ). . · . ed You
2" and 2" -I do not share any common bjts. As a result, x & (x -l) = 0, where & is a h b0 ttle of wme was po1son ·
the winery sent you an urgent message t at one bottle of \\-ine is poisonous.
bitwise AND operata(, is a simple way to ide ntify whethert he integer x is a power of2. happen to have 10 lab mice that can be u~d to. test wh::~~~ :xactly !8 ho~rs. But before
The poison is so strong that any amount will kill a mo there a sure wav that you can
the death on the 18th hour, there are no other symptoms. 1s •
Multiplication by 7 find the poisoned bottle using the I 0 mice before the party? .
. r1 .nate half of the bottles each ume,
Give a fast way to multiply an integer by 7 without using the multip1 ication (*)operator? Solution: If the mice can be tested s~quenttally toe ~: Ten mice can jdentify the
So/wion: (x <_,< 3)- x, where << is the bit-shift left operator. x << 3 is equivalent to x*8. the problem becomes a simple bmary s.earch p~o em~cly since the symptom won't
Hence (x << ..>) - x is x ~~<7. 8 - - . . _ poisonous bottle in up to 1024 bottles of wmes. ?~nhortun~e c~nnot sequentially test rhc
show up unti I l8 hours later and we 0 ?1Y ha~e - ?~All integers between 1 and 1000
mice. Nevertheless, the binary search tdea still app 1tes.l bottle 1000 caA be labeled a.
Probability simulation can be expressed in 1O-bit binary format. For examp 3
e,
9 8 ?' 2(i+2j+ 2
You are. .given, a. fair. coin 1111101000 since 1000 = 2 + 2 + - + · . fi . b.. (th . lowest bit
. · Can yo u des1gn
· a Simple
· . the fa1r
game ustng . com
. so that your
. . le that has a 1 tn the lrst ll c.
probabd 1ty ot wmnmg IS p, 0 < p < 1? 9 Now let mouse 1 take a stp from every bott b . th ., 1 in the second b1t~ ... ; and,
. f: very ott 1e WI .. . b' •
on the right); let mouse 2 take a stp rom e .th 1 10 · the lOth bit (the h1ghest Jl,.
fimall y, let mouse I 0 take a Sl· p firom e' 'en/
·: bottle WI a
the highest to the lowest btl ·
r:
and t at a
Eighteen hours later, if we Jinc up the mtce from ·· lv back track the label of the
live mouse as 0 and a dead mouse as 1. we c~n9 ~%icc arc dead and all others are
- -----~---
poisonous bottle. For example, if the 6th, ?th, an ~ the label for the poisonous bottle
: 1 1.1~: 1"\:, uh could be wrong if'-< causc..·s an overnow alive, the line-up gives the sequence 0101100000 an
H1n1: Computer stores bm·uy numbe · d f· . b
simulal~:d using a fair coin. ' · rs mslea 0 dec1mal ones; each digit in a binary number can e 8
is 2 + 2 6 + 2 5 = 352.
183
182
Algorithms and Numerical Methods
- A Practical Guide To Quantitative Finance lnlervicwl>

The esti mated price of the European call is the present value of the expected payoff,
M
7.3 Numerical Methods L:max(Sr.k- K,O)
- r ( T-1) ..!,
k-!!,-1_ _ _ _ __

The prices of many financial instruments do not have closed-form analytjcal solutions. which can be calculated as C = e M
The valuation of these financial instruments relies on a variety of numerical methods. In
this section, we di scuss the application of Monte Carlo simulation and finite difference
methods. . h £ N(" 0"2 ) (normal distribution
8 How do you generate random vanables I at o11ow r• .
·. d . 2) if your computer can only generate random vanablcs
with mean J1 an vanance C7
Monte Carlo simulation that follow continuous uniform distribution between and 1?
, . . . .
°
t the basic knowledge of random number
Monte Carlo simulation is a method for iteratively ~aluat~~g ~detenninistic model So/ut1on: Th1s IS a gr_eat questiOn to tes . f The solution 10 this question can
using ra~dorn numbe~with appropriate probabilities as inputs. For derivative pricing, it generation, the foundation of Monte Carlo Simu1a 10 0 .
simulates a~e nUI!lber of price _paths of ~!!.f!9~_r:.ly3_a_:5sets_ with probability be dissected to two steps:
corresponding to the underlying stochastic process (usuall y under risk-neutral measure), . N(O l) from uniform random number generator
1. Generate random vanable of x- ' h d
calculates the discounted payoff of the derivative for each patl1, and averagcs the . . r th d and reiection met o ·
discounted payoffs to yield the derivative price. The validity of Monte Carlo simulation usmg mverse trans1orm me o :1 ,

relies on the law of large nwnbers. d variables that follow N(p.CT·) •


2. Scale x to ).J + o-x to generate the final ran om . . ular
deserves some explanations. A pop
Monte-Carlo simulation can be used to estimate derivative prices if the payoffs only The second step is straightforward; the ftist steph . rse transform method: For any
depend on the final values of the underlying assets, and it can be adapted to estimate approach to generating random variables is. t edmv~ function. E..+ll.=...f(X) ), the
prices if the payoffs are path-dependent as well. Nevertheless, it cannoL be di r~tly . . bl X ·th cumulattve enstty .
contmuous random van a e WI . f u·j\'- F I (U) 0 5 u 51.
applied _,.___
. to American options-- - - early exercise options.
or any other derivatives with - d the inverse functton o
random variable X can be de fime as
. . -I ) i
' .
·.c_::.- I
. 0 < u < 1 So aov
1
a one-to-one function wit 1 - - . •
It ts obviOus that X= F (U s . h f0 Bowing process:
A. Explain how you can use Monte Carlo simulation to price a European ca11 option? continuous random variable can be generated usmg t c . . .
he standard uniform dtstnbutJon.
• Generate a random number ll from t b from the
So!w;on: lf we assume that stock price follows a geometric Brownian motion, we can the random num er
• Compute the value x such that u = F x as ( )
simulate possible stock price paths. We can split the time between 1 and T into :V
·
equa lly-spaced ttme 10 T- t n1 ~ d d rm·tl distribution,
steps. So 61 = - - and 1 = t + 61 xi !lor i =0 I 2 .. · N. n ~.;;
N
distribution described by F.
I ' ,,, ' I om utable. For stan ar no ,
For tltis model to work, F - (U) must be c p · ,, solution.
then simulat~ the stock price paths under risk-neutral probability using equation . has no ana1yttc,11
) _ S 11 - rr · 1 2'A_ !:J }+uEc; h , _ 1 U -:= F(X)=[:Y_l_e_ ~,; ,ldx. The inverse functJOil .· .
' , - . . ,_,e • w ere t::, s are liD random variables from standard norma
.J2i il'l ' of X lO U as the numcnc
di~trihution. L~t 's say that we simulate M paths and each one yields a stock price S, F Theoretically, we can come u~t
'th th one·to-one mapp g
e i ,t •! usin" ournerical
where k =I, 2, .....H, at maturity date T. - ) j(r) -~e o -
solution of ordinary differential equation F'(x :::: - • - ..J2!( . flicil.!nt than
h d I I Yet this approach IS less e
integration method such as the Euler met 0 ·
the rejection method:
'( ) tJte Euicr
- - - - - -- - -·- - · 'tial valut! r ;;; r X .
11
" . . . . "' ' =[(:c) and a known lnt . . • ·imat~ v vaiuo :
d' For European O"'i
" ·• .. · , ,_ .
1" on. · \\e ~~~n sunpl} set ,\ .. J. But for more general options espec•allv the path
.
To mtegrate y = F(x) w1th first denvallvt: Y . e) to sequenuaJiy approx ·
e,x·mkm ones. wr wam to have small ti•nc sk ps and therefore N should be large. ' • be positive or negatiV
method chooses a small step size h ( h can 185
184
Algorithms and Numerical Methods
A Practical Guide To Quantitative Finance Interviews
Some random variables have pdf f( x ) ' but no analyllcal
. solution for F ' ' (U). In these
simulation is computationally intensive if cr is large. Thousands or even millions of
cases, we can use a random variable with pdf g(y) and y-- C ' '(U) t o I1eJp generate simulations are often required to get the desired accuracy. Depending on the specif1c
random variables with pdf/( ) A . /( ) problems, a variety of methods have been applied to reduce variance.
x · ~ume that Nf IS a constant such that ___!_ ~ M, "i/y.
Antithetic variab le: For each series of &, Is, calculate its corresponding payoff
We can implement the following acceptance-rejection method: - g(y ) - - - -
Y(c11 .. ·, E,..,) . Then reverse the sign of all c, Is and calculate the corresponding payoff
• Sampling step: Generate random variable fro1n Y(-&1 ,. .. , - EN). When Y(E"· .. , E.v) and Y(-c" .. ·,-C.v ) are negatively correlated, the
from standard uniform d' 'b . [ Y g(y) and a random variable v
IS1f1 UtiOn 0, l).
variance is reduced.
• Acceptance/rejection step: ff v < f(y)
- Mg(y) , accept x = y; otherwise, repeat the
Moment matching: Specific samples of the random variable may not match the
population distribution well. We can draw a large set of samples first and then rescale
sampling step. 12 the samples to make the samples' moments (mean and variance are the most commonly
used) match the desired population moments.
An exponential random variable (g(x)- A -.<~ . l
So the inverse function has analytical -,e. ) Wit l A.= I has cdf u = G(x) =1-e-... Jon trol variate: If we want to price a derivative X and tbere is a c1oscly related
. so ut10n x =--log(! ) d d derivative Y that has an analytical solution, we can generate a series of random numbers
W1th exponential distribution ca b . - u an a ran om variable
n e convemently simulated For standard normal and use the same random sequences to price both X and Y to yield X and Y. Then X can
distribution, f(x) = ~ e-• '2 2
·
v21T. ' be estimated as X+ (Y- Y). Essentially we use (Y- f) to correct the estimation error of
(I lj), I . I ( ..
f(x) ~ . ~- - - vr J..{J c ~ , - "" X. ( r , n (o.ll 'iJ Yl ~
- -= - ex-.1 ! < ~e-i.r-ll, '~• l '1<,g ll2 ··- •
g(x) N ff - -e ~1.32, "iiO<x<co Importance sampling: To estimate the expected value of h(x) from distribution f(x),
instead of drawing x from distribution f(x), we can draw ~istribution ~(x) and
ff

So "ve can choose M = 1.32 and u h(x)f(x) \


x - N(O, l) random variables and I se the acceptance-rejection method to generate use Monte Carl o simulation to estimate expected value of\ g(x) ~
sea e them to N(/-l, a ~) random variables.

. J
ccan you explain a few variance redu (
Monte Carlo simulation?
.
c Ion techmques to improve the efficiency of
E, ,.T)[h(x)] = h(x)f(x)dx = Jh(x)f(x)
g . .
_ [ htx)f(x)ll.l
(x) g(x)dx- Egt.c> g(x) ·
f ?
{
h 4 11r. d e.. v' ... t1·- ~ ~ ~- v··
i • t Jp
I.
.
M

10 3
.\f I

Solution: Monte Carlo sirnulat' . . . If (xy(x) has a smaller variance than h(x), then importance sampling can result
Jon, m lis basJc foml .15 h g x)
~, >
;,... ,~ : f ===_I_ M
11 t e mean of liD random variables . I

more efficient estimator. This method is better explained using n_dec~ o~tt-o~-the-mone~.
,. •

M ~~ ~. Smce th~ expected value of each 1': is unbiased, the


option as an example. If we directly use risk~ neutral f(S, ) as the d1stnbutl0n. most of
estimator f is unbiased - h · t · n ariance will be
_
Var(Y) = a 1JM h
as welL If Var(Y) -
. -a and we generate liD Y, then
the simulated paths wiU yield h(S ) = 0 and as a result l e esuma 10 v
~ r ~·d spa•-vrl'lnter tai I tor ~''' )_
(
1~ ·
, w ere .\fis the number of si I . ,
· mu atJons. Not surprisingly, Monte Carlo
Iarge. If we introduce a distribution g(Sr) that has muc11 "" 1 er 'r ·-- .. \
- . - .- - ~ ~ .- . · f tt~ f( .t) ,J,ill keep the
more Simulated paths will have pos1ttve h~). The scah ng ac x(x) T
F(.r th) - F(x.. Hf(x) x h F(
·• •
. -
x + 2h} = f(x + h)
a standa1'd nonnal can be F(O) =O.S . ·· + f< x.. + h) x h, · · · . The initial value of the cdf of
- - .
estimator unbiased, but the approach will have lower vanance.
. /
11 P(X $ x)a: [g(v)~ -
, A~~{ 1') dy .\1
f /(y)c{l· .
.:::> F (x):::: P(.\ $ x) - r· d
. P(X< ~)- - ? f(y)y
11 . . hod using a change of measure.
1mponancc sampling is essentially a vanance reduct•on met
186
187
Algorithms and Numerical Methods A Practical Guide To Quantitative rinance Interviews

Low-discrepancy sequence: Instead of using random samples, we can generate a computing power, we can easily generate millions of (x, ~) pairs to ~stimate Jr with
deterministic sequence of "random variable" that represents the distribution. Such low- good precision. 1,000 simulations with 1,000,000 (x, y) pomts each usmg Mat\ab to~k
discrepancy sequences may make the convergence rate 11M. less than 1 minute on a laptop and gave an average estimation of 1r as 3.14\6 w11h
standard deviat ion 0.001 S.
D. If there is no closed-form pricing formula for an optjon, how would you estimate its
delta and gamma?
0.9 I

Solution: As we have discussed in problem A, the prices of options with or without


closed~form pricing fonn ulas can be derived using Monte Carlo simulation. The same 0.8l
...
t-
~
.-
methods can also be used to estimate delta and gamma by slightly changing the current 01
underlying price from S to S ±oS, where oS is a small positive value. Run Monte 0.61
Carlo simulation for all three starting prices S- oS, S and S + oS, we will get their
corresponding option prices /(S - oS), /(S) and f(S + oS) .
0.4

Estimated delta:!:::.= of = f(S+oS)-.f(S-oS) 03


os 2os 0.2 '

Estimated gamma: r= (/(S+oS)- f(S)) -( f(S)- f(S-oS))


+ - ..;.
oS 2 <"·
0 0.6 0.8 1
0 Q:?'
To reduce variance, it's often better to use the same random number sequences to X
estimate f(S- oS). f(S) and /(S + oS). 14 Figure 7. 1 A Monte Carlo simulation method to estimate TT

E. How do you use Monte CarJo simulation to estimate n ?

Solulion: Estimation of 1r is a classic example of Monte Carlo simulation. One standard Finite difference method . . . t; derivative
. h ular numencal techmquc or . .
~ethod to esti~ate 1r is to randomly select points in the unit square (x and y are The finite difference method ts anot cr pop . 11
·matc the ,rice
1 of a dcnvauvc:
·~ . fal1 equatiOn to cs 1
tndependent um form random variables between 0 and t) and detenn.ine the ratio of Pricing. It numeri cally solves a d tueren •
- 0 f the underlymg secun - ·
· 1,, We can convert t 1c
·
2 by discretizing the time and the pnce . r partial differential equation. to.
points that are within the circle x + / ::; 1. For simplicity, we focus on the first quadrant. · cond order non 1mea •.• , . ,
Black-Scholes-Mertoo equatton, a ~e . , This new equation. ~!.xprcss~::u ~:; a
As shown in Figure 7. I, any points with.in the circle satisfy the equation x} + y,2 ::; 1. The a heat diffusion equation (as we did 111 Chap.tcr ). 6 · t. the undcrlving secunty),
percentage of the points within the circl e is proportional to its area: . d ( f nctwn of the pncc o . . .
function of r (time to matunty) an x a u . . The difference between vanous
=Number of (x;,Y,) within x,2 + / ::; 1 114Jr 1 . . . I t'on for denvattvcs. d d 'tn<• th~
IS a general d1fferentta equal .. building a grid of x an ran us ': .
w
A A A

p Number of (x,. Y,) within the square = =4ff ::::::> ll' == 4 P · derivatives lies in the boundary conditions. Byl
1
t u ,11 cverv x and r using flmtc
boundary conditions, we can recurs!··velv- cacuae ' ·
So. we g~n~rate a .large number of independent (x. y) points, estimate the ratio of the difference methods.
po1.nts -:vutun the crr~Je to the points in the square. and multiply the ratio by 4 to yield an . . d"f[i ence methods?
A. Can you briefly explam fimte 1 cr . L •.
estJmat1on of tt. F1gure 7.1 uses only 1000 points for illustration. With today" s d in racucc. ct s
. f fi ite ditTerence methods use p d , nd the
Solution: There are seveml v~r:s10n ° tn h d the implicit ditlcrence metho a
14 T briefly go over the explicit difference met 0 '
h~.· method may not work well if the payoiT function is no! continuous.
18<>
188
A Practical Guide To Quantitative !=inane~ \ntcrvi~:"~
AI gont
· hms and Numerical Methods

Cran.k-Nicolson
. . method. As sho v.n ' tn
. F'tgure 7.2, if we d'v'd h
conditions and equation u~+' = au~_1 + ( l-2a) u~ +au~~" we can estimate a\\ 11':'-' on
dtscrete
N .
mtervals WI.th .
mcrement lH =T 1 N a . . t ' e t e range of r ' [0' T) , .Jnlo the grid.
J dtscrcte intervals WJ.th.tncrement & - (x nd dtvtde the range of x' [x· o• X 1 ] , mto
. The implicit difference method uses the backward difference at time 1
II+ 1
anti lh\!
expn::-.:,L'd as a grid ofT n- I - J - x~ )/ J , the time rand the space of n+l n "' ' ,+1
211 1 + ,,,\ -~
au
~ ~---"\.
" · - , · · ·. N and x J =:: , ... , .1 x can be SC 0d d ' tl} - U1. 1J 1 I -
1
U ·-1 V U
I'
c n -or er central dtfference at x I : -Of f:l f = ' ( flx ) ' Ox'
X ~
The Cronk-Nicolson method uses the central difference at time (1. +1.. ,)12 and the
XJ
- second-order central difference at xJ ·•
.\'.1-1 I
au ~ u"•' - ~t"
-
~
l (u" -2u" + u;-1 +
r ·' n n+l
uj+l - 2u"+l + u"·'
,-IJ\I o u "2

(~·<l (nx)~
' J - J J
-- - ::::-
or 6:r 2 fJxl .
u'·' u" .. ,
I ~
X
I' I - - JH
-
XI
II'I

,.,
X L/ .-> /
)
1
R If you are solving a parabolic partial diflOrcntial equation using the explicit tinitc
dJITer~nce method, is it worse to have too many steps in the time dimension or too man)
.J
u"
X un:.. ,
J-1 steps m the space dimension?
S<Jiulion: The equation for u••' in the explicit finite difiCrence method is
~ ~· =au'~_, + ( 1- 2a) u'~ +au" J
where a::: 6J J(Ax)
2
• For the explicit finite difference
J J j + l'
method to be stable, we need to have 1- 2a > 0 => At I( /!.x )' <1 / 2· So a · mall At (i.e ..
many time steps) is desirable, but a small /!.x (too many space steps) Jm\) make
/(l!.x)' > 1/2 and the resu!IS unstable. In thai sense. it is worse to lw,·c too many s«r'
61
in the space dimension. In contrast, the iJnplicit difference method is stable and alwa~s
convergent.
......
0 r, r~ ... r r ... 1,
. n 11 I

Figure 7.2 Grid of 'and x for finite different methods

l'h~ explicit difference method uses the fonnrd d.~


ord . . • ' "•crcncc at time
<r cenlral d11 tcn:nccat . , ·11 11· -• _ 11 " • r,. and the secoml-
~
xl. o r ;::; J
Jl I - u ,., - 2u"J +-u"1- 1 ciu
Rcomngin~ terms. r (Ax)' . "-(.\-.~
we can ex.pre..'is u ~I as . l'
an<.lu~ I:
II • I
WI I (I - ]a ) u '" au . where' a uA•jmear combination of u n,.l• u;'
conJition~ u • 1 u.,• · anJ u; fur' all = 1 . . . '.u :::: . · Besl'des. we often have boundary
(&f
11 . , .\ :, ~ o· ... · ·; · Combining the bow1dary

Das könnte Ihnen auch gefallen