356 16 17MB
English Pages 209 [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 tmposstble and unn~essary, practice does improve your interview skills. _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 mterv1ew room. probl:ms
IS,
3. Listen carefully
~;;~r~hoy~~ ~eamnpatcttive Jist~nerhin interviews so that you Wlderstand the problems well
o answer t em If any aspect f bl . politely ask for clarification. If the pr~blem is mo tho a pro !em IS not clea~ to you, 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, • 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.
When you analyze a problem and ex lore d·tJ . 1 • erent ~ays to. solve tt, never do it si lently. Clearly demonstrate your analysis p d necessary. This conveys your intelran wnte down the Important steps involved if methodical and thorough. In cas • th Itgence to the interviewer and shows that you are . . , e a you go astray th · · mterv1ewer the opportunity to correvt h ' ' e. tnteractiOn will also give your S . k. . t e course and provide you with some hints. ex . . ev pea· mg your mmd does not mean · PIammg · obVIous to you. simplv state tile c .· . ery t'my detall. If some conclusions are . .. one1us1on with t tl · · not, tI1c mtcrviewcr uses a probl ou le tnv1al details. More often than . your understandi em to test 1 on demonstratmg f a specific concept/approach. You should focus ng
0
the key concept/approach instead of dwell ing
5. Make reasonable assumptions ln r~al job settings, you are unlikely t0 h have before you b ' ld ave all the necessary information or data you' d mtervicwe rs may not g1ve . you all Ui a model and make a deciston. · · th ln interviews, make rc· , hi e necessary assu · · .• tsona c assumptions Th k mp1tons e•ther. So it is up to you to nssumpu . · so that e eyword · reasonable. Explain your · · . ~ns to tht: mterviewer , . here . ls qudantJt~tlv~ problems. it is crucial th· t ) ou wrU ~et Immediate feedback . To solve an dcs1gn appropnatc · frameworks to a you can qUick1 Y rna ke reasonable assumptions · so1ve problen1s based on the assumptions. w, . . c arc now ready to .· . lmv • f1 I . rc\•tew basic concepts i . . . c un so vmg real-world intervt'ew bl _n quanhtattve finance subicct areas and J ' pro ems!
~refer to
2
[n this chapter, we cover problems that only require common sense, logic, reasoning, and 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 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 problem-solving skills; some require you to think out of the box; while others ask you to solve the problems using fundamental math techniques in a creative way. In this chapter, we review some interview problems to explain the general themes of brain teasers that you are likely to encounter in quantitative interviews.
2.1 Problem Simplification If the original problem is so complex that you cannot come up with an immediate
4. Speak your mind
on less relevant details.
Chapter 2 Brain Teasers
solution, try to identify a simplified version of the problem and start with it. Usually you can start with the sj mplest sub-problem and gradually increase the complexity. You do not need to have a defined plan at the beginning. Just try to solve the simplest cases and analyze your reasoning. More often than not, you will find a pattern that will guide you through the whole problem.
Screwy pirates Five pirates looted a chest fuJI of I00 gold coins. Being a bw-1ch of democratic pirates, they agree on the following method to divide the loot: 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) accept the proposal, the gold is divided as proposed. If not: the most senior pirate will be fed to shark and the process starts over with the next most senior pirate ... The process is repeated until a plan is approved. You can assume that all pirates are perfectly rational: they want to stay alive first and to get as much gold as possible second. Finally, be ing blood-thirsty pirates, they want to have fewer pirates on the boat if given a choice between otherwise equal outcomes.
How will the gold coins be divided in the end? Solution: If you have not studied game theory or dynamic programming, thi s strategy problem may appear to be daunting. If the problem with 5 pirates seems wmplex, we can always start with u simplified ,.·ersivn of the problem by reducing the number 0f pirates. Since the solution to 1-piratc case is trivial. let '~ start with 2 pirates. The senior
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 get nothing. Rut if he offers private I nothing, pirate 1 wi ll be happy to kill him. So 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.
Following the same logic, we can naturally show that if the number of tigers js even, the sheep wil l not be eaten. If the nwnber js odd, the sheep will be eaten. For the case 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 by an old bridge, which holds at most 2 people at a ume. Bemg d~rk, they cant cross the brjdge without a torch, of which they only have one. So each patr can only walk .at the 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 takes 2 minutes; and D takes l minute.
PI~atc 3 und p1rate I. will get nothmg. So he only needs to offer pirate I and pirate 3 one com each to get thc1r votes i:lnd keep the remaining 98 cojns. If he divides the coins this way. he will have thrt::c out of the fi ve votes: from pirates 1 and 3 as well as himself.
On~c we start with a simplified version and add complexity to it, the answer becomes 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 himself.
go ~ith the ~ 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 and B go across ( 10 min); send C back (2min); ('and D go acros~ ~gain (2 ml~).
Soiulion: The ke_y point is. to r::aJize tha!_the 10-minute
Tiger and sheep
It takes 17 minutes in total. Alternatively, we can send C back first and then D back in the second round. which takes 17 minutes as weJI. 1.~ Ld 11.. t , ~ j .:: h -, r r ,~f ~, ~~ h 'I
One hundred tigers and one sh . . . put on a mag1c Island that on ly has grass. Ttgers eep are can eat grass but thev would rath t ... . . • .; er ea S~teep. Assume: A. Each tlme only one ttger can ~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
Solwion: I00 is a large numb r ,0 . 1 ~ . . problem. If there is onI 1 ti ' ere · ~ agam et_ s .\·!arr wrth a simplified version oj the to Wt.lrry about b · y g ( n- l ). surely It Will eat the sheep since it does not need . emg eaten. How about ? t'1 '> s· bo · · I either tiger probably , , ld d · . - . gers ' mce th t1gers are perfectly rattona. o some as to wh.at Wl'II h appen 1' t'.It eats t he sh eep. h • ther tiger is probablyltOU thinkin . if 1 thmkmg' • · be eaten by the other t' > S g. eat the sheep, I Will become a sheep; and then I will 0 tiger will eat the sheep. Iger. to guarantee the highest likelihood of survival. neither
pe~son ~ho~ld.
Birthday problem
r'J\
You and you r co lleagues know that your dates: .' Mar 4, Mar 5, Mar 8 / f7 Jun 4• JL}.l.b ~ · Sep 1. Sep 5 ·' _;
,/
1
~"'~
tl
;i ' v
t
y/
bos~
A' s birthday is one of the following 10
"7 "
J J':2 . ';L.
t;. )
t
.
1
.~~ ......___
L
Dec l. Dee-2. Dec 8 / J'
If lhl!rc arc 3 tigers. the shee will be . . . . . . changes to a sheep. there will ~e . eaten smc~ ea.ch t1gcr will reahzc that once 1t 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
A told you only the mom~}>r his birthday. and told your ,colleag~e ~ co,
adding or minus one x A should yield the same result. 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.
2.3 Thinking Out of the Box Box packing Can you pack 53 bricks of dimensions I x Ix 4 into a 6 x 6 x 6 box? So!wion: This is a nice problem extended fro problem vou have a 8 x 8 chess b d . h m a popular chess board problem. In that corners ;.;moved You have n1.a oba~ kWJt . two small squares at the opposite dia~onal . . . ny TIC ' S wuh dimens· l 2 C -. Into the remaining 62 squares? (A 1 . JOn x · an you pack 3 I bncks . . n a tcrnattve question . , h h 62 squares usmg bricks without an b . k . . . IS w et er you can cover all
the board, which requires a simt'l: ncl s ?vcrlappmg wtth each other or sticking out of ctr ana ysts.) ~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 o~pos1tc
L n = 100 + 99 + ··· + 2 + I ;·~: ~ ~ ~ ~ 100 x I 0 I 2L n = 10 I + J0 l + ··· + l 0 I + I 0 1= I 01 x 100 ~ L n = 2 ' 00
"~
d-1
.,,~ 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 =----'' -'n=1
2
Solution: Denote the missing integers as x and y, and the existing ones are z1, ••• , z98 .
Applying the summation equations, we have
Tht! summation formula for consecutive squares may not be as intuitive:
'f
11
:
100
6
3
2
n= l
100
6
"n = aN + b
L,n =x
~
2
3
u 2 + eN + d 1•v
··1 an d app 1y t he ·tmtta
conditions
Jv;: O=:> o=d N - I=:> 1=u+b+c+d A = 2 =:> 5 -= 8a + 4b + 2c + d
2
2
t;l
2
,
2
+y +
,.1
N
But if we correctly guess that
t 00 X I 01
L:n =x+ y+ L,z, => x+ y =
= N(N + 1)(2N + I) = N 3 + N 2 + N.
"1
')S
98
I z;
2
=>
t:1
x +y 2
2
98
Iz, t=l
100
3
I 00 2
I00
98
L,z,-
=--+--+- 3 2 6 ,.,
,
Using these two equations, we can easily solve x and y. If you implement this strategy using a computer program, it is apparent that the algorithm has a complexity of O(n) for two missing integers in 1 ton .
Counterfeit coins I
1\ = 3 ~ 14 =27a+9b+3c+d
we that tl will th --have the solution · . a = 1/3 ' b ==- 1/?-, c = 1/6, d- 0 · we can then east·1y show lat e same equation apphes to all N by induction.
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 grams. Can you find the counterfeit bag in only one weighing, using a digital scale that tells the exact weight? 9
Clock pieces
Solwion: Yes, we can identify the counterfeit bag using one measurement. Take I coin
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 (l,.'o strange 'h ~A • • on each ptece are equal. What are the numbers on each Piece?· ,.,. -s apcu ptece IS allowed.)
~ _ 12x l3 =78. So the numbers on each on, ~n 2 ptt:C(' must sum up to ?6 Some interv· . 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 . : ape p1ece IS allowed. It's easy to they cannot find more consccut"•ve · been e mtervtewees' thinking gets stuck because 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 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. Solwion: Using the summation equati
.
Th
out of the first bag, 2 out of the second bag, 3 out the third bag, · · ·, and I 0 coins out of 10
the tenth bag. All together, there are
L n = 55 coins. f f there were no counterfeit coins, i~1
they should weigh 550 grams. Let's assume the i-th bag is the counterfeit bag, there will be i counterfeit coins, so the final weight will be 550 ± i. Since i is distinct for each bag, we can identify tbe counterfeit coin bag as well as whether the counterfeit coins are lighter or heavier than the .real coins using 550 ± i. This is not the only answer: we can choose other numbers of coins from each bag as long as they are all different numbers.
Glass balls 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 two missing intt!gers twithin [I. lOOJ)?rom to IOO. What is a good way to find out the
9
Hint: In order 10 find the counterfeit coin bag in one weighing. the number of coins trom each bag must 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
Solution: Suppose that we have a strategy with a maximum of N throws. For the first tl~r.ow of ball one, we can try the N-th floor. r f the ball breaks, we can start to try the ~c~~>,~d ~II from the first floor and increase the floor number by one un tiI the second a re s. At most, there are N- 1 floors to test. So a maximum of N throws are 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'
:~: ~;;: ~::: ~~~:.~h~u~e~~(~~N~~)II ~~ only cover N- 2 floors if the fi rst balr breaks. ff
. t oor does not break, we have N- 2 throws left So can on 1Y tncrease the floo b b N · can only cover N- 3 0 'frhnufim er Y -2 for the first ball since the second ball .
w~
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 WSJS + /v-1)+· .. +1-N(N+l) / 2 l d 00 stories. we need to have N(N + > . · n or er to cover l 2 100 . l)/ · Tak,ng the smallest integer, we haveN =14 . Bastcally. we start the first ball on the 14 h t1 . st:cond ball to try floors 1 2 .. . lJ with t . oor, tf the ball breaks, we can use the 14th floor is X). If the fl~t doe a maxtmum throws. of 14 (when the l3th or the 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 , maxunum t rows of 'l 4 as well
ball
.
2. 6 The Pigeon Hole Principle
Here ts the basic version of th p· . e tgeon Hole Pnnc·1 1 • ·r • 1 ptgcons t1an and vou put every · . . P c. J you 11ave fewer pigeon holes , 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, , ptgcons. at least 2 pigeons have to ·t . . you la\ c n holes and more than n + I s tate one ot the I10I Thc generalized . 1.f ) .nu I1avc n holes and at least . 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 · . . cr~:: \\t' will usc some exarnples to sl th . e s.urp~tsmgly useful in many problems. lOw etr apphcatJOns.
1(111'
lilt:
Assume we desiun a st . t
.
b.111 ~an t·ovcr N - I tl ~ ... ra c~y wtrh N maximum
oors, •I the first ball is thro
Wll
throws If I ti
. . t le lrst ball IS thrown once the s~cond IWICC the db • , secon all can cover N - 2 floo rs ...
.
Matching socks Your drawer contains 2 red socks, 20 yellow socks and 3 I blue socks. Being a busy and absent-minded MIT student, you just random ly grab a number of socks out of the draw and try to find a matching pair. Assume each sock has equal probability of being selected, what is the minimum number of socks you need to grab in order to guarantee a pair of socks of the same color? Solution: This question is just a va riation of the even simpler version of two-color-socks 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 that at least two socks have the same color (2 pigeons share a hole).
Handshakes You are invited to a welcome party with 25 fellow team members. Each of the fellow members shakes hands with you to welcome you. Since a number of people in the room haven' t met each other, there's a lot of random handshaki ng among others as wel l.lfyou don)t know the total number of handshakes, can you say with certainty that there are at least two people present who shook hands with exactly the same number of people?
Solution: There are 26 people at the party and each shakes hands with from 1-since 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.
Have we met before? Show me that, if there are 6 people at a party, then either at least 3 people met each other before the party, or at least 3 people were strangers before the party.
Solution: Thls question appears to be a complex one and interviewees often get pul./.kd by what the interviewer exactly wants. But once you start to anaJyze possible scenarios, 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 scenarios: Case I: Suppose that at least 3 people have met you before.
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 no pair among these people met each other, then these people (> 3 people) did not meet each other. In either sub-case, the conclusion holds. Case 2: Suppose at least 3 people have not met you before. If two people in this group did not meet each other, you and the pair (3 people) did not meet each other. If all pairs among these people knew each other, then these people (;:::3 people) met each other. Again, in either sub-case, the conclusion holds.
we only use 2 coins from bag 2, the final sum for I coin from bag 1 and 2 coins from bag 2 ranges from -3 to 3 (7 pigeon holes). At the same time we have 9 (3x3) possible combinations for the weights of coins in bag 1 and bag 2 (9 pigeons). So at least two 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 ranges from -4 to 4, which is possible to cover all 9 combinations. The following table exactly shows that all possible combinations yield different sums: Sum
Ants on a square There are 51 ants on a square with side length of 1. If you have a glass with a radius of 117, can you put your glass at a position on the square to guarantee that the glass encompasses at least 3 ants?'!
Solu'io~: To guarantee that the glass encompasses at least 3 ants, we can separate the 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 sure that. the glass is large enough to Cover any of the 25 smaller areas. Simply separate the .area Into 5 x 5 smaller squares with side length of 1/5 each will do since a circle with radius of 1/7 can cover a square'? with side length 115.
Counterfeit coins II There are 5 bags with ~00 c~ins in each bag. A coin can weigh 9 grams, 10 grams or II ~r::s~~n~~~~a~ contain, cOl.n~of equal weight, but we do not know what type of coins 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 e ermine w Ich type of coin each bag contains?
Solution: If the answer for 5 ba s is
b . b WIg not 0 vlQus,.let's start with the simplest version of ag.. e °dny need to take one com to weigh it. Now we can move on to . 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 ypes to I, 0 and I (by removing the mean 10), If the problem-1 2 bags Ho
11
H·
m~:Separate the square into 25 smaller areas' h 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 mt: tart with a simpl" problem Wh t 'f up 0 ....2 r an Ji » 1.414. . alyouhavetwb f" d you nee from each bag to find the ty f . . . 0 ags 0 coins Instead of 5 how many coins do b .. ' difference In .' com num ers:'Th en how about three bags? pea Comsmeltherb ago'Wh' at IS the rmrumurn 12
t coin, bag 1
• I~ "
-I
0
1
-I
-4
-3
-2
0
-I
0
1
1
2
3
4
N
CO ,;; c
'0
U
~ eland
C2 represent the weights of coins from bag 1 and 2 respectively.
Then how about 3 bags? We are going to have 33 = 27 possible combinations. Surely an indicator ranging from -13 to 13 will cover it and we will need 9 coins from bag 3. The possible combinations are shown in the following table: Sum
C2
I~ "
~
-I
0
1
-I
0
1
-II
-10
-9
-8
-7
-6
-5
-3
-2
-I
0
1
2
3
4
6
7
8
9
10
II
12
13
-t
0
-I
-13
-12
0
-4
1
5
ee
CO ,;; c '0 U
~
C2 1
C2=O
-I
1
C 1, C2, and C3 represent the weights of coins from bag!, 2, and 3 res p ectiveiy .
Following this logic, it is easy to see that we will need 27.coins from bag 4 and 81 coins from bag 5. So the answer is to take 1, 3, 9.' 27 and 81 corns ~rom bags 1,.2,3, 4, ~n~ 5, respectively, to determine which type of cams each bag contams using a single weighing.
2.7 Modular Arithmetic The modulo operation----,
32
The generalized
I(x) f(x+LIx)LIx
t~
power rule:
Some useful equations:
dy dy du and u = u(x) , then dx = du dx
dy" 11-1 dy -6 r 'Vn:t:dx = ny dx a
a
exist,
Calculus and Linear Algebra
A Practical Guide To Quantitative Finance Interviews
In(ab)=lna+lnb 1im~=1 lim(l+x)"=I+!O
H'
minimum value of [(x),
d"
d" =e"du -e dx
a -=(a dx
dx
d . dx smx
e
" Ina)- du
I du u' d -Inu=--=dx udx u
dx
d cos x, dx cosx = -sinx,
is a decreasing
function at c.
foranyk
HO
lim(lnxlx')=O
is an increasing function at c; if j'(c) < 0, [(x)
j'(c) > 0, [(x)
Second
Derivative
then j'(c) = O.
test:
Suppose
the secondary
derivative
continuous near e. If J'(e) = 0 and f"(e) > 0, then J(x) j'(e) = 0 and ["(e) < 0, then [(x)
~ tan x e sec- x
of J(x),
J"(x),
is
has a local minimum at e; if
has a local maximum at c.
tr
What is the derivative of y =
Without calculating the numerical results, can you tell me which number is larger, e J[e ?2
In Xln .. ?1
Solution: This is a good problem to test . specifically, the chain rule and th d your knowledge of basic derivative formulase pro uct rule. Let u=lny=ln(lnx'''')-1 h we ave du dx
= d(lny)
~_: =
dx
- nxx In (I nx ) . . . Applying the cham rule and the product rule
d~X)
xln(lnx)+lnxx
d(ln(lnx)) dx
In(ln x)
x
Solution:
right side we have e ln x. If elf '
In x
+--, xlnx
To derive d(ln(lnx)) . dx ' we agam use the chain rule by setting v = In x : d{1n(lnx))_d(lnv)dv I I dx -=-x-=~ dv dx v x
xln x
.i-dy _In(lnx) Inx d dx +-==>2_Y(1 y x xlnx dx --:;
ln x'?"
n(InX)+I)=~(ln(lnx)+I).
Maximum and minimum Derivative ['(
) .
essentially the slope of the . the Illstantaneous rate of ch ( . tangent line to the curve y = [(x) and ange velocity) of .h Y Wit respect to x. At point x:::: c, if •
X
IS
'H' tnt: To calculate the derivative 0 . logs on both side f functIOns with the format _ ,.. s and then take the derivativ . Y - f(x) , It IS common to take natural e, Since d(lny)/ cit- '" 1/ yx dy/ dx.
34
Let's take natural logs of elf and ffe. On the left side we have >lle,
ell" >1[e
ee s-x ln e c- e x ln a
c> Ine
e
Jr
or
In e , on the
> lnff. 1r
Is it true? That depends on whether J(x)::::: lnx is an increasing or decreasing function x . , 1/ .r x x ln r l-eln x from e to fl. Taking the derivative of lex), we have J (x):::: 1 ::::: x: x2 ' c
which is less than 0 when x> e (In x > I). In fact, J(x) x
v
Ine
e for all x>O. So ->-e
Ina 1r
an
has global maximum when
d e" e e »w,
Alternative approach: If you are familiar with the Taylor's series, which we will discuss • 1 3 .. . xx"", xx-x ' mSectlOn3.4,youcanapplyTaylor'ssenestoe : e ::::LJ!=I+,+-,+~,+··· So n=O n. I. 2. 3. e x > 1+ x,
v» > O. Let
L'Hospilal's
x
= ff I e -1,
h
t en e
,1'1e > 1l I e
¢:>
e tt t e > J[ ee- e If > st e .
rule
Suppose that functions [(x) and g(x) are differentiable at x -+ a and that ,~~ g '(a) " O. Further
2
Hint:
suppose
Again
monotonously
that lim [(a) =0
consider
x--;o
taking
natural
and limg(a)=O X--;Q
logs on both sides;
or that lim[(a)-+±oo
and
X--;U
In a > In b :::::> a > b since
In x
IS
a
increasing function.
35
Calculus and Linear Algebra
A Practical Guide To Quantitative Finance Interviews
-> too, then lim f(x) = lim f'(x)
limg(a) Ho
g(x)
HO
an indeterminate
.a
L'Hospital's
g '(x)
form to a determinate
rule converts
F(a) ~ Yo => F(x) ~ Yo +
the limit from
r
form.
The generalized power rule in reverse: What is the limit of
eX / x
2
as
x ----t
and what is the limit of
u),
In x as
Xl
O+?
x ----t
, Solution: ~~~ Xl
is a typical
x:
example
of L'Hospital's
f(x)
e'
lim-== x~"'X2
x~'" g'(x)
, f(x) IIm--== x_"'g(x)
I'
e'
f'(x)
Im-==lim--r x-."'x2 .O'
Ilx
-21x'
,x'
==lim -
x~O, _ 2
Xl
In x since it's
Inx limit as IIm----:?
x-4O·xSo we can
now apply
:. Ilnxdx==xlnx-
B. What is the integral of sec(x) from
and v ==x , we have
wherecisanyconstant.
x ==0 to x
=
lr
/6?
Clearly this problem is directly related to differentiation/integration trigonometric functions. Although there are derivative functions for all
Solution:
trigonometric
=0
Idx==xlnx-x+c,
by parts. Let u ==In x
functions,
we only
need
to remember
two
of them:
~sinx dx
e
of basic cos x,
~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
Again, let's begin with some basic definitions . 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 If f(x) = F'(x)
36
rf
,1
(x) =
r
1F'(x)dx
= [F(x)]: = F(b)-
F(a)
dx
dx
cos"
e
sec r tan x,
X
F(x) an
~d:c(~s:::ec:cx~+~t:::an~x) = sec x( sec x + tan x) . dx 37
Calculus and Linear Algebra A Practical Guide To Quantitative Finance Interviews
Since the (secx+tanx) d In I secx+ tan x
1_ secx(secx+ ~
dx
term occurs in the derivative, we also have tan x)
(sec x + Ian x)
e
sec r
~ fsecx=lnlsecx+tanx!+c an
d
f''r/6
.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 . applied problems, the most di~ I on o. integration to volume calculation. For these '. ICU t part IS to correctly [annulate the integration. The general IntegratIOn function to calculate 3D vol . V ume IS = A(z)dz where A(z) is the 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. expression for eros s-sec tirona Iarea A as a functton " of z.
f'
Figure 3.1 gives us a clue. If you cut the i . ntersecnon by a horizontal plane, the cut will b' (2)2 e a square WIth side-length ~( 2)' calculate the total 1 r - z . Taking advantage of symmetry, we can vo ume as 2x 1[{2r)2 _{2Z)2}tz
=8x[r2z_z3
/3]; = 16/3r3 ~ 16/3"
An alternative app h " ". roac reqUIres even b tt 3 . IS lllscnbed inside both cylinders . ~ ~r D Imagination. Let's imagine a sphere that lt sphere should have a radius of A IS mscribed inside the intersection as well. The "" the eireIe from the sphere IS "" Inscribed r iine. th I each cut perp en diICU Iar to the z-aXIS, Acirde = ~ A' V-I 6/3 r 3 = 1613. 'Ole'sec/IOJ! -
i~
l1
Figure 3.1 Interaction of two cylinders B. The snow began to fall some time before noon at a constant
rate. The city of Cambridge sent out a snow plow at noon to clear Massachusetts Avenue from MIT to Harvard. The plow removed snow at a constant volume per minute. At I pm, it had moved 2 miles and at 2 pm, 3 miles. When did the snow begin to fall? Solution: Let's denote noon as time 0 and assume snow began to fall T hours before noon. The speed at which the plow moves is inversely related to the vertical crosssectional area of the snow: v =cjl A(t), where v is the speed of the plow, c1 is a constant 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 A(t) = c2 (t + T), where C2 is the rate of cross-sectional area increase per hour (since the snow falls at a constant
rate). So v=
c c, c where c~-' Taking the = c2(t+T) t+T c,
integration, we have
1
c --dt=cJn(l+T)-clnT~cJn T+t
c l'--dt=cJn(2+T)-clnT~cJn T+t
(I+T) -~2, T (2+T) -=3 T
From these two equations, we get
(I
(2 T)' ;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 knowledge and algebra knowledge.
continuous polar region R is converted to
""
fff(x,y)dxdy
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 probability and statistics. Here we just use one example to show its application:
If X is a standard normal random variable, X - N(O, I), what is E[ X I X > O]? Solution: Since X - N(O, 1), the probability density function of x is f(x) and we have E[X
IX
> 0] ~
2
Because d(-1/2x )=-x
f xf(x)dx ~ f x ;", e-
II
Jke~112X\lx
determined by x -- E[X I X >
=:
=: ~ ~
OJ= l/fh'
;;[euJ;
=: -
0 and x =:
OCJ ~
U =: -OCJ
t12
[e-xlI2Jx.
Solution: Hopefully you happen to remember that the probability density function (pdf) x1 e- /2. By definition, we have of the standard normal distribution is f(x) == ~
2
.r
constant,
it is
by letting u = -I / 2x2• Replace
AJr(O-I)
=: -
.$r e-
Calculate
II
..,2"
and JeUdy=eu +c, where c is an arbitrary
r -j==beudu
=
~ jff(rcosB,rsinB)rdrdB_
n
dx .
'"
obvious that we can use Integration by substitution . h e" - h -du, we have e ~lIhlWit e an d x dx wrt
rx
Changing Cartesian integrals into polar integrals: The variables in two-dimension plane can be mapped into polar coordinates: x =: r cos e, y == r sin e. Tthe integration in a
=:
r-r
h' where
[f(x)dx~
[Jz;e-""dx=2f
•
[_J_e- l/2m-=I, .J2"
problem:
[ e-x212 dx [", e~J'2/2dy == [(
e~(Xl+yl)/2dxdy ==
rr
e ~(rlcos2B+r2sin20)/2rdrde
~f re-"12rdrdB f e-"I'd(-r'/2)
(".
= -
3.3 Partial Derivatives and Multiple Integrals
~-[e-"I'IrBr
Partial derivative: w= f(x,y)=> af (xo'Yo) = lim f(xo + ill:,Yo)- f(xo,Yo) = J,
ax
Second order partial derivatives: a'f
ax'
tu
ik-.,.O
= ~(af), ax
a' f
ax
2
continuous first-order partial derivatives, then 8w ::::mv
at,
=
Since [e~x2/2dx=
x
a af
ax0'
The general chain rule' Supp th . ose at w== f(xt,x2,···,x Xl' x2, xm is a function of the variables 11' f , "., ".,
ax (0') ~
If all these functions have
aXt
+ Ow
aXl afi
&:2
aX2 + ... + at,
Ow
r
dB
~2" (e~x212dx=:.J21r:::::>
[e-XlI2dx=:J%.
3.4 Important Calculus Methods
) and that each of variables ;~.
[e~y212dy,wehave
a af a/a)
ax'!!.
ax", at
for
Taylor's series One-dimensional
Taylor's series expands function f(x)
derivatives at a point x
>
as the sum of a series using the
xo :
i
f(x)=f(xo)+ 40
you will need to use polar integrals to solve the
X
~
each i, I s; i:
I'(xo)(x-xo)+
1"( o ) X
21
(x-xo)'+---+
f"'(x 0 ) 1 (x-xo)"+--n. 41
Calculus and Linear Algebra A Practical Guide To Quantitative Finance Interviews
Combining these three series, it is apparent that ei8 ==cos 8 + i sin B.
If Xo =0, J(x) = J(O) +J,(O)x + J"(O) x' +...+ J''''(O) x" + ... 2! n!
When
Tavlor's seri~s are often used to represent functions in power series terms. For example aylor s senes for three common transcendental functions, e", sin x and cosx a; xo=Oare ' 2 3 x~l XX X e =L.-==l+-+-+-+ /I"on! I! 2!
.
"00
cosx
e
(2n+ I)'
L"(1)/12/1-
x
(2n)!
"o0
'
=x--+
__
x
2
4
eiJr ==cos II + i sin II ==~ 1. When 8 ==II /2, the
equation becomes eiJrl2 =cos(1l/2)+isin(1l/2)==i.3 Hence, In(ii) ==Hni ==i(i1!/2)
==-J[ /2:::::} ii ==e-
So Ini==ln(e JrI2
iJr/2
)==ill/2.
.
for all x > -1 and for all integers n~2.
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)
6
x
X
becomes
7
7T+'"
3! 5!
=1-':"'-
==st , the equation
B. Prove (l + .r)" 2':l+nx
x'
x)
~(-I)"X2/1+1
stn x e L.
...
3!
f)
with
X
o::: O. So we can consider solving this problem using Taylor's
senes.
2! +41-61+'"
The Taylor's series can also be expressed
h
as t e Sum of the nth-degree Taylor )' J'''' (x ) polynomial T,,(x) = J(xo) + I'(xo)(x _ x ) + J"(xo) ( • 0 21 x-xc + ... + 0 (x-xo)" and aremamder R,,(x): J(x)=I;(x)+R,,(~.~ n!
t/
( ) _ J''''''(x) For some x between x and o '''X_ R ______ (n+1)!
~
!R" (x)l
J(x) = J(xo) + I'(xo)(x - xo) + I"(x) (x - xo)' = J(O) + ('(O)x + I"(x) x' 2! . 2', = I + nx+
I x-xo 'I...... ") /.LetMbethemaximumof
IJ''''''(x)-I for all i between xo' and x, we get constraint
For Xo ==0 we have (1 + x)" ==1 for v n ~ 2. The first and secondary derivatives of f(x) are I'(x) = n(1 + x)"-' and I"(x) = n(n -1)(1 + X)"-2. Applying Taylor's series, we have
:$
,,+1
M x I x - Xo I (n+ I)!
where x:$x:5:0 Since x>-l
n(n -1)(1 + x)"-' x2 if x -I . The base case: show (I + x)" 2':1+ nx, v x > -1 when n ==2, which can be easily proven since (1+x)22':1+2x+x2
2':1+2x, Vx>-l.
step: show that if (l + x)" 2': 1+nx, \Ix > ~I when n ==k, the same (1+x)"'2:I+(k+l)x,'1x>-1. This step IS holds for n :::k + I :
The induction statement
straightforward as well.
3
.Os .B' +1--1_+ ... 3! 5! 7'
'CI ear Iy t hey satlS'J '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) ~(I+kx)(I+x)=I+(k+l)x+kx2,
Alternatively, we can use algebra since it is obvious that the solution should be slightly higher than 6. We have (6+y)2=37=;.y2+l2y-l=0. If we ignore the / term,
'1x>-1
which is small, then y = 0.083 and x = 6 + y = 6.083.
~1+(k+l)x 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) a differentiable function.
Newton's method Newton'~ met.hod,.also known as the N~wton-Raphson method or the Newton-Fourier method, IS an iterative process for solving the equation [(x) = O. It begins with an initial value Xo and applies the iterative step x Il+]
=x
Il
- I(x") f'(x,,)
t
0
1 I() (Lif so ve x = I
XI,X2,'"
Convergence of Newton's meth d . is far away from th 0 ~snot guaranteed, especially when the starting point e correct so 1unon For Newt' th d .. ft 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 I erentIa e around the root When it d - --;''---;2' oes converge, the convergence rate is quadratic, (x hi -x) w Ichmeans "+1 f O. Since I(x) is differentiable, there must be an x between Go and bo that makes f(x)
A. Solve
O? Assume f(x)
Solution: Besides Newton's method. the bisection method and the secant method are two alternative methods for root-finding. 5
converge."
f
=.
.J5)/2,
which makes it faste~than the_bisection
--
method but slower than Newton's method. Similar to Newton's method, convergence is not guaranteed if initial values are not close to the root. series for
•
= 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"
V!(x)=(Z"
vector
%1' "', ~).
The
necessary
",
condition
WIith
XII )
for
gra d'lent
maximizing
or
minimizing !(x) subject to a set of k constraints gl(XI,X2,",X,,)
= 0,
,"',xJ
g2(XI'X2
is thatV/(x)+A,Vg,(x)+A,Vg,(x)+ Lagrange multipliers.
=0, "',
gk(XI'X2,'
... +AkVg.(x)=O,
. ,XII)
=
a
where A,,···,Ak
Separable differential
equations
A separable differential equation has the form dy = g(x)h(y). dx can express the original equation as
are called the
dy
h(y)
= g(x)dx.
Integrating both sides, we have the
solution f dy ~ fg(x)dx. h(y)
What is the distance from the origin to the plane 2x + 3Y + 4z = 12 ?
A. Solve ordinary differential equation y'+
Solution: The distance (D) from th " I' . . . '. e ongm to a pane IS the nurumum distance between the ongm and points on the plane. Mathematically, the problem can be expressed as
dy Solution: Let g(x) = -6x and h(y) = y, we have - ~ -6xdx.
min D
J
= !(x,y,z) = x
2
+ / + Z2
6xy
= 0,
y(O)
=1
y
the equation:
s.t. g(x,y,z)=2x+3y+4z-12=O
Since it is separable, we
fdY
y
=
f -6xdx
In y
+ c :::::> y
= _3x2
= e~3xl+c,
Integrate both sides of where c is a constant.
Plugging in the initial condition y(O) = 1, we have c = 0 and Y = e-J.r'.
Applying the Lagrange multipliers, we have i!f
i!f iJx+A.fu"=2x+21=0 iJj
1 iJj
if
~aj
iJy+/loay=2y+3A.=0
"" D=~(1!)' +(")' 29 29 + (-"-)'_~ 29 -.J29
a: + /loa:= 2x + 41 = 0 2x+3y+4z-12=O In general, for a plane
D=
Idl .Ja2 +b2 +c2
with equation ax + by + CZ = d, the distance
to the origin is
. I equation . B • S 0 Ive or dimary diff I rerentia y ,x= -- - Y
x+y
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 Z = x + y , then the original differential equation is converted to d(z -x) = x-(z -x) c> dz -I = 2x -I ""zdz = 2xdx => fzdz = f2xdx+ dx z dx z
•
=::::}
3.5 Ordinary D'u . I"erentlal Equations
In thi . ~s ~ectlOn, we cover four tical seen In mterviews. YP
.7
di . IfferentJal equation patterns that are commonly
(x+
y)2
= Z2 = 2x2 +c
First-order
=::::}
i
+ 2xy-x2
C
=c
linear differential equations
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 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 IOnsto constrain d I' 46 e non mear optimization problems. 6
7
Hint: Introduce variable z = X+ y.
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)
for y: I(x)y = fI(x)Q(x)dx
and we can integrate both sides to solve
fI(x)Q(x)dx
=:> y
I(x)
T
Thee !mtegratmg ina factor, I(x), must satisfy ' dI(x)
separable differential equation with general solution lex)
- I S I Q( x ) -7' 0 (x)=e
= ef"lX)dt.
=..!.. x
and
= I, we get c = I and
x
I =nx+c::::::>y=
In x + c . x
y = In x+ I
It is easy to show that
homogeneous li
.
complex roots r = -11 2 ±.,J3 /2/ (a = -112,
= e'"
I
(c, cos fix + c2 sin fix)
are
independent
solutions
fJ = .,J3/2),
is
linear
and the general solution to the
h
to t e
= e-lI2x
(c cos( .J3/2x) i
+ c2 sin(..Jj / 2x)).
' ,d'y a dx + b dy hnear equation dx + C = 0, a non homogeneous 2
a second-ordej- differential equation with the form
2
solution
homogenous I e a Un Iik 2
rmear I'y
then the general
linear equations
particular
d
a ± ifi,
Nonhomogeneous
yg(x)
if
,Iyany
numbers
Solution: In this specific case, we have a = b = c = 1 and b' - 4ac = -3 < 0, so we have
equation a d ; dx
Homogeneous linear equations IS
are complex
f2
Y = e'" (c, cos fix +C, sin fix) .
y
x
A homogenous linear '. d' e~atlOn a(x)--?+b(x) dy +c(x),'J,O dx dx '
and f2 are real and 'i = r2 = z-, then the general solution is Y = cle'x + c~)
differential equation is therefore
I
., I(x)(y'+ ?(x)y) = (cry)' = I(x)Q(x) = II x
Plugging in y(l)
fl
What is the solution of ordinary differential equation y"+ Y '+ Y = O?
and we have I(x)Q(x)=-,
Taking integration on both sides , xy -- f(l/)dx x
2. If
:;t:. f2,
It is easy to verify that the general solutions indeed satisfy the homogeneous solutions by taking the first and secondary derivatives of the general solutions.
8
first-order linear equations with P(x)
1"m=l the solution to y"+y'+' y=
y = y,(x)+ y,(x) =
x
IS
norm:
IIXII~~tx" ~.JXTX;
Ilx-yll~J(x-y)'(x-y)
, Then angle B between R" vectors x and y has the property that cos o = II x
___
=
n--
' -
x,
IS.
I
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
+ 1.
L etYI'(x)=mx+n,
between Y and z?
. l. So the particular solution is x-I
e-u" (c, cos( J312x)+ c, sin(J312x))
Solution: We can consider random variables x, y and z as vectors. Let e be the angle between x and y, then we have cos e = PX,y = 0.8. Similarly the angle between x and z is
then we have and
+ (x-I).
e as well.
For Y and z to have the maximum correlation, the angle between them needs to be the smallest. In this case, the minimum angle is 0 (when vector y and z are in the 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. If you still remember all you need is that
.
Y
xillY II" x and y
__
viewed as the cosine of the angle between them in Euclidean space (p = cos e).
e-u" (c, cos( J312x) + c, sin( J312x)) y
L X,Yi = xTy
are orthogonal if xl'y = O. The correlation coefficient of two random variables can be
What is a particular solution for y "+ y'+ Y = I? CI I _ y"+ y'+ Y = I is . ear y y -I
To find a particular solution for y"+y'+
the inner product (or dot product) of two R" vectors x and
product:
1.. 1
y = e-'''' (c, cos( J312x) + c, sin( J312x)).
Y = Y,(x) + Y,(x) =
,
3.6 Linear Algebra
Lm~a~ algeb~a is extensively used in a Ii '. ~tatlshcs, optimization Monte C I . pp e~ quantitative finance because of its role in It is I ,ar 0 sImulation si I . di a so a comprehensive mathematical fi ld ha igna processing, etc. Not surprisingly, lSCUSS several topics that have . .file t at Covers many topics In this section we stgm tcant applications in statis~ics and nume;ical methods.
-, h
UJx __
y 12:..
Vectors
cos(28) = (cos 8)' - (sin 8)' = 0.8' - 0.6' = 0.28
,
0.8
0.6
some trigonometry,
Otherwise, you can solve the problem using Pythagoras's Theorem:
", "
,
0.8x 1.2 = I xh => h ~ 0.96 --,- __
-"'"
Z
cos2B ~ .JI' -0.96'
=
0.28
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 QR decomposi~ion: ~or eac~_f!On-singutar nxn matrix A. there is a unique pair of orthocronal matnx Q and upper-tn·angu Iar matnx · R V.'lt· 11 poSH· ·tve d ·tagonal elements such e that A= QR. 10 QR · 1ar , dccomposjtion . . . is often used to solve linear systems Ax = b when A ·IS a non-smgu 1 matnx. Smce Q IS an orthogonal matrix Q- - Qr d ORx b o~ r . . , an _ == ::::> JU = Q b. Because R 1 an _up~r-tnangular ma~ix, we can begin with xn (the equation is simply ; , ...x" -{Q h)"). and recumvely calculate all X;, V'i == n,n- 1, .. ·, 1. If the progranuning language you arc . d 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?
To minimize the function /(/3), taking the first derivative 11 of f(/3) with respect to
we have f'(f3)=2Xr(Y-X/J)=O:::::>(XTX)/J=XlY, where (XTX) is a pxp 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 using QR decomposition as we described.
=f3nx,,o +Ax" + ... + f3 1x ·
term and x .. . x '·' '
, . •.r '
P-
3. var( c,) == a 2 , i = 1, .. ·, n (constant variance), and E[c,c) = 0, i ;t j ( uncorrelated
:L>.2
c,,
-l, .. ·,n, where x = 1 V'i ;() - '
. . squares regression IS to fmd a set of
'
5.
is the ,· n•erccpt ~~
p =[ n
R
Po • f/1 •
p ]'
... '
r-t
the smallest. Ler s ex . . ,_, · 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, · · ·, &, · n x Wtt each colu · mtercep!) and each row repres f mn representmg a regressor (includ ing the . " en mg an observation. lhen the problem becomes 2 mm f( p) ::: • I! · ~ c. == mm(Y_ X /3)1 (Y II /., P -Xp) that makes
errors). 4. ~~ perfect multicollinearity: p(x,, x)
;t ±1,
where p(x,,x1 )
i ;t j
is the
correlation of regressors x, and x.~.
"if.1
are p- I exogenous regressors.
The goal of the linear least "
•,p-J
+
A
Alternatively, if the programming language has a function for matrix inverse, we can 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): l. T~e relationship between Y and X is linear: Y =X f3 + &. 2. E[&;]==O, "ifi = l ,··· , n.
Solution: The linear least squares re ,· . analysis method Let's . gressiOn lS probably the most widely used statistical · go over a standard app 0 h · . regressions using matrices A . . r ac to so 1vmg linear least squares 1 expressed as · simp e hnear regression with n observations can be Y,
fJ,
•ru·n"
E
and
X;
are independent.
Surely in practjce, some of these assumptions are violated and the simple linear least squares regression is no longer the best linear unbiased estimator (BLUE). Many econometrics books dedicate significant chapters to addressing the effects of assumption violations and corresponding remedies.
Determinant, eigenvalue and eigenvector Determinant: Let A be an nxn matrix with elements {A,), where i , j = l, .. ·, n. The
determinant of A is defi ned as a scalar: det(A) = Ll/l(p)a1.f\ a~.r·l .. .a,,"", where p
p ==(pi> p2' ... , Pn) is any permutation of (1, 2, ... , n); the sum is taken over all n!
possible permutations; and
11
A nonsingulur matrix Q is called . an orthogonal matrix if Q • "' 1 • .. Ill:; ( }Ou are mterested in the Gram-Schmidt process.
~olun ·
To do that. you do need a little knowledge about matrix derivatives. Some o f the importanl derivative
• equat•ons
co
10r
- r.a c:x • r . ca vector·slmalnccs arc -:=-.-11 =a.
err
rx
C'·x' A:c
1.J.•
1
-r~\• •
== 11.
- - "'
o.>:
, (A' + 1) •
x.
,-.• x'.lr c.u {
, - ~ .1.
o_ ( A_x_+_h:..... )'_c...:..·(l_.J.\_.+_!!....:.) n... -= A I ( ' ( v., • e ) + D' ( .' ( .,,...• ,.. b). 12
The m;;;ix inverse introduces large numerical error if the matrix is close to sinaular or badly scaled. 53
Calculus and Linear Algebra A Practical Guide To Quant itative Finance Interviews
~(p)=
1. if p can be coverted to natural order by even number of exchanges { -1, if p can be coverted to natural order by odd number of exchanges .
If matrix
For example, determinants of 2 x 2 and 3x 3 matrices can be calculated as
!
])=ad - be, de{ [:
dct ([:
:
~
A: [~ ~] , what are the eigenvalues and eigenvectors of A?
Solution: This is a simple example of eigenvalues and eigenvectors. Tt can be solved
using three related approaches: Approach A: Apply the definition of eigenvalues and eigenvectors directly.
] ) =aei +bfg +cdh-ceg -afo- bdi l l
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 det(A)
have
Eigenvalue: Let A be an n x n matrix. A real number ..< is called an eigenvalue of A if the.re ~xists. a non~ero. vector x in R" such that Ax = A.x. Every nonzero vector x sausfymg th1s equation ts called an eigenvector of A associated with the eigenvalue l
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.'~ 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 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 · · ·- .• . . · · c ensttc equation of A. Ustng the characteri stic equauon. we can also show that ~A, ... A. =det(A) and f. , ( ~ , L../'-1 =trace A)= ~ A,,. ,,., . .-1 is diagooalizabJe if and onJ if · h · . 1~ .1 , b . Y It as linearly mdependent eigenvectors. · Let . A, • "'2 , · · ·, ;1., e t1le etgenvalues of A • xl . x1• .. . , x, be the corresponding eigenvectors. and X =[x, I x2 ... I x, ), then
,.,
Ax=
[2 21][xx '] = [2x, + x2] =A.x = - A.x, ]=> {2x, + x2 =A.x, J(x, + x~ ) =A.(x, + x2) x + 2x LA.x x + 2x = A.x :::::>
J
2
1
2
2
corresponding normalized eigenvector is
normalized
.J2 , or x, + [1l!../2] 1
t1.J2 eigenvector is [ -l J2 ] and
X2
= A.x, ) and
the
· wh IC' ' l case the = 0 , tn
A. = I (plug x2 = -x, into equation
1
2x1 + x 2 = A.x1 ).
Approach B: Use equation det(A- J..l) = 0. det(A-A./)=0~(2-A.)(2-A)-1=0. Solving the equation, we have ?.., =I and ~
=3.
Applying the eigenvalues to Ax= A.x, we can get the corresponding
eigenvectors. II
de t(A)
~A.,
II
=trace( A)=~ A,,,.
=2x 2- 1 x 1= 3 and trace(A) =2x2 =4.
A, x J":! =3} :::> {A, == 1· So we have ?..,+~=4 ~;::: 3 1
I
2
So either A. =3 , in which case x1 =x 2 (plug A. = 3 into equation 2x1 + x2
Approach C: Use eq uations A,·}":!··· A., = det(A) and
}'t
11
1
2
Aoai n apply the eigenvalues to Ax= A.x, and we e
can get the corresponding eigenvectors.
.
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: • 11 co.actors are often used to calculate detcnnmants 1 " ~::l · • lktenninam can also be appl'ed . . oJ If II 11 . ' to matnx mverse d I' ~n mear equations as well. a eJgi.TJvalucs are real and d' 1· ts met, then the e 1g . · 1 envectors are mdepcndent and A is diagonahzab e. )>
J
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 matrices, all the eigenvalues of A are real numbers. Furthennore, all eigenvectors that belong to distinct eigenvalues of A are orthogonal.
Each of the following conditions is a necessary and sufficie nt condition to make a symmetric matrix A positive semidefinite:
,.
det(P) =1x det = (l- p ~
l p o1.sjl•J +O.Sxdet([o1.8 oP.8]) ([p1 p1 ~ ) -0.8 x det (ro.s r
...1
2
)-
0.8x (0.8 - 0.8p) + 0.8x (0.8p - 0.8) = -0.28 + 1.28p- p 2 ~ 0
(p -l)(p- 0.28) s 0 ~ 0.28 s p
sl
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 . determinants. 16 ·
Let A be a nonsingular n x n matrix. LU decomposWoo expresses A as the product of a lower and upper triangular matri x: A= LU. 17
~ovariance/correlation matrices must also be positive semidefinite. If there is no pcrft:ct hnear ~ependenc~ among random variables, the covariance/correlation matrix must also be P?~JtJve defimte. Each ~f the following conditions is a necessary and sufficient condtt1on to make a symmetnc matrix A positive definite: All eigenvalues of A are positive.
3 · All the upper left (or lower right) submatrices AK K detenninants. '
=
LUx =b ~ Ux = y, Ly b; det(A) =det(L) det(V)
" " =IT L•.. nU ,., ,...
• 11
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.
I. x' Ax > 0 for any nonzero n x 1 vector x .
..,
LU decomposition can be use to solve Ax= b and calculate the determinant of A:
Es~e~tially, it is a LU decomposition with the property L = ur.
= 1 ...
n have positive
Cholesky decomposition is useful in Monte Carlo simulation to generate correlated random variables as shown in tbe following problem:
There are J random variables r d - Th . corrdation between v • d : 'Y an .:.. ~correlation between x and y is 0.8 and the _, an z IS 0.8 What 1s tl · · · · between y and z? · ' le max1mum and m11umum correlatiOn
How do you generate two N(O, I) (standard nonnal distribution) random variables with correlation p if you have a random numbe r generator for standard normal distribution?
Sulurion: The problem can be solved u .·, , .. . . . correlation matrix. smg the POSittve sem1defimteness property of the
Solution: Two N(O, l) random variables x., x2 with a correlatio n p can be generated 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 I 0.8 0.81 P = 0.8 p . [
0.8
p
1
J
x,
=z,
x2
= pz1 + JI - p 2 z~
and cov(xl'x2 ) = cov(z1 ,pz1
11 '
A nee~ ·.sa , b
• ~ I). ut not sufficient, condition ~0 r . l~gattvc dragonal elements. matnx A to be positive st:m iditinitc il thai I ha~ 00
r
=var(zJ =I, var(x2 ) = p 2 var(z,) + 0- p 1 ) va r(z2 ) =I, + .J1~j/z 2 ) = cov(z,.pz,) = P ·
It is easy to confirm that var(x1)
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
•
'' LU decomposition occurs naturally in Gaussian elimination.
56 57
w
Calculus and Linear Algebra
nonnal
distribution
X =[X X . . .
x , ]'
· wtth mean J.l = [J.i, •J11 , · .. ' p,Jr and covariance matrix l: (a n x n positive defi nite matrix) 18 , we can decompose the covariance t · z: · r . _ ma nx tnto R R and generate n independent N(O. J) random vanablcs z,, .:, . .... z . Let vector J'~ 7 " r 19 - - ~~ z2,-· ·,zn , then X can be generated as X =p+RZ.
multivariate
"
l•
•
V(
~ J tJ. 2:)
z _[
Alternatively. X can also be generated . . called singular value d .. usmg another tmponant matrix decomposition r. · • ccomposthon (SVD): For any n x P matrix X there exists a 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 . ' ~ 0 u sparmmg the colum fX 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 or a posttlvc detinue covariance t . . D is the diagonal matrix f . manx, we have V =U and 2: == UDU' . Furthermore. o etgenvalues ; 1 . . . 1 d U . h . . corresponding e· .,, "'2• • "'-,. an IS t e matnx ot n 1gcnvectors. Let DJ ·~ be a d' . jJ; jT;2 ... f) h . •agonal matnx with diagonal elements ~ ' ~ ' ' 'IJ~"·u' t en Jt is clear that D = (DI' 2)2 _ (D' I2)(D"2 )' , d ~ == UD''l(Ulf:> ' . . an · ) · Agam, tf we generate a . · Yariables = f ~ , vector of n mdependent N(O, l) random z" -'· •· .. · z"] · X can be generated as x = +(UD" l)Z. 11
z
Chapter 4 Probability Theory Chances are that you will face at least a couple of probability problems in most quantitative interviews. Probability theory is the foundation of every aspect of quantitative finance. As a result, it has become a popular topic in quantitati ve interviews. Although good intuition and logic can help you solve many of the probability problems, having a thorough understanding of basic probability theory will provide you with clear and concise solutions to most of the problems you are likely to encounter. Furthennore, probability theory is extremely valuable in explaining some of the seeminglycounterintuitive results. Anned with a little knowledge, you will find that many of the interview problems are no more than disguised textbook problems. So we dedicate this chapter to reviewing basic probability theory that is not only broadly tested in interviews but also likel y to be helpful for your futu re career. 1 The knowledge is applied to real interview problems to demonstrate lhe power of probability theory. Nevertheless, the necessity of knowledge in no way dovvnplays the role of intuition and logic. Quite the contrary. common sense and sound judgment are always crucial for analyzing and solving either interview or real-life problems. As you will see in the following sections, all the techniques we discussed in Chapter 2 still play a vital role in 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
' Tile probability densitv of n I . . • lU trvanate nomlal d" 'b . rstn Ut1 on is 1,, In general ·r . • I "" l \ ' h. where .4 and hare consta I lh 58
f t , _ ~:"P t' -
(
l-' - .u)' E (.t- ,ut)
-"-----
( 2~r) d~t' n • en the covariance mat rice l.
. 11: " .I
r
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 knowledoe and shows how it can be applied to a wide range of real Jntervtcw problems. The knowledge used in this chapter is covc::rcd by most introductory probability books. Tl is always helpful to pick_ up one or two classic probability books in case you want to rcfrc::sh your memory on some of the top1cs. My personal favorites are First Cour.~e in Probubility by Sheldon Ross and lntmtluction to Probubilily by Dimitri P. Bertsekas and John N. Tsitsiklis.
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
P(A): ProbabilityofanevcntA, P(A)= LP(a>).
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 coins?2
Au R : Union A v B is th
Solution: We have yet to cover all the powerful tools probability theory offers. What do
Mutually Exclusive: A(") B = where "' . w Is an empty set.
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 ' A and 8 will become symmetric. Not surprisingly, the symmetry will give us a Jot of nice properties. So let's remove the last coin of A and compare the number of heads in A's first n coins with B's n coins. There are three possible outcomes:
Event: A set of outcomes and a subset of the sample space.
· event A or in event 8 (or both). e set o f outcomes In A(") lJ or AB ·· Intersection A(") B (or -'',~B) Is · the set of outcomes in both A and B. .rl'. ·. The complement of A. which is the evem ''not A».
For any mutually exclusive events F. £ ... ,.. '"
2,
J.:. .v
,
r(U NE ) = I.\' P( E ) I
•~I
I
£,:A's n coins have more heads than B's n coins; E1 : A' s n coins have equal number of heads as B's n coins;
•
i=l
Random variable: A function that m· . , . the set of real numbers. aps each outcome (co) 1n the sa mple space (Q ) into
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 omes mapped to a d . the sample space n is 11 ... _ ran om vanable): I, 2, 3, 4, 5, or 6. So 2 4 • t • ·-'· .:>.6} and the p ob bT f · 16 (assummg a fair dice) We . d fi · r a t Ity o each outcome 1s J, · · can e me an event A · 1S an odd number A =={I ., representmg the event that the outcorn~ } h • -'· 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 B ={4, 5. 6}. Then the t . • the e\ ent that the outcome is larger than J: • •mon IS Au B == {I 3 4 c 6 . . . 11 (") B = {5}. One popular rand . ' • · -'~ } and the mtersectton IS ,.. bl ) . om vanable called . d' . \Mta e tor event A is defined . · In Jcator vanable (a binary dummY . as the followmg: = r 1. x E {I. 1 s} . , 1 ~l 0• if ·\" ~ {1• 3• 5l, · Basacally 1 • -- 1 w hen A occurs and I =0 if Ac occurs. The 11 ~.::xpectcd value of 1 is £[/ ] _ p
tr
I
.I
Now• t 1'n1·~... tl~'0 r some examples.
-
(A).
£3 : A's n coins have fewer heads than B's n coins. By symmetry, the probability that A has more heads is equal to the probability that B has more heads. So we have P(£1) = P(E). Let's denote P(£1) = P(£3 ) = x and P(£2 ) = y. Since
L P(o;) = l, we have 2x+ y= 1. For event £1' A will always have more heads
than 8 no matter what A's (n+ l )th coin's side is; for event £3 , A will have no more heads than B no matter what A's (n + !)th coin's side is. For event £ 20 A's (n + l)th coin does make a difference. If it's a head, which happens with probability 0.5, it wi ll make A have more heads than B. So the (n + l )th coi n increases the probability that A has more heads than B by 0.5 y and the total probability that A has more heads is x+0.5y=x+0.5(l-2x) =0.5 whenAhas (n+l) coins.
Card game 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 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 .. 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 ea er pte s a 2 3 winning is ' · or K) · So your probability· of I ( 0
4
48'\
4
Ox 51+51+ .. ·+51) =~x(O+ 1+ .. ·+ 12) =
12x 13 = _!_ 2 · Although th,·s ,· s a stta1g .. hlrOGvard c 17 so l t' · sequence. it is not the most eff · u ton and It elegantly uses the sum of an integer spirits of the coin tossino probt~tent way to solve the problem. If you have got the core different outcomes: o m, you may approach the problem by considering three xSI
4
>
( £ ) == (1- P(E ))I?_ ave(lequal valu c Js · 3/5 I. As a result, the probability · 1 2 - - 3151 )12== 8/i7.
d
£ 2 : Seat # 100 is taken before # J. If any passeng_er takes seat #100 before # 1 is taken, surely you will not end up in you ~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 probability that you end up in your seat is SO%.
In case this over-simplified version of reasoning is not clear to you, consider the following detailed explanation: If the drunk passenger takes# I by chance, then it's clear all the rest of the passengers will have the correct seals. If he takes# I 00, then you will not get your seat. The probabilities that he takes #I or #100 are equal. Otherwise assume 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 new "drunk." guy with designated seat # l. If he chooses # l , all the rest of the passengers will have the correct seats. If he takes #100, then you will not get your seat. (TI1e probabilities that he takes #I or #100 are again equal.) Otherwise he wil l just make another passenger down the line the new "drunk" guy with designated seat # 1 and each new "drunk" guy has equal probability of taking #I or # 100. Since at all jump points there's an equal probability for the "drunk" guy to choose seat #I or 100, by symmetry, the probability that you, as the 1OOth passenger, will seat in# IOO is 0.5.
N points on a circle Given N points dra\.vn randomly on the circumference of a circle, wbat is the probabi lity that they are all within a semicircle't
Drunk passenger A line of 100 airline passe ' 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 random scat ( . r t?e seat number n. Be in d · et s say that the n-th passenger tn go to thd; p cqua 11Y likely for each seat). All 7thrunk. the first person in line picks a choos\: 't fr. ~oper seats unJess it is already oo ~other passengers ate sober and will . · ' cc seat. You'r ccup1ed· In 1 . ' . 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 Solwiun: l.et'sco .d
ns• er seats #I and #I 00 Th · ere are tw0 poss1'blc outcomes:
' ,. . . 1 1111. It you :Jr, I . • · . c rvme to usc ·· 2 > · · · >2n. It is orgaruzed as a 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 assun~c that when .t~o players meet in a game, the player with better skills always wins. What s the;: probabthty that players I and 2 will meet in the final? 8 So!u~ion: Th~r~ ar~ nt least two approaches to soJve the problem. The standard approach ~p~ltcs multJph~atiOn rule ?ased on conditional probability, while a counting approach Is
tar more effic1cnt. (We will cover conditional probability in detail in the next section.)
Let's begin with the conditional probability approach, which is easier to grasp. Since there arc 1" - !)laver· . • s, the tournament w1·11 have n rounds (including the final). For round 1 l, players 2.3,. .. ,2" each have " _ probability to bel's rival, so the probability that 2 1 }" 2 2 (')II I land 2 do not m~et in round 1 is.:___:.__h l d 2 do not 2" _ - x ...n _ -1) · Cond"t' 1 IOn on t at an 1 2 1 1 meet in round 1· ?" - · PJ·ayers proceed to the 2nd round and the conditional probability that I and 2 will not meet in round 2 is
1
T- -2 -_ 2 x (2n,-1 _
2
-1)
n_ 1 _
•
We can repeat the same
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 1 ~- ~2 _ 2 x (2~ -- 1)
- -I - - - I
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 is obvious that 2" players are separated to two 2"- 1 -player subgroups and each group will have one player reaching the final. As shown in Figure 4.28 , for player 2 to reach 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 as player 1 or one of the 2"- 1 players in the subgroup different from player I, the probability that 2 is in a different subgroup from 1 and that I and 2 will meet in the final . . 2"-1 IS stmply " _ . Clearly, the counting approach provides not only a simpler solution but 2 1 also more insight to the problem.
nth round
(n -1 )th round
General Case
I & 2 in the Final
1
I
t
t
+
+
1
?
l + ?
? +
1\ 1\ ?
nth round
(n-J)th round
l
2
1\ 1\ I +
2 +
?
?
?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
.
no meet m rounds 1 and 2;
2"·' players 2"·' players
A
2"" 1 players 2"' 1 players
8 1
he the ~vent that I and ) do not n . 'leet m round I, 2,. .. , n _ 1. AJilply the mtlltiplication ruk. we have Fll
I
P(l and 2 meet in the nth game):::;: P(E) x P(E " ' . . , ., 1 1 , E, )X···xP(E IEE···E) .! X(_ - l) 2x(2" ~ - !) ? ~- I • n -l 1 2 n- l 2"- )
x
'")" I
...
-
l
-- 1)
X···X -~-......:.!...
~ Hint: Consider ""CP'Lrnt· ' • lllg t he pla)•ers. !lame !.!T11 11 l '> Or · - P· not m the same group? 68
- x(2
2l -I
t
o two
2"-1
=2< - l
2· -· subgroups.. What
. happen if player 1 and 2 .111 the
Will
Figure 4.2A The general case of separating 2n players into 2"· -player subgroups; 4.29 The special case with players 1 and 2 in different groups
Application letters You're sending job applications to 5 firms : Morgan Stanley, Lehman Brothers, UBS. 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 personalized to each of these firms. Your 3-year-old tried to be helpful and stuffed each cover letter into each of the envelopes for you. Lnfortunately she randomly put letters 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_ 2! 3! 4! 5! 30 / -'I
Sulurion: This problem is a classic example for the Inclusion-Exclusion Principii:. In tact a more general case is an example in Ross' textbook First Course in Probability.
I
} ) ll 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
1-P(~t )
1
5
is the probability that all letters have the \vtong envelopes. p U
•-1
J
I
£,)can
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 basic principle of counting tells us that there are 365" possible sequences.
P(~E,)= ±P(£)- LP(E, EJ+···+(-ItP(EE ···E) I
1..
I
,·
1 are Pl A) = Ill 000 and p ' turnsuphcads. so J>(BIA)= I (A_ ) ~ 9 99 1 1000. lf the coin is untair. it always · Ifthe com 1s ra·tr. eacb hmc . .1t has 1/2 probability tunllng .
74
I should point out that this simple approach is not the mo_!>1 efficient ~pproach since r am ?isregarding the cases HH and TT. When the coin has high bias (one sid~ •s far more likely than the .other s1d~ to occ~r). 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!Js 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}' ~~ ·
s-
,, lrnt:-:-------condition on th~ I -
resu t of A's fin;ttoss and use S)• m
80
Russian roulette series Let's play a traditional version of Russian roulette. A single bullet is put into a 6chamber revolver. The barrel is randomly spWl so that each chamber is eq ually likely to be under the hammer. Two players take turns to pull the trigger- with the gun unfortunately pointing at one's oWid1ead - without further spinnin~; until the gun goes off and the _e_er~9!:!_ who gets killed loses. If you, one"'fllle playt'rs, cnn cnoosc to go-first 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 Intuition is wrong. Once the barrel is spun, the position of the bullet is fixed. If you go first, you lose if and only if the bullet is in chamber I, J and 5. So the probability that you lose is the same as the second player, 112. In that sense, whether to go first or second does not matter. -
Now, Jet's change the rule slightly. We ·will spin the barrel again after every trigger pull. Will you choose to be the first or the second player? And what is your probabjlity of loss? Solution: The difference is that each run now becomes independent. Assume that the first player's probability of losing is p. then the second player's probabili ty of losing is 1- p. Let's condi tion the probability on the first person's fir~t trigger pull. He has 1/6
pr:oba bility of losing in this run. Otherwise, he essentially becomes the second player in 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 choose to be the second player and have 5/ I 1 probability of losing. lf instead of one bullet, two bullets are ~al}domly put in t~ chan1~r. Your opponent 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?
metry °
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 y~u don ' t spin th_e_ barrel , there are only 5 chambers left and your probability of losing Ln
th1s round (cond1t10ned on that your opponent survived) is 2/5. So you should spin the barrel.
Wb~t if th~ two bullets are randomly put in two consecutive positions? If your opponent surv1ved h1s first round, shouJd you spin the barret?
Solution: Now ~e have _to condition our probability on the fact that the position!> of the two bu llets are consecutive. As shown in Figure 4.3, let's label the em pty chambers as I, 2. 3 and 4; lab~l the o~e_s with bullets 5 and 6. Since your opponent survived the first ro~md, the possible pos1t~on he encountered is I, 2, 3 or 4 wi th equal probability. With 11 ~_ch~?ce. ~he next ?ne IS a _bullet (the position was 4). So if you don' t spin, the chance ~It s~l~vJva! J~ 3/4. It you spm ~he barrel, each position has equal probability of being c lOsul, and your chance of survtval is only 2/3. So you should not spin the barrel.
/~ --
( 0) 8
needs to have one ace, we can distribute the aces first, which has 4! ways. Then we 48! di stri bute the rest 48 cards to 4 players with 12 cards each, which has - -- 12!12!12!12! permutations. So the probability that each of them will have an Ace is
4!x
48!
52!
52 39 26 13
=- x-x- x- . 12!12!12!12! 13!13!13!13! 52 Sl 50 49 +
The logic becomes clearer if we use a conditional probability approach. Let's begin with any one of the four aces; it has probability 52 I 52= 1 of belonging to a pile. TI1e second ace can be any of the remaining 51 cards, among whi ch 39 belong to a pile different from the first ace. So the probability that the second ace is not in the pi le of the first ace is 39 I 51 . Now there are 50 cards left, among wh.ich 26 belong to the other two piles. So the conditional probability that the third ace is in one of the other 2 pi les given the firs t 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
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. .............
~
Figure 4.3 Russian ro~;;:~h tw
0
.
consecutrve bullets.
From any initial state i (the dollars the gambler has}. 0 ~ i ~ N, let P. be the probabili ty 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 Fifty- rwo cards arc randomly d·~ 'b 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 So/wion: The problem can be . . . answered usmg st d d · 'b te 52 cards 1 4 . an ar counting methods. ·1o d1strt u 1 . o p ayers With 13 cards each h 52' as ! ! · !IJ! permutations. . · . 1f l:UC -. h player 13 13
!L
2
P = pPa) + qP => P~ ~~ - P = p =(!L p. ) cP,_, I
I -·J
1
1
I
We also have the boundary probabilities Po
P.-) ) =.. · =(!L)' p u=: - ~ )
= 0 and P_, =1·
So starting from ~,we can successively evaluate P, as an expression of ~ :
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..!..= .!. .
·-
P4.2 = P( (4,2) I (3, l)) XP31+ P((4,2) I (3,2)) X Pn ' ··-
3 2
2
3
= ]_ 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 ntotal probability can be used in the induction step. Extending this expression to p·" 'we I1avc
Induction
)_=l'r + i.p +... + (!!._p J·' -~] p, -.- J1--qcq pp)'\ ~' . q p :;: t l N~,
' ·" - I
1
I
I
if I
ifq lp=l
::::>
~=
1-qlp • I - (q I p )"' , l[ q I p l . ~P, { li N · ifq l p=l
'*
{
=
I
·r
l - ( q I p) p l - (qlpt "~ p:t:JI2 i iN .
,
ifp=l/2
A bask(!tball player is takino 100 ~· through the Itoop and zero point e . . 1f . the ball passes . ·rJ.fCe sl throws . · She scores one pomt 1 m1ssed . ~ 0.11 her second. I·•or each of th· 1e.... mtsses ll . · Sh • e has scored on her first throw and I1c traction of th rows s 1e has made soe far tthe !O ·OWJno throw th b b' · · · F e . _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 11 5~~\-\sk(mcl,~dtng the first and the se~o~:)J 11. ~cor.e tn the 41th throw is 23/40. After !00 as ·cts'?" · · · w at IS the probability that she scon;s exactly Solution: Let (n k ) 1< k tlmn... s d p ' · - s; 11 · be the event that the 1 . an n.t P ( (n. k )) Th . . P ayer scores k baskets after n . · e solut1on 15 su · · 1 . . . • ~J . 3 ~proac t starting with n = Th . (pn smg YSi mple 1f we use t} · 1 a ng lt-continuous function.
23 ·
..,
r·· o ·
''tochastic Pr(lcess'' by Robert G. Gallager. ·
fbe residual life is explained in Chapter J o · tscrete ~.,
91
-Probability Theory
and .\lr(O) =E[X" ], Vn 2:.1 in general.
Conditional expectation and variance
We can use this property to solve E[X"] for X~ N(O, I).
distribution M (I)= E[e'x ] = [ e'.c
,!.-- e-·'
2
'2 dx:::
v2n
(};e-1'
~
1
For standard normal
/12 [-1-e-< ,_, / n d.,'(= e' 'z . ~
,·
For discrete distribution: E[g(X) IY = y] = _Ig(x)pxj) {xI y) = Lg(x)p(X ~\' I Y = y) .t
Law of total expectation:
isthe pdfof normal distribution X -N(t, 1)-so (f(x)dx= l ).
L E(X I Y =y]p(Y =y), for discrete Y E[X] =£[£(X I Y]) =
{[
'
=te
_r
For continuous distribution: E[g(X) I Y = y] = [g(x)fYJr (x I y)dx
~M'(0) = 0,M"(t)=e,. ·~ +t 1/n :::::>M"(0)=eo=l ,
,: I '
.,
1
Taki ng derivatives, we have '( ) :\ ·/ I
A Practical Guide To Quantitative Finance Interviews I I 0 l I { • ~J u 1 ' " v '-' _
Y
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,
Connecting noodles
1 • and M4(t ) =3e'I "- +3re~" · 2 +3t 2e•' .-2 +3t4e'l'2=> M4(0)=3eo =3.
4.5 Expected Value, Variance & Covariance ~xpcctcd valu~:, variance and covariance
. . . . nsks of any im·estments. Natu . are md!spensable Jn estimating returns and The basic knowlcduc inclltde rtah11~.t11ey .ate a popular test subject in interviews as well. :=s e tO11owmg: If £lx, , . l is fini te for all ; = 1· . .. ,n. then E[X +· ··+X ]-E[X] E[X] The re\attOnship holdS whether the , , . . I n I + .. • + . . x, s me tndependent of each other or not. lf .\ and r arlo! indcpendcn lh . t. en E[g(X)h(Y)] = E[g(x)]E[h(Y)]. Covariance : tfn•(X }') _ 1:;[ X . - ( -E[X])(Y-EIY])]=E[XY]-E[X]E[Y]. II
Corrclatiun: p( ..\'.Y) =
I
I
J
'
J•
M
r
J·llr( '\..., \' ) f....1 ~ , =
•I
1.--f
Var(X) '
11li! ~\crsc b not tme
92
"! I
4x3 = 6
combinations. Among them , 2 combinations will connect both ends of the same noodle together and yield 1 circle and 1 noodle. The other 4 choices will yield a single noodle.
p(X .Y) == 0. 26
We now move on to 3 noodles with ( 6 ) :::
,2
~ . : 15 choices. Among them. 3 choices 2
will yield l circle and 2 noodles; the other 12 choices will yieJd 2 noodles only. so I •
y )
£[[(3)] =3115 X (1 + E[f(2)]) + 12/15 X £[/(2))::: 1/5 + £[/(2)] = 115 +I / 3 + I .
I
·ILL Cov(X
"" -
(4 l
£[f(2)] =2 / 6x (l + £[[(1)]) + 4/6 x £[/(I)]= 1/3 + £[/(I)J = 1/ 3 + I .
General rules of "ariaoce and cov 0 • So Indced \VI'et1 h a • the hedge portfolio has the minimum eh: - -u /J ' = P~. O'H ntriance.
Therefore, E[X] = 1 +
Tl)
~..
Dice game Suppos~ that you roll a dice. for . h
. . 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~
48
L E[X,] = 1+ 48/5 =10.6 . t=l
This is just a special case for random ordering of m ordinary cards and n special cards.
"'
t=l
Sum of ra ndom variables Assume that X X . . . and X are independent and identically-distributed (liD) 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 . •· " o l e aw oft · 1 · Clearlv your payoff wtll · be dtlkrcm dcpendinc on' "the ~ ota expectation. 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 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 • • , • ace v.t ue 2. so £[X I y e {1,2.3} I == 2: you have
m
The expected position of the first special card is 1+ LEl XJ = I +-;;+~ ·
•
· w8 ld' ?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
ny !8
in Chapter 5 i ualitv d ' 1formuia and prove it using a genera 10
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 though it may not give you the (ina! answer. When n = I , P( S1 $ 1) is I. As shown in
1- X
Figure 4.6, when n = 2, the probability that X 1 +X 2 ~ I is just the area under
wehave P( S
X I+
x2.$ 1 'v\'ithin the square with side length
the probability becomes the tetrahedron A BCD under the piane X 1 +X2 +X 1 ~I 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 to induction. I'(S,," .S I) == 1/(n+ I)! .
I'
So its volume should be (1 -
, ..,1
I (a triangle). So P(S"l ~ l) = 1/ 2. When
n = 3,
resort
,.
Assume P(S, ~ 1) =1I n!.
We
need
to
prove
that
~ I)=
x n+ l )"
n!
r(l-Xn+lr dX ..b n! , .. ,
=J._[ n!
instead
of~n!
Plugging in these results,
(l - .,.¥,.,)".. ']' n+i
0
=J..x - 1-
n! n +l
=-(n+l)!
So the general result is true for n + 1 as well and we have P(S, $1) =J I n!.
Coupon collection 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
.'
Solution: For part A, let
'
X~_,
'I'.
to obtain the i-th type after (i -1) distinct types have been collected. So the total number
I
I
• '•
N
0
'
B
0
x,, i =1, 2, ... , N, be the number of additional coupons needed
of coupons needed is X =X,+ X 2 +··· +XN =LX,
I
I
'...
-tJ. .. ~.; ·-•··---· -~)..# -
.-·#
·······-..
0
n=2 Figure 4.6 Probabil ity that Sns 1 when n = 2 or n= 3 .
n=3
,;,
·
For any i , i -1 distinct types of coupons have alread~ _been co_llected. It follo~s that a new coupon will be of a different type with probab1ltty l - (J - 1) / N=(N - t+l) / ~. Essentially to obtai n the i·th di stinct type, the random variable X, follows a geometric 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 '( \; ~ ,, 1 / · • ~ I ) = j/(X 1 )P(S < 1- X . • • • "' ~~ )dX" ..'' where /(X,,. 1) is the probabili ty denstl) 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
'I
1
'
You Ca ll lkrivc I! b
integrat1on: .
r
J, A( _ cl.· _
k
• An n-Simpl · · ~ . . 1 · ) • - l / 2:"dz '= I! 6 . where A(:) is the cross-sectional areJ. c\ ll> t ll·dlm\!nSJonal analog of a triangle.
96
N
:. E( X]= L E[X,]= ial
I
N
i=l
( 1 I 1) . =N -+ N-l +· "+). N- +J \ N N I
· ll ted to get the i-th distinct coupon after Hmt : For part A let X be the number of extra coupons co ec . ' ' h 1expected number of coupons to collect t-1 types of distinct coupons have been collected. Then t e tota . ... . . 1 pected probability (P) that the Hh all distinct types is .E[X] = E[X,] . For part B. wh1ch 1s n e ex 31
2: tal
coupon type is not in the n coupons'? 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 introd uce indicator random variables I, , i =I, 2, · · ·, N , where
P(A or B defaults)= E[I 11 ] + E[J 8 ] - E{l AI 11 ) = 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 =0.65- JOij f2pAIJ
PA11a ,laB)
N
So we have Y == 11 + 12 + .. ·+ 1., =
Ll,
For the maximum probability, we have 0.65- J05i 12pAH
•• I
For each collected coupon, the probability that it is not the i~th coupon type is A~\~ 1. Since all n coupons are independent. the probability that none of then coupons is the i~th coupon type is P(l,
=
N -1 \ " and we have £[1 ] = P(l = l) = 1_ ( N -l \ I" . 0) = ( --=-) N N ) I
,.
I
For the minimum probability, we have 0.65- Jo.2J 12pAR = 0.5 => PAn = J3i7 ·
In this problem, do not start with P(A or B defaults) = 0.65- Jo.2I 12p,us and try to .set pAIJ
=±1 to
cannot be ±t . The range of correlation is restricted to [ -.J3i7, .J3i7] ·
.32
4.6 Order Statistics . dtstn . 'button · rtunc( JOn F.r (r) Let X be a random variable with cumulattve · · We can derive . . yn = mrn · (X 1' X 2' ... • X " ) and for the maximum the distribution function for the rmmmum
Joint default probability
=max(X
lf there is a 5?% probability that bond A will default next year and a 30% probability 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?
Z11
~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;
P(Z"
Solutio:: The nmge.
~ h~;~·~; d~·.ta~hs. A does not default. So the maximum prob~bili ty that at 1east one ~1 aults
)0% + 30% =: 80%. (The result only appl ies if P(A) + P(B) 51). For the ~-~,~~ .muml ' ·we can assum~ whenever A defaults, B also defaults. So the minimum pro, ,aut ny t lat at least one bond defaults is 50~ .
1
IS
o.
• To colculmc the con·espo ct· n mg corre1atton. let I, and I 11 be the indicator for the event that bond AlB defaults ne ·t d · . ' x year an P 11 be their correlation. Then we have l:.l/ ' I = Cl 5 £f I 1- 0 " •
J
A
· •
calculate the maximum and minimum probability since the correlahon
(N -t)"
:. E[YJ :::; LE[I, l = N- N - •1 N
on
=0.8 =>PAn= -J3i7 ·
•l
-
·"·
varU.J=p.~ x(l - p_4 ) ==0.25,var(J )=0.21.
8
p
X 2' ... , / v\n ) of n liD random variables with cdf Fx(x)as
P(~, ~ x) = (P(X ~ x )t => 1- Fr. (x) = (1- Fx(x))"
::::> fr. (x) = nf~. (x)(l - F:\. (x))" ~'
~ x) =(P(X :f, x))" => Fz. (x) =CF.r (x))" ::::> f z. (x) = nfx(x)(F,. (x))"-'
Expected value of max and min . ·r d ·1stribution between 0• and I. Let X X ... X be liD random variables WJth umJorm • • r> 2> ' " • • h robability density functton and What are the cumulative distributiOn functiOn. 1 e p th . ulativc distribution expected value of Z, =ma-x(X" X 21 .... X , )?• What are e cum . X v · ... X)'' . the probability density . function · and expec' t cd value off" =mm( ,. ~\ ? · ' •· · functton,
·l -d For uniform distribution on [O,Jj · X . . . \' ) we Solution: This is a direct test of textbook know e ge. ·( 1 Fx(X)=x and fx(x)= l. Applying F.r(x) and fr(x)to Z, = max." 2• •• " have
511'lilar tJu~~tion: if ) ou randomlv put 18 b II . I' · a s rnto I 0 boxes, what is the expected nurnber of emp >
hox~s .
99
Probability Theory
and E[ZJ=
A Practical Guide To Quantitative Pinance Interviews
J.r/ f2. (x)dx=
r
"dx n [ II+ .bnx = n+l x
I]' = n+l n ·
I
0
r;, =min(XpX 2 ,-··,X,J we have
Applying F.vz, P(Y~y jZ$;z)=O. For y~z, that X, X 2 , we always have yz =X1X2 ( z '=' max( x" x2) and y =min(xwtJ ). :. £(Yl] =
£! x x dx dr =E(X,]E[X~ ] =2x2 =4· 1 I
1 2
1
I
2
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.
direction, simply set x expected va Iue ('tOr .tt to tir.atl off is J·ust x. min. ff it goes in the• other . 10 1_ x. So the original problem is eqwvalent to the followmg. . . · f_._ 500___ JID random .variables Wltat is the expected value of the maxtmUil!.Q. . .with untform distribution bet wecn-O.and 1?
. ~9 · \\,h.ch is the expected time for all ants to fall off the 1 Clearly the answer IS ~ mm, 50ostring.
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. I li ' H ~ core co II" JSJOn: __,;___H_.....;;.,_: Atier collision: ~~; switch label : ~ 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
~
1
hnt: If we swikh happ~ncJ. 102
th~ label of two ants that collide with each other• it's. like that the collision ne\'er 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 i,, .p i , and
=j
11-P
. ..
>
X0
=i0 } =p IJ = p!lX 1 =j 1 X n = i} tH·
for all n, i0 ,
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) •
Transition matrlx: p ::: {
P,,} =
p"
P 12
Pt \t
PJI
P 22
P 1\f
P111
Plo
PM\f
. where p,,
IS
the transition
probability from state i to state j. •. (
Initial probabilities: P(X
0
)
1 =(P(X0 =l), P(X0 =2), ... , P(Xo = \rl)) · L 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• ·• • 001 change over time). IS chapter,
-------------------------------------------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
i =
0.5
2
0
J
P=
0.5
3
4
0
0.5
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
......
LPJ.1 m
u I
J.l, =I +
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.5
0
0 .25
0 .25
2
0
0.4
0.4
0.2
3
0
0
0
9
fo r all transient states i. These equations can be easily deri ved using the
1
j =l
4
GamblerJs ruin problem
Figure 5.1 Transition graph and transition .. matrix of the Play
Classification of states Sta teJ· IS · accessible from state i if th . . j { 3n such that p > 0). Let T _er~ IS a dtrected path in the transition graph from i to ., v , -mm(n·X - ·1 x . ) < 1 ). In Figure 5 I only stat~ 4 is · ' - " -' ar~ a11 tra · · · ' "' not acccsstole from4. nslent smce 4 is accessible from l/2/3, but t/2/3 are Absorbing Markov "··ha1ns , .. A st·n · · 1 IS called absorb· 0 · • • • . state ( p _ 1 p _ () '..I. · · • • l' " ' '' - ' v.f ~ i ). A Markov d · . 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 . 10 4 IS an ahsorhin' . . \: J1 IS po~stble to go to a b . e · g ~tate. The corr~spondinn M· ·k 0 a. s~rbwg state. In Figurr.: 5. 1, state · Markov chain. F...quatiOJ Js· t-1 or ahsorprion rob· . . e . { a, = 417 "2
=113xa1 +2/3xl
02
=617
Dice question 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 playl'rs h·L'p rolling the d·. ayder ets that two consecutive 7s will occur first. The tee an record the sums u f 1 . . 1 probabilit y that A wi ll win? n I one Payer wms. What IS the Solutiun: Many of the simple 1M k . conditional probability argumen! Ita~s ~:t cham ~roblems_ can be solved using pure ddin~d as condit ~onal probability.: surpnsmg constdering that Markov chain is 0
11
-
•
,.
-
I,· 1, · · ·, ./\v 0
= i0 } =. pIJ
=7)P(F =7)+ P(A I F~ {7, 12})P(F ~ {7,12})
= 1 X 1/ 36 + 6/36 X (1/36 + 29 136P(A)) + 29 136P(A)
Solving the equation, we get P(A) = 7 113.
So, starting from $1, player M has 4/7 probability of winning.
P:xn I - 1· I X - i X
P(A) = P(A IF= i2)P(F =12)+ P(A l F
= P{X
_ .
11• 1 - )
. I X, = I}.
So let's first solve lhe problem usino con . . .. pwhability that ·1 win. C d. . . 0 dihonal probability arguments. Let P(A) be the ' !). on tltontng P(A) fi on t 11e lrst throw's sum F, which has three po..;sibk· outcomes F = F_ 12 ' - 7 and Fe {7,12}, we have P(. 1) = P(.l l F == l 2)P(F = 12) + P( 'l IF - 7 ' ~ )P(F = 7) + P(A I F e (7, 12} )P(F li: {7, 12} ) Then WI.! tackle each com .. . ponent on the nght hand .d U . . . (,Ill eastly see that P( F = _ Sl e. smg Slmple pem1Utat10n, "'e 12) = 1136 is obvious that P( ,1 .~ _ I~) · P(F - 7) = 6136, P(F ~ {7, 12}) = 29/36. Also il • 1 L = 1 and P(A 1 F starts 0\'1..'1' again.) To calculat, f( I cli: {7, 12}) =P(A). (The game l:Ssentially c t: A r = 7) W d f
1
thrnw·s totn l. ~hich a"ain has thr •e . · e nee to urther cond iti on on the second o .: possthle outcomes: E === 12 £ - 7 p, •I F . 7) p · - . 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) _ ) . - . ~{7.12})J>(£~{7, 1 2} ; F=7) - I ( ..J II· = 7,E-=1 2)x l /3 6+P( ;l l f '-7 E 7
=
, . - ' · = )x6 / 36 + P(.-I rf = 7.£ e(7.12} )x29 / 36 - 1X l / 36 + 0 X 6 / 36 P( .. + :1)x 291-> 6 = i i36 +29136P(A)
lien: the · ·cond . . relies on th , · d . cquat1on rolls. II J. =7 and £ - 12 A . \,; 1.n ependence between the second and tl1c lirst - · wms: tf F = 7 . ' and E = 7, A loses: if F = 7 and
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: 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 no 12 or 7-7 occurred). Do we need any other states? Theoretically, you can have other states. In fact, you can use all combination of the outcomes of one roll and two consecutive rolls as states to construct a transition matrix and you will get the same final result. Neverthe less, we want to consolidate as many equivalent states as possible. As we just discussed in the conditional probability approach, if no 12 has occurred and the most recent roll did not yield 7, we essentially go back to the initial starting stateS. So all we need are states S, 7, 7·7 and 12. The transition graph and probability to reach state 12 are sho\\'0 in Figure 5.3.
6136 ®)I 7
Probability to absorption statt 12
a," =I. a7_ 7 = 0 as== I / 36 x 1+ 6/36 xa1 + 29/36 x a_, a1 := l/36 x 1+ 6/36 x 0 + 29/36 x a..
:::>a~ -= 7113
Figure 5.3 Transition graph and probability to absorption for dice rolls
Here the transition probability is again derived from conditional probability arguments. Yet the transition graph makes the process crystal clear.
Coin triplets Pan A lf . . . h · th xpected number of tosses such · you keep on tossmg a fau com. w at ts e e . of that you can have HHH (heads heads heads) in a row? What IS the expected number tosses to have THH (tails heads heads) in a row? Soh11 · • • to choose the right state /On: The most difticult part of Markov cham IS, agatn, d [! space. For the HHH sequence, the state space is straightforward. We only neeb f?u~ states· S' (f' · · d ,,,henevcr a T turns up e ore H! · or the starting state when no com 1~ tossc or fH), II, HH, and HHH. The transition graph IS 0
108 109
Srochaslic Procc~s and Stochastic Calculus
A Practical Guide To Quantitative Finance Interviews
~~~~~a~~ ~-i, ~~;~~~at~o~:~~~~:he state wi II st~y at S when the. t~ss gives a T.
Jf the toss the n~:xt toss is T othe . . H. At state H, Jt has 1/2 probabJ lJty goes back to stateS if · • 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.
w~ have the follmving transition probabilities: P.. ,. = _1, f~, ., - ~· p -- I n I d ''•·' • ''r( • · .1'"' · ' -· '· r 111., · w 111 -"' ,- , an pHI/If IIIII/ -1 ' •
P.
So
1
_
.\'.If -
o
1
1
2' •
_
H.S -
.•
- I'
)
I
II
p,, r +J. u . . , _" 2 l!tl .
- 1" ,\
)J!IU -
1
+
l + J.l, + f.J,,,
.u1/1/(1 = 0
I
I=:>
Jls
= !4
JIH
= 12
) " ill/If
o
=0
@
= I + .Lp +L ! .~ 2 fiT
p,' =l+.Lu 2 rr
/.. =J+.l.
J. ru
j.ll'H/1
2
f.l,
+.111 , r ·11., I
+I
JlnrH
l Ir fl' ·-- 8
1
=>
=0
l I
11 rJ
J.l"'
II
I' /HI/
- 4
-
=2 =0
,
@
@
Ql
@)
Figure 5.4 Transition graph of coin tosses to reach HHH or THH
We want to get the probability to reach absorbing state HHH from the starting state S. Applying the equations for abso rption probability, we have
Q T
p.·'
C' , .
(f)
A
'-.Ja/~ 1/2
·
'
So !l·on, the startin!l stall'S. the ~x
~(J~AA
l~@
a~ :::.la +.la
expected number of tosses to get HHH is 14. Snllllarly for exp~cted time to . h T gruph ~nd ~stimat~ the correspo ~~ac . HH, w~ can construct the following transition n mg expected lime to absorption: .
1/2
aHim =I, a'I'HH = 0
So from the startincr state rhe ,.
~n
l'
=8
JIHH
1/2
1
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 expcctt'd ti,;J~ to ·tbsorp' ,. U1 rohm state S. Applying the standard equations for the ' ton, we ave J.l,, - l 'l" +j(. + t iJ
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 these states, we can build the following transition graph:
2 1'
::;;;la
2 I'
2
ar
=O,arH = 0 I
as =s
H
+I I I "'i'aJ'H , aH = l ( IT +TaHH
a," 1 == 12 aI' + 2'1 a1'HH > aHH --
12 a I'
+ 21 aHHH
I
aH
== :r
_, aIll! -2
So the probability that we end up with the HHH pattern is 1/8. 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· · 1· h · tl e hrst two coms m 1'he reason is that the last two ~ coins in THH IS HH, w uc 15 1 .'. sequence HHH. In fact the onlv way that the sequence reaches state llll/-1 before /HI~ ·18 ' ~ · alwl)'S bnve a 1 that we get three consecutive Hs in the beginning. Otherwise. we ' · ' . · ... H fi s ·r w · don't start the com b t' 0 1 e ore the first HH sequence and always end m TH Irst. ~ THH Hipping sequence with HHH which has a probability of 1/8, we will always have before HHH. '
, p ctcd num.her of tosses to t~"Ct TuH . 8. u . IS
Pan 8 Ke~.:p n· · .. . ~ 11 • · . . tppmg n f I = v (-o. h ) The proof is ior 1i th path (() 11 ' t0 ( '· ~) h " . • • • ' "· "~· ' cn.:tsaone-to-onecorrespondingpathfrom (0. -o) to (k.OJ.
ds in a row + l)H ) must be n hca n . . w (denoted as ( nH. The state before (n + 1) heads m a ro l ?"+' _ 2 tosses to rc·teh • f (the new toss t··d £[ f(n) ==(denoted as nH ). lt takes an ex pee c b.l· 't ' it will go to (n + l)rc . the U2 proba 1 1) t ·t w1l1 go to · 1 Conditioned on state nH. there ts a . probability t11a . There tS also a 112 Yields H) and the process stops. 119
A Practical Guide To Quantitative Finance Interviews
Stochastic Process and Stochastic Calculus
swning sLate 0 (toe new toss yields 7) and we e to reach (n +l) f-l. Sowehave n edanother expected E[j(n+l )] tosses
26• All the (i- 6) players before him went bankrupt; the (i - 4)th player loses in the second toss (HT); the (i - 3)th player and the (i- 2)th player lose jn the first toss (1);
£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
payoff 2.
_
2
2
G~n~.:ral
Martingale approach: Let's use HH · · · H to explaLn . 1 expct:h:J time 10 get an . n a genera approach for the9 . Y com sequence by exploring th . . a gambler has $ 1 to b e stopping ttmes of martingales. Imagme . et on a seq uence of n h d ( HH . . 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 . •. . . . IS money (unless he go b - example .1f II .tpp....u:s at the first game he w'lll $ es ank rupt). l·or . e1ther . , he 1I mve 2 and he will pu t a II $2 tnto . ' He ·st op:-;. PI·£[i] =2"+J _2 rhh a_pproach can be .. . 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)' a · usc a stopped ~ ~.:mcnts · -!!~lllbl. . ·. ". ~:can 'gam 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 t: etorc each t ) b ., Sl!tjuence st .. , ~ gJm ll!r b~comes the f . ( ss to ct on the same sequcnc'. op:> alter lhe i·th toss th. c· - trst to get the sequence 1/HTTHH. If the •• \: 1 - ) )th g 9 lf . ~am blcr gets the HHTTHH wjth payot1' ',
I
-
mur··' U.ll...,, 'I n.. ~ou prdN . 'l:i .II li 'tho ~~o url'\.·n~o:t: of s • ut 1 I·1 ~ :tJ')pro·tch 1ease refer 10 I'rrww•illll L .. , , cquenl:e P·m ·r ' ·P , Vol 8 n-; Ill E"p .
·
120
·
~ r:_~ · o. (• ~c 6
··
R~peatcd I980)
1
·'A Mart1ngale . Approach to the StudYl f . , enment.s" b Sf · · Li. The AnntJ.,. l c~:i • PP l l71- 117o. ) 1uo-Yen Robert
Hence, £[(x1 - i)] = 26 + 2 2 + 21 - E[i] =0 => E[i] = 70.
5.3 Dynamic Programming Dynamic Programming refers to a collection of general methods developed to solve sequential, or multi-stage, decision problems. 10 lt is an extremely versatile tool with applications in fields such as finance, supply chain management and airline scheduling. Although theoretically simple, mastering dynamic programming algorithms requires extensive mathematical prerequisites and rigorous logic. As a result, it is often perceived to be one of the most difficult graduate level courses. :ortu~ately, the dynamic progranuning problems you are likely to enco~nter in mtcrv1ews- although you often may not recognize them as su~h-are ~dtmenta':Y problems. So in this section we will focus on the basic Jogtc used tn dynamic programming and apply it to several interview problems. Hopefully the solutions to these examples will convey the gist and the power of dynamic programming. Adiscrete-time dynamic progranuning model includes two inherent components: 1. The underlying d iscre te-time d ynamic system 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
d)~namic
stag~s ~ith dcc~s~on
at one stage transforms the current state into a state in the next stage (at some stagc.!s and :>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 label these stages as 0. I, . .. , N -1, N. At any stage k. 0 ~ k ~ N -1. tbc state transit: Jon can he expressed as x = ((x u w ) where x .. is the state of systt!m at stagl! k: uk •
IS the
k~J
.
/c'
k,
4 '
•
decision selected at stage k, wk is a random parameter (also called di sturbance).
. . . • ·n , For up-to-date at all other stages gk (xk> uk, wk) can depend on xk , uk, and wk. So the total N-\
cusuprofit is R ~ (xA )+ L g4 (x~.,ut , wk,l} . j ·'
Th\! gunl of optimization is to select strategies/policies for the deci sion sequenl~
n• fun*,- ... 11 . ,*}that minimize expected cost (or maximize expected profit):
Dice game You can roll a 6-side dice up to 3 times. After the firs t or the second !oil, if Y?u get a number x you can decide either to get x dollars or to choose to conlmue rolltng. ~ut · · strol led · If you gel to the. thtrd once vou 'decide to contmue, you forgo .1u1e number you JU ron. ymi1Tl JUSI get-X do1fais if the third number is X and the game stops. What IS the game worth and what is your strategy? • • • • • 1 strategy game l- all-dvnamic Solulion: Thts IS a stmple dynamtc programmmg · A'·--:-- . . . h h ti 1 t·tge und work backwards. tor programming questions the key 1s to start_~1t t e tna s' __ . , ' ... --- - ~ th. first two rolls It becomes a - . -- this quest10n, It 1s tne.. stage where you have torgone c d · h have a i/6 simple dice game with one roll. Fa_c~~s 1, 2, 3, 4, 5, an 6 eac probability and your expected payoff~~§~ · t after the second roll, for 1h 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, ~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 face value is 1, 2, 3 or 4) or keep the current face v~lue. tu~c y ~o~ou stop rolling. So 0 value if it is larger than 4.25; In other w~rds, when y:u 7~x(S ~ )=$14/3. your expected payoff before the first rollts 4 I 6 x 4.25 . . . . . d namic prooramming- gtvcs us the Thts backward approach-called tail pohcy m Y . . . c • $l 13 •1 at the mtlla1stage, 4 · strategy and also the expected value ott 1e game
s·
Dynamic programming (DP) algorithm The. c.l yn.amie progmnuning algorithm relies on an idea called the Principle of Optamah tv: If It*-= r111 • • 11 *} · h . . . " • • • • :. _, ~ 1s t e optunal policy for the ongmal dynamic·, program mmg problem, thea the taj l policy "• = {u "'· .. . u *} must be optimal for tht> I
.
I
'
\' I
tlt~ic:s unJ ~:ost-to-•'o fun . . . ·v. the DP algorithm is applied.
:e I
I :!2
1
6
World series .. . Ia in in the World Series finals. In I he Boston Red Sox and the Colorado Rocktes are P Y g . ·mltm of 7 g'an1cs and · there are a m,lxt S case you are not familiar with the World enes, . h. You have $100 dollar~ to lhc fi rst team that wins 4 games claims the champiOnS tp. ~~a-~~ a double-or-nothing bet on the Red So~ . . •l ol· How ot the cocrtCS as a \\ l t:. U01(' · d. ·d · l game n ·' · onunately you can only bet on each Ill lVI ua · · the •vbolc series, you wm ' ·f h Red Sox wt ns much should you bet on each game so that 1 t e Q? 0 exactly $100, and if Red Sox loses, you lose exactly$ ) · · mes and the . . ed So:< has won t ga .\ulut~ a Wiener rowman motion is often denoted as B Alternatively 1 IS . 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 )
1
1
ed . denot as
rJ' (/)
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 sketch for the exponential martin~a_le is the following: 2
£[ Z(t + s)] =E[exp {A (YII(I)~!v (s)) -t A, 2 (1 + s)} J
· p·tgure 5·)0- When we .have 81 >0 and This approach is better demoostrated m B - B 0 and B < 0? 2
1
~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 1 2 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) _ f'
- j,
r
I
Ji;e
r·.f I , -(.\" ~ &e•,l '/ldy::
_,~ , l
r[
1
r
~
0
?
-fr
e
_,J ll
]Y .• = .!_ 8 0
But do \\c really ne 1tl · · 8 el tc llltegratton step? If we fully take advantaoe of the facts that and B.- R1 arc two liD \'(0 I) o .. . d -J ' • • the answer is no. Using conditionaJ probabJllty X~ ,\
VI
2
I
l
2m
,
'V X > U.
h om part .'\. it's ea ~ t0 1 . 1, li I ~Y s ) O\\ t hll th~ e:xpl.!cted stopping time to reach either a ( a>
or .. t1 ( P> 0 ) i~ again
E[r;]-- afJ' · ·rh c
· 1 1el r is expected first passage tune to e' ·
clX(t)==mdt+dW(t )? " . beth~ probability that the (. • · · artingale. Let p, · t. · is 't ootution: A Brownian motwn 1s a 111 • d at a stopp1ng tm~ • stoppe .. lk Jf \\C Bro\~nian motion hits 3 before -5. S.1 ~ce a matttngale P, =SI S . Similar to random. \\a · . martmgalc we have 3~ + (-5)(1 - ~)- 0 ==> ~ h babilit): that 1t stops at 1.1 ' . p > 0 ). t e pro . -n have stopping boundaries (a> 0) and - {J ( · . · e to reach ctther a or 1' . . ed toppmg um Instead of -fl is Pu = fJ /(a + fJ). 1 he expect s IS again
I
I.
I" ~ tll'line .Ifi ll
II l th
r~'lft ou \
•
"" ..... II I
•.
I I!
•'
r'
· •
d .
I hell
PI
. ) .1f
r sr
d an only if
\4f t) ?
. f PI
c. -e e -e ' c = I /(e-ow -e Jn., ) I!J;" /( ..(,, ,
I Om )
:.:::> P(O) = c1 + c2 =
e
- e~ = - d2 - O'.j; = -d
1
and we have
LJ2;
_J_e- i:l t2di =Se'rN(d,) ,
d,
K[ _!_e-~' 2 de = K(l-N(-d 2 ))= KN(d2)
Jl &
:. E[V(T)] = Se'r N( d, )- KN(d 2 ) and V(t)
Ke -rr N(d2) 1 =e ·trE [V(T)] -- SN(d)-
•
. . .· that t -N(-d1) == N(d2) is the nskFrom the derivation process, It IS also obv ious · neutral probability that the call option finishes in the money. ~ European call option on a nonC. 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 equations (PDE). One approach to solving the problem is to convert the Black-ScholesMerton differential equation to a heat equation and then appl y the boundary conditions to the heat equation to derive the Black-Scholes formula.
Let y=lnS (S=eY) and i=T-L then oV = -oV
'
at
ar ·
DV =oV dy as ay dS
S=exp(x-(r-0.5a 2 )'r) . When
u(S,r)=u(x , r)=
s ay
1
as
2
t
as as) as s ay
S1
ay s as ay
S 2 ay
=
S 2 8/ ·
2 , 8 V aV oV I , . -+rS-+-a- 1s- --r ~ == 0 1 a, as 2 as 1 8v ( r --a 1 2 )av 1 1 -o V -rV = 0. can be converted to -- ~+ -+-a vr 2 8y 2 &/
II
= etf v '
ou _fJu
Ot~ +(r-
or
2
(. I
I
1
)2u
ay 2 and
a;/
r=f ,
t
&a (rnax(evt -K,O)exp
(
(x-'1') 2a2r
}
'II
~ (e~" -K)exp(-(x2a-;)r }'1'
l
& a JnK
2
'I' -X
Let s- - -
-a-h'
then :
=:
then
dl{l
dE= a~'
e =e
.
-2a ) fu· • WhiCh transforms the equation tO
:x+ea .Jr
X (
' e P
( x- 'I' )
za2r
\J = e-&21 2
and when
ln(K /S) -(r-a /2)r --d -
1
avr
:. u(S , r) = [ :odl ( se r -= 0 ).
=
146
TI le fun damental SOlutiOn
u(x, t):::
£ .. '
p(x :: :r ~"o
to
OU l a'u . h initial condition heat equa t"on - wrt I -Or -- 2 iJ/
=lf! )f(ljl)dlfl , where
p(x,
=x Ix.
-
- IJI )
' . (! to The For detailed discussion about heat cquatron. please re er Paul Wilmott. Sam Howison, and Jeff Oewynne.
==
II,
(IJI) = j(IJI) is
~exp{-(x -IJI r .' 2t}. ..{i;; . . . . {F . · 1 [)em·uttw!.' mancta
M(lthematic.~ ~
b}
147
A Practical Guide To Quantitative Fin:Jnce Interviews
Finance 2
• B . . Hence, InS= -+a 1 + aW(t) => lnS+tcr · / = W(l ) ts a rowman mot1on. . a 2
Whenever S reaches $H, the payoff is $1. Because the interest rate is 0, the discounted payoff is also$ I under risk-neutral measure. So the value of the option is the probability that S ever reaches $H, which is equivalent to the probability that InS ever reaches In H . Again we can apply the exponential martingale Z(l)=exp{A.W(I) -fA- 11} as "e
£[ Z(l)j =
did in Chapter 5:
£[
exp {,! InS
:+a't- t,! ' r}] = 1.
. Solution: Under nsk-neutral measure dS=rSdl+aSdW(I). Apply Ito's lemma to
dV 1 V=S:
S oV _!_ a2V a1s2)dl + av aSdW(I) =( -oV r +-+ ~(' as at 2 as-' CN
(
=
l 1 2 2s2)dl --l aSdW(t)=(-r+a.2)Vdt-aVdW(l) -srrs +O +2 s3 a s2
. . well and we can apply Ito's lemma to 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 E[ exp (InS) =I. The Let P be the probability that In S ever reache s In H (usin.g - P =1I H. So the probability that Sever reaches $His 1/H and the price of the option should be $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 the expected value of Sr is l, the probability that s,. ~ 1 actually approaches 0. lt is si mpler to use a no-arbitrage argument to derive the price. In order to pay $J when the stock price hits $H, we need to buy 1/H shares of the stock (at $IIH). So the option should be wo;th no more than $1/H. Yet if the option price C is less than $JIH ~~~I: H ~ CH ~I), we can buy an option by borrowing C shares of the stock. The tmltal mvestmcn_t Js o_. Once the stock price hits $H, we will excise the option and retum 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.
E. Assume a non-dividend paying stock follows a geometric Brownian motion. What is the value _of a contract that at maturity r puys the inverse of the stock price observed at the maturrty?
-rr 1 ] Discounting the payoff by e-rr , we have V =e E [r 1
-
-
1 -'•"•tr -e · · r. -'t
6 2 The Greeks
.
f on price wtth d artial derivatives of t e o~ ' II All Greeks are first-order or second-or e~ sed to measure the nsks-~as_ we as respect to different underlying factor~, w~tc Talre ~oHowing Greeks for a dcnvatJve fare . returns-of the fimancJa · 1.denvattve. 1e potenttal routinely used by financial institutions: . of . ,_Df ~2j· Th t 0==of ., Vega·. v == -:"I ; Rh o. p - VI~, M v G mma· f = ; e a. oa Delta: uA = VJ as ; a • OS']. v~~ · •
h
h.
0
Delta . . . ld . D. =e '~ N(d, ) For a European call with dtvtdend yte y. . . . ld . ~=-e- .r [J - N(dl)] For a European put \\~th d1vtdend Y'e Y· .
. n on a non-dtVI"dcnd paymg stoc o
k'> How do 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 . " • ·• · . o 0\\ ~ a g~:ometnc Brownian motion. S has two boundaritS for stor.pino · 0 and fl. The bounda~ cunu 1t1onO and 6 =N(d ) > 0.5. As shown lO •Jgu a r a 2 1 and the longer the maturity, the
~ o, (!_ + ~ )J.; ~ 0 ~ N(d (J
)
= N(O) =0.5, which is also
1
-
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. Figure 6.2 also s~ows that wh~n Sis large ( S >> K) 6 approaches 1. Furthermore, th.: shoner ;he matunty, lhe faster lhe delta approaches' 1. On the other halid. if S is small 6 (S 0.5
,• ••
0.3 r
.·
.··.• ...· .··
.... ....... ·· 0 •...
:
I
.•
_,, ,"
,. ,'
I
;
I
I
I
II
I
'
95
85
80
I
i•
I
•••
0.2 .
J
I
.'' .:
75
1
• .' I • I •
0
l S rr e-u,z 12 x-e S cr.J2nr K
6.2, all at-the-money call options indeed have
....··
.·
,= 3 months
=
as
.··.. ~
...
e - d,212
~N(d., )=§_errN(d1 )~Sx~N(d1 )-Ke-rr J_N(d,)=O. as - K as as ac cancel out and -oc =N(d ). last two components of-
hight.:r the 6 . As T -
1 month
....··..
0.7
1
So we have
as
----- 1=
0.8
=~e-dit2 x I = e (d,-uJi)l/2 - as & saFr Scr../2Jrr
=
= W days-
0.9
) 9:
j_N(d2) = N'(cl,)j_d2
as
F ,
100
105
110
115
120
125
Spot Price Figure 6.2 Variation of delta of a Europe T. K 100. r= 0.05, a= 0.25.
an call option with respect to S and
=
. GM stock and dc~iuc ~ European call opt Jon on fUM t ·k C You just entered a long posi~tion or a h ·sk from the fluctuation 1 s ol: to. dynamically hedge the position to your hedge. the price of GM u price. How will you h~dge the c~ll op~JO~~r hedging position? sudden increase, how WJll you rebalanc Y
°
eli~in~t~/ a~t~~-
Solution: Since d,
=
ha~
ln(S I K)+(r-y+cr 2 '' 2)r and 6 -= e -rr · L'"''(dt ) is a monotonously cr~
increasing function of d" we have
st
d i::)L\ i
·
-J r :\ ' ( 1) shares of stock t 6 ::::o e lv c ' · ~ f GM hor • £; which we s One hedging method is delta hedgmg, or ~ . delta-ncutr-dl. Since 6 s~are:s 0 . ' · · ke the portlo110 cash (1f the option for ~ach unit of call optiOn t? GM option. we also need to mves1 -rr V(d._ ) for each , stock costs more than one umt 0 ·e need to lend $Ke ' 1a, w . BI· k S holes fonnu pnce exactly follows the ac - c
:::::>
'
m;
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 6 increases as wel l. That means we need to shon more stock and lend more cash ( Ke_,., N(d2 ) also increases). The delta hedge only replicates the value and the slope of the option. To hedge the curvature of the option, we will need to hedge gamma as welL
What happens to the ganuna of an at-the-money European option when it approaches its maturity? Solulion: From the put-cal{ parity, it is obvious that a call and a put with identical characteristics have the same gamma (since r =0 for both the cash position and the 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 Su r v2~ 1
D. Can you ~stimate the. vaJue of an at-the-money call on a non-dividend paying stock?
I.
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 environment, r ~ 0 and e-rr~ I, soc~ S( N(d,) - N(d We also have N(d1) - N(d2 ) w here
)).
In a low-interest
)).
2
r·-
=
2
1-
z/2;
e-lf2x
1
dx,
r a 1 r a d 2 = (---)"1/ r and d, = (- +-)fr .
a
a
2
2
For a small r , a typical a for stocks (< 40% per year) and a short maturity (< 3 months). both d~ and d, are cl~se to 0. For example, if r = 0.03, a= 0.3, and r =l / 6 year. then d)= - 0.02 and e-l t"!.Ji =0.98.
a.Jr -12; ,-d1)=J2;-::::.0.4a.JT-t =::>c :::: 0.4aSfr.
:. N(d)N(d ) 1 2
I
(d
In practice, this approximation 1·s ·d b .. · ·d volatility of th Ysome volatthty traders to estimate the 1mphe . usc an a1- c-money opt1on. (The approximation e- 112x 2 - r . ., . , . . _,.. - caust:s a small overestimation since e- 1-' 2·'·- < ,1: but the approxtmat1on -e · K ~ -K cau. opposi te etlects cane 1 d h:ses ~ small und~restimution. To some extent, the {\\'0 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.
Figure 6.3 shows that gamma is high when options are at the money. w~ich is the stock price region that 11 changes rapidly with S. If S > K (deep 1n the money or 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 outof-the-money options longer maturity means higher gamma. In contrast, •f the stock prices are close to the,strike price (at the money) as the maturity nears, the slope of d~lta for an at-the-money call becomes steeper and steeper. So for options close to the stnke price, shorter-term options have higher gammas. As r ~ 0 an at-the-money catllput has r ~ co ( 6 becomes a step function). This can be show~ from the formula of gamma for a European call/put with no dividend,
r = N '(dl). Sa../r · 1 (d)~-:]2;J . Thcnumcratoris 11-fi;; (5) r O ::> limN . (r 1lrn - +-.../1:-+ (I J 2tr r-+0 a 2 r-> . . . I 0 r ~ 00· In other words, When I ':""" T. yet the denominator has a hm1t hmS(5vT ~ · so
s
When = K , d I
=
r-+0
·
.
kes hedging at-the-money options delta becomes a step function. This phenomenon. ~a ,. . difficult when t -+ T since delta is e>.1remcly sensttlvc to changes 111 S.
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
0.09 1 0.08
Theta of Call Options
I
--c= 10days
0 r...--~~-~-------~------
....
----- •= 1 month I
.......... •= 3 months
-5
0.07
·~~..
,,
r
'
····........ ',', ··. ···.... ' ', ··.
··. \ \
0.06 ;
ro E E 0.051 0
•••••• ·• .•
•
1-
•••• •
i.. .·..
i
·- ..
t=10days
I
-25
I
..· , .· / .·· , ~~" 0 I.. ·· __ ,,.
0.01
80
85
f r----- •= 1 month
: :L --. .......... •= 3 months
I.
95
100
10 5
110
115
120
125
Spot Price 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.
=
75
80
85
90
95
100
105
- --
110
------L
115
120
125
Spot Price Figure 6.4 Variation of theta of
Theta
For a European call option: 0
-20
II I
I I
Q)
I
..···,, .
0.02
··........~ ........ ..... .
\
.c
--~~··· .... ......... j
0.03r
··.
\\
~
f
I
,'
a European call option with respect to Sand
T. K = 100, a= 0.25, r =0.05
=_ SN '(d, )ae-yr 2~
+ yS'e-yr N(d,) - rKe-'' N(d.;)
For a European put option: 0 = _ SN '(d,)ae-yr 2~ -
ySe- yr N(-d,)+rKe-~''N(-d1 )
When there is no d' . ~·v '(d tvtdend, the theta for a E 0 ...:;-·· · ,)_rKc:-'' · ' . uropean call option is simplified to 2J; ;\ (d2 ), Whtch is alwav · · S > K }, N ( d,):::: N ( d 1 )-:::: I, N'( d1 )-:::: 0, so the component ySe-·\( N(d1 ) can make 0 positive.
Solution: Implied volatility is the volatility that makes the mod~l option price ~qual. to 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, 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 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 neither constant nor deterministic. In fact, the volat1hty IS a stochastiC process ttself. Furthermore, there may be jumps in asset prices.
B. You just entered a long position for a call option on GM and hedged the position by shorting GM shares to make the portfolio delta neutra I. ( f there is an immediate increase
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.
Solution: A position in the underlying asset has zero gamma. So the portfolio is deltaneutral and long gamma. Therefore, either an immediate increase or decrease in the GM stock price wiJI increase the ponfoJio value. The convexity (positive gamma) enhances returns when there is a large move in the stock price in either direction. Nevertheless, it is not an arbitrage opportunity. It is a trade-off between gamma and theta instead. From the Black-Scholes-Merton differential equation, the portfolio I" 2 . fi h . av av t t .. , oV 2S·f =rV. ForadetasatJsJes t eequatton - +rS-+-a 2S·--=0+rS6+-a 1 0/ as 2 as 2 2 2
2
neutral portfo lio, we have E>+.!.a S f =rV This indicates that gamma and theta often 2 have opposite signs. F~~ example. when an aHhe-money call approaches maturit~ 1 gamma . ~ large and pos1t1ve, so theta is large and negative. Our delta neutral portfolio has POSitive .gamm~ and negative theta. That means if the price does not move. the passag~ of time wtll result in a lower portfolio value unless we rebalance. So the ponfoho does not provide an arbitrage opportunity.
Vega for European options: u =~ = ep :: Se-Fr frN'( 1) C(J 00"
'I
At-the_-mon~y options are most sensitive to volatility change so they have hioher vegas than e1 ther m-th~-mo 1p)· 0 ' . 0 e . 1 t' 1 . ~.: : r ou -o -t 1e-money opt1ons. The vegas of all opttons decreas as ttme to expiration becomes h ( r . · · re . . . to change .n volatility. . s Orter v r -+ 0) smce a Long-term opt1on JS mo sens1t1ve 1 A. Explain implied volatility and volatility smile. What is the implication of volatility 156
B. You have to price a European call option either with a constant vol~tility ~0% or by · "butiOn · Wit · h a me_. ~n1of 30o/c0 · Whtch optiOn would drawing volatility from a random d1stn be more expensive? Solution: Many would simply argue that stochastic volatility ":'~kes_ the stock pril:c • IS . more va 1ua ble when the volatility ts drawn. fromf a more volatile so the call pnce · argume~ t. ·IS thatd the ' random distribution. Mathematically, the underlytng . . pnce ,o·ulta · of volatiltty an . . as a . is res!he European call option is a convex functiOn . c(E[aJ)~ E[c(a)], where a is the random variable representmg volat•hty and ' · . call option price. Is the underlymg argument correct.? Ies correct in , most.- but,.. not all
a·c cc . . f a , then -aa ·- 2 2: 0. -()a 1s the cases. If the call price c is always a convex functJon
°
Vega of the option. For a European call option,
a2ci·s called Volg,a. for a European call option, The secondary partial derivative -::;---2 0 0
. . both d 1 and d2 are postll\ c. . o ' ~ 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 -. ' -
a2 c: 0 when the option is close to hcing have conditions that d , > 0 and d 2 < 0 and oa1 < 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 constant volatility may have a higher value.
should also have a good understanding of pricing and hedging of some of the commnn 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 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 (continuous) strike prices K. Can you detennine the risk-neutral probability density function of the stock price at timeT?
Bull spread
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
=e
-rr
=~ -
r
JK
r
Maturity T Cash flow
TimeO
Long c1
Sr ::; K 1
K, < S.r < Kl
s7" ~ K2
-c,
0
Sr-Kl
Sr-K1
Short c2
c2
0
0
-(S.
Total
c2 -c, < 0
0
Sr
(s- K)/.;, (s)ds
K~ )
K2-KI
-K~
Table 6.3 Cash flows of a bull call spread.
f ._, (s)ds
and -r·c - - (j ( -ac tK l
summarized in table 6.3.
1
a(s- K) r DK ~s. (s)ds-e-'r(K-K)x l
r-
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
f,. (s) is the
probability density function of S, under the risk-neutral probability measure. Taking tht' first and second derivatives of c with respect to K,10 we have
;~ - f! a~
What are the price boundaries for a bull call spread?
I . r: r f. (s - e-'· cK
aK cK ; -
'!\ -
s,
Since K < K
s =e-rr f ..., (K ) .
)d
I
the initial cash flow is negative. Considering that 2,
2
Hence the risk-neutral probability density function is f.. (K) = e'' fi e., . ~, o}(-
the price of the spread, c, - c1,
bounded by K - K
.
JS
the ,
final payofT is _,, ( K - K ).
bounded b) e
'
·1
"
Besides, the payoff is also bounded by K2 - Kl Sp so the price is nlso bounded by
K2
6.3. Option Portfolios and Exotic Options
:~. addi.tio~ to lhL· pri\:ing an_d_ prop~rties of vanilla European and American options. you __ a)_ b~.: expect~d to he fa,, both options are undervalued. When the market prices converge to the prices with th.e realized volatility, both the call and the put will become more valuable.
We can also approximate a digital option using a bull spread with two calls. If call 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 K + £ . The payoff of the bull spread is the same as the digital call option if Sr. $ K -£
Although initially a straddle with an at-the-money call and an at-the-money put ( K = S ) has a delta close to 0, as the stock price moves away from the strike price, the delta is no 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 11 swaps or variance swaps. For example, a variance swap pays N x (u; - Kvar ), where.\' is the notional value,
a; is the realized variance and Kvw is the strike for the variance.
(both have payoff 0) or Sr ;:::. K + & (both have payoff $1 ). When K- £ < S.r < K + & , their payoffs are different. Nevertheless, if we set £ -4 0, such a strategy will exactly 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 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 nondiVIdend paymg stock 1f the stock pnce follows a geometric Brownian motion? Ho" would you hedge a cash·or-nothing call option and what's the limitatior1 of your hedging strategy?
Exchange options
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 0 1100 P IS Cu = e N (d2) rf the underlying asset is a non·dividend paying stock. As we
Brownian motions with correlation p .
have discu_ssed in the derivation of the Black·Scholes formula, N(d2) is the probabilit} thar a vanilla call option fin.sh · t he money under the n.sk-neutral measure. So ·tts. 1 es m . dtscounted value is e-n N(d 2 ). Theoretically, a cash-or-nothin~ call option can be hedged using the standard delta h d . cc I e grng strategy. Since 6 = ~=e-n N '(d ) a long position in a cash-or·
cS
2
SaJ; ,
nothing call option can be hedooed bY s1lOrtmg · e_,., N·,( d, )
· shares (and a nsk-free
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)
•• 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 be approximated by a po,rtfolt'o 01• } ddresl 1111 1 ~ Demererfi. el al. Th~ paper shows that a variance swap can s1ra es· With propc.;r ~ · 1liS ·mversdy proportional to 1/k-.' we1g 160
How would you price an exchange call option that pays max (S J .t - S7.2 • 0) at maturity. Assume that S and S are non-dividend paying stocks and both follow geometric 2
1
Solution: The solution to this problem uses change of numeroire. Nu~eraire t~e~ns.:·; unit of measurement. When we express the price of an asset, we u.sua ly use d'cfr.,ocant 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 asset as the numeraire. The only requirement for a numcralre IS 1 at mus '' positive. I S (price of S1 at maturity dateD • • The payoff of the exchange option depends on bo t 1 1".1 .• d , geometric Browman motJOn~. and s ./.2 (price of s?. at 1), so it appears that we nee t\H)
ciS, = f.l1S1dt + a,S,dW,,~ dS2 = Jt1 S2dt + 0"2 S 2dW,.2
•
. th ~ rob tern to just Yet if we use S as the nwneraire, we can convert e P
. Browman
' .
motion. The final
on~
gcometnc
(s~ J ol . ( _ · o) =S max - - 1. 1· payoff IS max s1 .~ 8r.r ' rI s,, /
Wh
en
"
"
- s~K and r-+O=>In(S / K)-+O ~ d: -)(r / u+ 0·5a
'"L . )J; -+ o=> o -+ ~~~ -r:::: · r
"2tr Su"r
!61
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
6.4. Other Finance Questions
I
well. One intuitive e:-VaR(A)+VaR(B). Lack of sub-additivity directly contradicts the intuiti ve idea that diversification reduces risk. So it is a theoretical drawback ofVaR. (Sub-additivity is one property of a coherent risk measure. A risk measure p(X) is considered coherent if the following conditions holds: p(X + }') ~ p(X) + p(Y); p(aX)=ap(X), \ta>O; p(X)~p(Y), if X~Y; and p(X+k)=p(X) - k for ~ny constant k. It is defined in Coherent Measure of Risk by Artzner, P., ct al., MathemallcaJ Finance, 9 (3):203-228. Conditional VaR is a coherent risk measure.)
Duration and convexity h p · th. price of the bond andy 1 dP T he duration of a bond is defined as D =- p dy , w ere 15 c l d! I' . is yield to maturity. The convexity of a bond is defined as C = p d.t ' · Applymg Tay l or•s expansion, 1:1P
pz
6P
1 , h A is small -:::: -D~y. - Dlly+2C fly-. w en uy : p
. A= e 'I:-'e>O
For a fixed-rate bond with coupon rate c and time-to-maturity T: Iss
. v R b · ating the Jail risk. tress test rs often used as a complement to a Y es11111
165
-
A Practical Guide To Quantitative Finance Interview~
Finance
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
...
-lSOr,
I 1
Year 5
dP Another important concepl is dollar duration: $D = - - = Px D. Many market dy
Short 3 fl oatingrate bonds
300
-150~
participants use a concept called DVOI : DVO I =
Long 4 bonds with 7.5% coupon rate
-400
15
...
\5
400 +I 5
Total
-100
15 -ISOr.
...
30 - 3001;,
115-ISOr,
dP , which measures the 1O,OOOx dy price change when the yield changes by one basis point. For some bond derivative_s, 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.
When n bonds wi th values P,, i =I , ··· , n} and Durations D; (co nvexities C; ) form a portfolio. the dura tion of the portfolio is the value-weigh ted average of the d urations of n p the compo nents: D = I . . . !. . D, ( C = t= l
p
n
p
n
L......!...C, ), where P = L _r:. The dollar duration of p ' '· I
1•1
t ool
103.75 =lOOx O.S -= 48.19. 1+y l2
d(103 .75 /(1 + y/2))
$Djloa11ng =-
=0.5x(l+ y/2)1
dy
°
. f h fixed-rate bond is of the bond. So the dollar duratlOn t e 1'
(2' t c/2 -d = 1 + y/2 ~ 2 (I+ dP
Solulion: The key to solving basic fixed-income problems is cash flow replication. To
price a fixed-income security \-vith exotic .structures. if we ca n replicate its cash flo\v using a portfolio of fundamental hond types such as fixed-rate coupon bonds (incl uding 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 3 floatmg rate bonds, which is worth $100 each, and longing 4 fixed-rate bonds with a
7. 5o/~ annual coup?n r~tc, which is worth $100 each as well. The coupon rate of a n oatt~g-~ate bond. ts adJ usted every 0.5 years payable in arrear: the coupon rate paid at
ts determmed at 1. The cash flows of both positions and the whole portfolio arc summarized in the following table. It is apparent that the total cash flows of the portfolio are the same as tl1e described inverse floater. So the price of the inverse float is the price of the replicating portfolio: P.... Y'\1 . ; $100. 1 + O.:>y
c12
100 where T is the maturity The price of a fixed-rate bond is P = ~ (1+ y /2)' + (l + y 12)u ' 2r
What are the price and duration of an inverse floater with face value $I 00 and annual 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%.
J
. . the same as the dollar duration of the The dollar duration of the mverse floater t$s D Since the yield curve is flat. ~ )' e\J · $D =4x$D .,-3x fifK•''''s: ' . , port10 10 as w · "''w'" fu·'. · worth $lO} 75 (after the payment of '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,.
•
-300-ISOr,
J \
$Dfl.ted =
1
lOOT -)= 410.64. y/2)' + (1 + yl2)u . - 1498 and the duration of the inverse floater tS
y
So $D1
nv(J.n:~
=
4 x$Dfi.,h"3 x$D1t...t~ms "'
Forward and futures , h 'cc of the underlying as~~~ d forwards? It t e pn ·t ··h·tstlc What's the difference between futures.an and the interest rates are soc • ~ · d . th tnterest rates, is strongly positively correlate wt r , rds? Whv? · f t es or lorwa · " which one has higher pnce: u ur . d tracts· f(jrw:.ml standardszc con ·· .~ exchange-traded 'bl · Futures ~ontntct~ Solwion: Futures contracts ar: ents so they are more tlcxt e. e contract n:nn. contracts are over-the-counter agreem ct , are settled at the end of th ~ wards conta s are marked-to-market da1··-Y,. .or
16
•
•
The initial duration of a tloatmg rate bo
. fa six-lllonth zer(• nd is the same as the duration o
coupon bond.
167
A Practical Guide To Quantitative Finance Interviews
Finance
If the interest rate is deterministic, futures and forwards have the same theoretical price: F = Set r+u- ylr. where u represents all the storage costs and y represents di vidend yield for investment assets, convenience yield for commodities and foreign risk-free interest rate for foreign currencies. 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 contract increases, the differences between forward and fu tures contracts may become significant. If the futures price is positively correlated with the interest rate, the 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 immediate profi t that can be reinvested at a higher rate. The loss tends to occur vvhen the interest rate is low so that it can be financed at a low rate. So a futures contract is more Vtl luable than the forward when its value is positively correlated with interest rates and the futures price should be higher.
The Cox-Ingersoll-Ross model keeps the mean-reversion property of the. Vasicek modeL But the diffusion rate a~R(u ) addresses the drawback of Vastcek model by guaranteeing that the short rate is positive. No-arbitrage short~rate models
Ho-Lee model : dr = B(t)dt +adz The Ho-Lee model is the simplest no-arbi trage short-rate model where B(t) is a timedependent drift. B(t) is adjusted to make the model match the current rate curve. Hull-\Vhite model : dR(t) =a (b(l) - R(t) )dt + adW(I) . '\ t the Vasicek model. The difference is The Hull·White model has a st~cture. Slffit ~ul~-Wl ' te model to make it fit the current that b(t) is a time-dependent vanable m the lt 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 )