..... 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 ~ <_?nl~. the d~. A~ter that, you fi rst said: "lOon 't know A's birthday: C doesn t k.now 1t e1the_r. · After heanng 1 Hint: The key is to realize that A and 8 should get across the bridge together 5 Brain Teasers A Practical Guide To Quantitative Finance Interviews what you said, C replied: "I didn't know A's birthday, but now I know it. " You smiled and said: "Now 1 know jt, too." After looking at the I 0 dates and hearing your comments, your administrative assistant wrote down A's birthday without asking any questions. So what did the assistant write? red and black cards are discarded. As a result, the number of red cards left for you and the number of black cards left for the dealer are always the same. The dealer always wins! So we sho uld not pay anything to play the game. Solution: Don' t let the " he said, she said" part confuses you. Just interpret the logic behind each individual's comments and try your best to derive useful infonnat ion from these comments. Burning ropes Let D be the day of the month of A's birthday, we have De {1,2, 4,5, 7,8}. [f the birthday is on a unique day, C will know the A's birthday immediately. Among possible Ds, 2 and 7 are unique days. Considering that you are sure that C does not k.now A's birthday. you must infer that the day the C was told of is not 2 or 7. Conclusion: the month is not June or December. (lf the month had been June, the day C was told of may have been 2; if the month had been December, the day C was told of may have been 7.) Now C knows that the month must be either March or September. He immediately figures out ~·s birthday, which means the day must be unique in the March and September ltst. It means A's birthday cannot be Mar 5, or Sep 5. Conclusion: the birthday must be Mar 4, Mar 8 or Sep I. Among these tJ1rce possibilities left. Mar 4 and Mar 8 have the same month. So if the mont~ y~u have is ,Ma~ch. you still cannot figure out A's birthday. Since you can figure out A s btrthday, A s btrthday must be Sep 1. Hence, the assistant must have written Sep 1. Card game A l:asino offers a card game us· g 1d k · " . · m a norma ec of 52 cards. The rule 1s that you tum ~' clr two cards ea~h tune. For ca~h p.air, if both are black, they go to the dealer· s pile; if 1 ot arc. red. the) go .to your ptle; tf one black and one red they are discarded The p~occss IS repeated unttl you two go throuah all 52 ca d rf ' h .. I • • p1le, you win $ 100· otherwi. . . :r s. . you ave more car us m) our negotiate the price. ou wa~'ie (mcludmg ties) you get notlung. The casino allows you to pay to play this gat:C•r t to pay for the game. How much would you be willing to I Solwion: This surely is an insidious . . N and the dc·tlcr will al~ h h casmo. 0 matter how the cards arc arranged. you \.'ach pair ~f dis<.:arded ~~·~d a~'e t e same number of cards in your piles. Why? Because • ' <It s ave one black card and one red card, so equal number of ·' I lint: Try to npproach the problem usin ' s mme . What does that tl!ll you as 10 lhe number ~f~l k tl)'. Each dtsc;:arded pair has one black and one red card. ac and red cards m the rest two piles? You have two ropes, each of which takes I hour to bum. But either rope has different densities at different points, so there's no guarantee of consistency in the time it takes different sections within the rope to bum. How do you use these two ropes to measure 45 minutes? Solution: This is a classic brain teaser question. For a rope that takes x minutes to bum, if you light both ends of the rope si multaneously, it takes xI 2 minutes to burn. So we should li ght both ends of the first rope and light one end of the second rope. 30 minutes later, the first rope will get completely burned, while that second rope now becomes a 30-min rope. At that moment, we can light the second rope at the other end (with the first end still burning). and when it is burned out, the total time is exactly 45 minutes. Defective ball You have 12 identical balls. One of the balls is heavier OR lighter than the rest (you don't know which). Using just a balance tbat can only show you which side of the tray is 3 heavier, how can you determine which ball is the defective one with 3 measurements? Solution: This weighing problem is another classic brain teaser and is still being asked by many interviewers. The total number of balls often ranges from 8 to more than l 00. Here we use n =12 to show the fundamental approach. The key is to separate the original group (as well as any intem1ediate subgroups) into_tht=-ee sets instead of' two. Th-e reason is that the comparison of the first two groups always gives information about the third group. Considering that the solution is wordy to explain, I draw a tree diugram in Figure 2. 1 to show the approach in detail. Luhel the halls 1 through 12 and separate them to three groups with 4 balls each. Weigh balls 1. 2. 3. 4 against balls 5. 6. 7. 8. Then we go on to explore two possible scenarios: two groups balance. as expressed using an h_,, sign, or l , 3 Hint: First do 1t for 9 1dentical balls and use only 2 measurements. knowing that one is ht:avi~:r than the rest. 7 Brain Tca.-;crs A Practical Guide To Quantitative Finance Interviews 2, 3, 4 are lighter than 5, 6, 7, 8, as expressed using an "<" sign. There is no need to explain the scenario that 1, 2, 3, 4 are heavier than 5, 6, 7, 8. (Why?") If the two groups balance, this immediately tells us that the defective ball is in 9, 10, II and 12, and it is either li ghter (L) or heavier (H) than other balls. Then we take 9, I 0 and ll from group 3 and compare balls 9, I0 with 8, 11. Here we have already figured out that 8 is a normal ball. If 9, I 0 are lighter, it must mean either 9 or I0 is Lor 11 is H. In which case. we just compare 9 with I0. If 9 is lighter, 9 is the defective one and it is L; if 9 and I0 balance, then II must be defective and H; If 9 is heavier, 10 is the defective one and it i:; L If 9, I0 and 8, ll balance, 12 is the defective one. If 9, 10 is heavier, than either 9 or I0 is H, or 11 is L. You can easily follow the tree in Figure 2.1 for further analysis and it is cJear from the tree that all possible scenarios can be resolved in 3 measurements. lighter, you can identify the defective ball among up to 3" balls using no more than n measurernents si nce each weighing reduces the problem size by 2/3. If you have no infonnati~n as to whether the ~efe~tive ball is heavier or lig~et•, you c~n ideotjfy thedefective ball among up to (3" -3)/2 balls using no more than n measurements. -- - --- ----- - -- Trailing zeros How many trailing zeros are there in 100! (factorial of I 00)? Solution: This is an easy problem. We know that each pair of 2 and 5 will give a trailing zero. If we perform prime number decomposition on all the numbers in l 00! , it is obvious that the freq uency of 2 will far outnumber of the freq uency of 5. So the frequency of 5 determines the number of trailing zeros. Among numbers 1, 2, · · ·, 99, and 100, 20 numbers are divisible by 5 ( 5, I0, · · ·, I 00 ). Among these 20 numbers, 4 are divisible by 52 ( 25, 50, 75, 100 ). So the total frequency of S is 24 and there are 24 trailing zeros. Horse race 112'J/4 L or 5/6/7/S 111 @) - / There are 25 horses, each of which runs at a constant speed that is different from the other horses'. Since the track only bas 5 lanes, each race can have at most 5 horses. If you need to find the 3 fastest horses, what is the minimum number of races needed to identify them? 9/lD/11/12 L or H GV GV - ~ "l ~ / 9/J OL or 1111 ®-@ ~ •l 1 2Lo~ 12H (!) -@ Solution: This problem tests your basic analytical skills. To find the 3 fastest horses, surely all horses need to be tested. So a natural first step is to divide the horses to 5 groups (with horses 1-5,6-10, 11 -15, 16-20, 21-25 ,j n each group). After 5 races, we will have the order within each group, let's assume the order fol~ows the order of numbers (e.g .• 6 is the fastest and 10 is the slo'vvcst in the 6- 10 group f. That means I. 6, 11 , 16 and 21 arc the tastest within each group. 9/I OH or II L 0-@ ll \ I \ /! \ Ql. 111-1 IUL l2H 121. 1011 Ill. 911 Figure 2.1 Tree diagram to identify the defective ball in 12 balls In general if you have the inf0 _ - · -- ~ m1at10n as to whether the defectivt:! ball is heavier or - lk~rc is whc_rc the symmetry idea comes in. Nothin' . . . . h g makes the I. 2, 3. 4 or:>. 6, 7. 8 labels spec1al. II I, 2. ., · • · • · s ust exc ange the label50 f th . 0 f I • ... 3. 4 bc1ng light~r than 5, 6. ?, 8 _ esc two groups. Agatn we have the case I Surely the last two horses with in each group arc eliminated. What else can we infer? We know that \-Vithin each group, if the fastest horse ranks 5th or 4tlil among 25 horses, then all horses in that group cannot be in top 3; if it ranks the Jrd, no other horse in that group can be in the top 3; if it ranks the 2nd, then one other horse in that group may be in top 3; if it ranks the first, then two other horses in that group may be in top 3. J. 4 al'i! hc(lm.·r than 5 6 7 g l'et' , J. Such an assumption doe~ not affect the generality of the solution. If the order is not as described, just change the labels of the horses. 5 8 9 .........,.. Brain Teasers A Prc~ctical Guide To QuantiJaJive Finance Interviews So lei's r~ce horses I. 6, II , 16 and 2 l. Again without loss of generality, let's assume the order IS I, 6, II . 16 and 21. Then we immediately know that horses 4-5 8-1 0 12-15 16-20 an~ 21-25. are eliminated. Sinc.e l is fastest among aJI the horses, 1 j~ in. We need to detcrmmc wh1ch two among horses 2, 3, 6, 7 and II are in top 3, which only takes one extra race. fit in the 62 squares left, so you cannot find a way to fill in all 62 squares without overlapping or overreachi ng. Removed So all together we need 7 races (in 3 rounds) to identify the 3 fastest horses. Infinite sequence If x ~'~ x ~'~ x~'~ x~'~ x ··· ::-:2, where x Ay =xY, what is x? Solut_ion: This problem appears to be difficult. but a simple analysis will gi ve an elegant solutiOn. What do we have fro m the original equation? Removed +-- limx "x~'>x~'~ xAx · .. =2¢:.> lim x~'~x~'~xA A _ -~ n--+:.c - - - - -I......!.:...:. - 2 . ln Figure 2.2 Chess board with alternative black and white squares II-+"Y n- 1 1erms other words, as n -> 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 <hagonal corners have the same c an~ whue squares, both squart:s at the 01 Will always cover one black uare or: ~t you put a I x 2 brick on the board, it corner squares were removtdih ~nd one whne square. Let's say it's the two black wco only have 30 black squar'es el ~ t-e !:_de_!t of the. board can fit at most 30 bricks since e.t lan each 6i~ -k · - Prtck J I bncks is out of the •.5 1.nc reqUi res one black square). So to ov .. ·h· qu..:: JOn, To cover all 62 . . errc.lc mg. we must have exactly 31 b . k squares without ovcrlappmg or nc s. Yet we have proved that 3 1 bricks cannot Just as any good trading strategy, if more and more people get to know it and replicate it, the effectiveness of such a strategy will disappear. As the chess board problem becomes popular, many interviewees simply commit it to memory (after all, it's easy to remember the answer). So some ingeni ous interviewer came up with the newer version to test your thinking process, or at least your ability to extend your knowledge to new problems. If we look at the total volume in this 30 problem, 53 bricks have a volume of2 12, which is smaller then the box's volume 216. Yet we can show it is impossible to pack all the bricks into the box using a similar approach as the chess board problem. Let's imagine that the 6 x 6 x. 6 box is actually comprised of small 2 x 2 x 2 cubes. There should be 27 small cubes. Similar to the chess board (but in 30), imagine that we have black c~bes and white cubes alternates--it does take a little 30 visualization. So we have either 14 black cubes & 13 ,,1lite c~bcs or 13 black cubes & 14 white cubes. For any_! xI x 4_ brick tt.lat we pack j nto.J!!e box. half (~x I x 2J_of i,t_must be in .~ black 2 x 2 x 2 cube ~ ~ tl!e other half must be in (~ white 2 x 2 x 2 cube. The problem is that each 2 x 2 x 2 cube can orily be -used by 4 of the 1x 1x 4 bricks. So for the color with 13 cubes, be it black or white, we can only use them for 52 I x 1x 4 tubes. There is no way to place the 53th brick. So we cannot pack 53 bricks of dimensions 1x 1x 4 into a 6 x 6 x 6 box. Calendar cubes You just had two dice custom-made. Instead of numbers 1 - 6, you place single-digit numbers on the faces of each dice so that every morning you can arrange the dice in a way as to make the two front faces show the current day of the month. You must use both dice (in other words, days 1 - 9 must be shown as 0 1 - 09), but you can swi tch the 10 II - Brain Teasers A Practical Guide To Quantitative Finance Interviews order of the .dice if y~u want. What numbers do you have to put on the six faces of each of the two dtce to achieve that? Solution.:. The d~y~ of a month include II and 22~ so both dice must have 1 and 2. To express smgle-?tgl~ days, we need to have at least a 0 in one dice. Let's put a 0 in dice ~ne first. Con~t~enng that we need to express all single dioit days and dice two cannot lave all 1he.dtgtts ~r~m I - 9, it's necessary to have a 0 in°dice two as well in order to express a11smgle-dtglt days. So far we have assigned the following numbers: direct quest ion does not help us solve the problem. The key is to involve both guards in the questions as the popular answer does. For scenario l, if we happen to choose the truth teller, he will answer no si nce the liar will say no; if we happen to choose the liar guard, he will answer yes since the truth teller wi!J say no. For scenario 2, if we happen to choose the truth teller, he will answer yes since the liar will say yes; if we happen to choose the liar guard, he will answer no since the truth teller with say yes. So for both scenarios, if the answer is no, we choose that door; if the answer is yes, we choose the other door. - Dice one I Dice two I 1 2 2 0 ? ? ? Message delivery '? ? ? You need to communicate with your colleague in Greenwich via a messenger service. Your documents are sent in a padlock box. Unfortunately the messenger service is not secure, so anything inside an unlocked box will be lost (including any locks you place inside the box) during the delivery. The high-security padlocks you and your colleague each use have only one key which the person placing the lock owns. How can you securely send a document to your colleague?6 I 0 If we can ass1gn all the rest of cltgits 3 4 5 6 7 problem is solved. But there are 7 di. its' I 8, and 9 to the rest of the faces, the think out of the box We c g e · . lat can we do? Here's where you need to time! So simply p, ~~ 3- 4 an dus5e a ~!IS~ ~ smce they will never be needed at the same • ' • ' an on one dtcc and 6 7 . d 8 ·. tmarnumbers on the two dice are: • • an on the other dLce, and the ft Wl ' Solution: If you have a document to del iver. clearly you cannot delive r it in an un locked Dice one I 2 0 3 4 Dice two 5 I 2 0 6 7 8 Door to offer box. So the first step is to deliver it to Greenwich in a locked box. Since you are the person who has the key to that lock, your colleague cannot open the box to get the document. Somehow you need to remove the lock before he can get the document, which means the box should be sent back to you before your colleague can get the document. Y?t~ are facing two doors. One leads to ·our ·o So what can he do before he sends back the box? He can place a second lock on the box, which he has the key to! Once the box is back to you, you remove your own lock and send the box back to your colleague. He opens his own lock and gets the document. Solution: This is another classic b . Last ball A bag has 20 blue balls and 14 red balls. Each time you randomly take two balls out. (Assume each ball in the bag has equal probabil ity of being taken). You do not put these two balls back. lnstt::ad, if both balls have the same color, you add a blue ball to the bag; if they have different colors, you add a red ball to the bag. Assume that you have an unlimited supply of blue and red balls~ if you keep on repeating this process, what will be the color of lhe last ball left in the bag?7 What if the bag has 20 blue balls and 13 red balls instead? ot either door is a guard. One guard al~a ·s J b o!fer and the other leads to exit. In fron t You can only ask one guard one yes/ Y te~ls ltes and the other always tells the truth. ofler. what question will you ask? · no question. Assuming you do want to get the job One popular answer is to ask ram teaser (maybe a little out-of-da te in my opinion). · , 0 ne guard· '" W ld h guardmg th~ door to the offer'"' If h . · ou t e other guard say that you are no' c I1oosc tI)C door this ''uard .is t ed'answers yes • choose the other door; if he answers 5 an tng .m front of .• e. 1here ure two possible scenarios: l. lruth tdler guards the door toot . . . 2. l h Ter. Liar ~ruards the door to exit nu teller guards the door to exit· Liar . lf we ask a I.!Uard ad ' • ' guards the door to offer. ~ Jrcct quesuon such as ,, A . scenano I· both guards will answer yes· fi re yo.u guarding the door to the offer?" For ' or scenano 2, both guards wi ll answer no. So a 6 7 Hint : You can have more than one lock oo the box. Hint : Consider the changes in the number of red and blue balls after each step. 13 Broin Teasers A Practical Guide To Quantitative Finance Interviews So!Uiion: Once you understand the hint, this problem should be an easy one. Let (8 , R) represent the number of blue balls and red balls in the bag. We can take a look what will happen after two halls are taken out. Uoth balls are blue: ( B, R) ~ ( B -I. R) Both balls are red : ( R. R) ~ (8 + 1, R- 2) Quant salary Eight quants fro m different banks are get1ing together for drinks. They are all interested in knowing the average salary of the group. Nevertheless, being cautious and humble individuals, everyone prefers not to disclose his or her own salary to the group. Can you come up with a strategy for the quants to calculate the average salary without knowi ng other people's salaries? One red and one blue: (B. R) ~ ( B -l,R) Notice that R either stays the same or decreases by 2, so the number of red balls will never become odd if we begin with 14 red balls. We also know that the total number of balls decreases by one each time until only one ball is left. Combining the information we have. the last ball must be a blue one. Similarly, when we start with odd number of red balls. the tina! ball must be a red one. Light switches There is a light bulb inside a _room and four switches outside. All switches are currently at ?ff state and only one swttch controls the light bulb. You may turn any number of ~wttches on or off any number of times you want. How many times do you need to go nlto the room to figurt~ out which switch controls the light bulb? ~ol.lllion: You may have seen the classical version of this problem wi th 3 light bulbs tns1de the.room and 3 switches outside. Although this problem is slightly modified the approach ts exact the same Whethe th 1· h · · · · ' . . . · r e tg t IS on and off 1s bmary whtch only allows c: ' h 2 2 4 us to dtsiJngUish two switches. If we have another b' - "bl · · mary 1actor t ere are x = poss1 c combmatlons of scenarios · d. · · · ' · r.,J b lb 1 . · ·' so we can tstmgu1sh 4 swttches. Besides hoht, a J&&ll u a so em1ts heat and becomes hot after th b lb h b · " · 0 , we can use the on/olf and c0 ld/h . . ·e ~ a~ een ht 10r some t1me. So \!On trois the 1ight. ot combmatJOn to dec1de which one of the four switcihes · ~·urn on switches I and 2: move 00 to solve s • ., tor a whi le· turn off sw't ·h ? d .orne other puzzles or do whatever you hke bulb and ohserve whetltel cth~ ~~nl ~~m on SWitch 3~ get into the room quickly, touch the · r e 1g 1t IS on or off. :l:he l~ght bulb is on and hot-+ switch l controls the light; l~ght bulb is otr and hot - switch 2 controls the light; fhc l~ght bulb is on and cold-+ switch 3 controls the light; The light bulb i::; ofl~ and cold - switch 4 controls the light. .I he Solution: This is a light-hearted problem and has more than one answer. One approach is for the first quant to choose a random nwnber, adds it to his/her salary and gives it to the second quant. The second quant will add his/her own salary to the result and give it to the third quant; ... ; the eighth quant will add his/her own salary to the result and give it back to the first quant. Then the first quant will deduct the "random" number from the total and divide the "real" total by 8 to yield the average salary. You may be wondering whether this strategy has any use except being a good brain teaser to test interviewees. It does have applications in practice. For example, a third party data provider collect fund holding position data (securities owned by a fund and the number of shares) from all participating firms and then distribute the information back to participants. Surely most participants do not want others to figure out what they are holding. If each position in the fund has the same fund ID every day, it's easy to reverse-engineer the fund from the holdings and to replicate the strategy. So different random numbers (or more exactly pseudo-random numbers since the provider knows what number is added to the fund ID of each position and complicated algorithm is involved to make the mapping one to one) are added to the fund ID of each position in the funds before distribution. As a result, the positions in the same fund appear to have different fund IDs. That prevents participants from re-constructing other funds. Using this approach, the participants can share market information and remain anonymous at the same time. 2.4 Application of Symmetry Coin piles Suppose that you are blind-folded in a room and are told that there are I000 coins on the floor. 980 of the coins have tails up artd the other 20 coins have head s up. Can you separate the coins into two piles so to guarantee both piJes have equal number of heads? Assume that you cannot tell a coin,s side by touching i t~ but you are allowed to tum over any number of coins. Solution: Let's say that we separate the lOOO coins into two piles with n coins in one pile and 1000- 11 coins in the other. If there are m coins in the first pile with heads up, there 14 15 Brain Teasers A Practical Guide To Quantitative Finance Interviews must be 20-m coins in the second pile with heads up. We also know that there aJ:e n- m coins in the first pile with tails up. We clearly cannot guarantee that m =I0 by simply adjusting n. What other options do we have? We can turn over coins if we want to. Since we have no way of knowing what a coin's side is, it won't guarantee anything if we selectively flip coins. However, if we tlip all the coins in the first pile, all heads become tail s and all tails become heads. As a result, it will have n-m heads and m tails (symmetry). So, to start. we need to make the number of tails in the original first pile equal to the number of heads in the second pile~ in other words, to make n- m =20-m. n = 20 makes the equation hold. lf we take 20 coins at random and turn them all over, the number of beads among these turned-over 20 coins should be the same as the number of heads among the other 980 coins. Mislabeled bags One has apples in it; one has oranges in it; and one has .a m1x of apples and oranges in it. Each bag has a label on it (apple, orange or mix). Un_tortu_nately. your mana~cr tells you that ALL bags are mislabeled. Develop a strategy to~ tde~ltJfy the hags by takmg out minimum number of fruits? You can take any number ot fnn ts from any bags. 8 You are_given three bags of fruits. So!uJiun: Thc.key here is to usc the tact that ALL bags are mislabeled. For example, a ba·g' labeled wtth apple must contain either oranges only or a mix of oranges and apples. Let s look at the labels: orange. apple, mix (orange+ apple). Have you realized that the 0 ~~ge !a~l and the apple ~abel are synunctric? lf not, let me explain it in detail: If you pick a l':lut _from the bag wtth the orange label and it's an apple (orange ~ apple) then the bag 1s etther all apples o · · If , · k · ~ · ' . ;-r a tmx. ) ou pte a fruit from the bag with the apple label and It s an orml''e (apple ~ 0 a ) th h . . . . o r nge , en t e bag IS etther an orange bag or a mtx. Symbmctn~ labels a:e not exciting and are unlikely to be the correct approach So let's u·v t: ag WJth the m1:x label and get 1· · r. · · • . k . h b .· one nut •rom tt. If the fruit we get is an orange then ''e ncm· t at ag 1s actually or·1 , (I · · know tht: bag's lab;! ·, ) ·~~e t cannot be a mtx of oranges and apples since we it must be th~ mix ~: wr~n~ . , mce the with the apple label cannot be apple only. Similarlv fo r the c~sc tgha. t n l the b~g wtth the orange label must be the apple bag. ·· app es are m the bag, w'th th · 1b 1 fi II 1 the bags using one single pick. e mtx a c, we can tgure out a th ?ag Wise men A sultan has captured 50 wise men. He has a glass currently standing bottom down. Every J11inute he ca lls one of the wise men who can choose either to turn it over (set it upside down or bottom down) or to do nothing. The wise men will be called randomly, possibly for an infinite number of times. When someone called to the sul tan correctly s tates that aJI wise men have already been called to the sultan at least once, everyone goes free. But if his statement is wrong, the sultan puts everyone to death. The wise men are allowed to communicate only once before they get imprisoned into separate rooms (one per room). Design a strategy that lets the wjse men go free. SoLwion: For the strategy to work, one wise man, let's call bim the spokesman, will state that evety one has been ca lled. What does that tell us? 1. All the other 49 wise men are equivalent (sy mmetric). 2. The spokesman is different from the other 49 men. So naturally those 49 equivalent wise men should act in the same way and the spokesman should act different ly. Here is one of such strategies: Every one of the 49 (equivalent) wise men should flip the glass upside down the first time that he sees the glass bottom down. He doe s nothing if the glass is already upside down or he has fl ipped the glass once. The spokesman should flip the glass bottom down each tjme he sees the glass upside d ow~ and ~e should do nothing if the glass is already bottom down. After he does the 491h f11~, wh1ch means all the other 49 wise men have been called, he can declare that all the w1se men have been called. 2.5 Series Summation Here is a famous story about the legendary mathematician/physicist Gauss: When he was a chi ld, his teacher gave the chi ldren a boring assignme_nt t~ add the n~mbers from I to 100. To the amazement of the teacher, Gauss turned m h1s answer m less than a minute. Here is his approach: 100 In =I , ,1 100 I l + 2+ ···+ 99+ 100} + + + .:::::::> 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 . l)/ 2 - 100· 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 t1an ptgcons 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 f 1 , · • mn + I ptgeons t I · 0 t lC holes. 1hese sitnple and · · · .~ ' a east 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 throws If I ti . oors, •I the first ball is thro . . t le lrst ball IS thrown once the s~cond Wll 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----<lenoted as x%y or x mod y-finds th~ remainder of divisio~ of number x by another number y. For simpicility, we only consider the case where! Is.a positive integer. For example, 5%3 = 2. An intuitive property of modulo operation IS 22 23 Brain Teasers A Practical Guide To Quantitative Finance Interviews that if XI%Y=X2%Y, x%y, (x+l)%Y, then (XI-X2)%y=O. "', and (x+y-I)%y From this property we can also show that are all different numbers. Prisoner problem One hundre.d prisoners are given the chance to be set free tomorrow. They are all told hat each wII~be given a red or blue hat to wear. Each . ner can see everyone else's at but not hIS own. The hat colors are assigned randomly an nee the hats are placed on top of eac~ priso~er's head they cannot communicate with one other in any form, or else t~ey are ImmedIatel~ executed. The prisoners will be called out' n random order and t~ehPnsonerhcalledout will guess the color of his hat. Each prisoner eclares the color of hi s at so t at everyone else can hear it If . h he i '. I. a pnsoner guesses correctly the color of his at, e IS set free Immediately; otherwise he is executed. They . are given the . night to come . up WIith a strategy among themselves to save as many ble What IS the b t t h pnsoners as POSSI ?14 es s rategy t ey can adopt and how many prisoners can they guarantee to's ave. Solution: At least 99 prisoners can be saved. The key lies in the first prisoner wh be red if the number of red hats he a ca? see everyone.else's hat. He declares his hat to He will have a 1/2 chance f h . sees IS odd. Otherwise he declares his hat to be blue. 0; his Own hat color combin~ng :~m~gue~sed correctly. Everyone else is able to deduce among 99 prisoners (excludi e h edge whether the number of red hats is odd (excluding the first and hims:~ F e irst) and the color of the other 98 prisoners the other 99 prisoners A prison' or example, if the number of red hats is odd among th h . er weanng a red hat will . e ot er 98 prisoners (excludi th fi 1 see even number of red hats III red hat. mg e irst and himself) and deduce that he is wearing a Th~ two-color case is easy, isn't it? What if . white? What is the best strategy the there are 3 possible hat colors: red, blue, and guarantee to save?IS y can adopt and how many prisoners can they the rest of 99 prisoners and calculates s%3. If the remainder is 0, he announces red; if the remainder is I, green; 2, blue. He has 1/3 chance of living, but all the rest of the prisoners can determine his own score (color) from the remainder. Let's consider a prisoner i among 99 prisoners (excluding the first prisoner). He can calculate the total score (x) of all other 98 prisoners. Since (x+0)%3, (x+I)%3, and (x+2)%3 are all different, so from the remainder that the first prisoner gives (for the 99 prisoners including i), he can determine his own score (color). For example, if prisoner l sees that there are 32 red, 29 green and 37 blue in those 98 prisoners (excluding the first and himself). The total score of those 98 prisoners is 103. If the first prisoner announces that the remainder is 2 (green), then prisoner i knows his own color is green (1) since onlyI04%3~2 among 103, 104 and 105. Theoretically, a similar strategy can be extended to any number of colors. Surely that requires all prisoners to have exceptional memory and calculation capability. Division by 9 Given an arbitrary integer, come up with a rule to decide whether it is divisible by 9 and prove it. Solution: Hopefully you still remember the rules from your high school math class. Add up all the digits of the integer. If the sum is divisible by 9, then the integer is divisible by 9; otherwise the integer is not divisible by 9. But how do we prove it? I Let's express the original integer as a == a" 10" + Q,,_IIO"-I+ ... + QIIO + Qo' Basically we state that if a" +Q,,_I+···+al +ao =9x (x is a integer), then the Q is divisible by 9 as well. The proof is straightforward: 1 For any a=a"IO"+Q,,_110"-1+"'+QII0 +Qo' have let b=a-(Q,,+a"_I+'''+QI+ao)' b~a,.(10"-I)+a"_,(10"-'-I)+···+a,(lO'-I)~a-9x, which is divisible We by 9 since all (10k -1), k = 1,·· ',n are divisible by 9. Because both band 9x are divisible by 9, a = b + 9x must be divisible by 9 as well. Solution: The a~swer is still that at least 99" . that. the first prisoner now only has 113 pnsoners wl~1be saved. The difference IS sconng system: red===O green«] d bl _chance of survival. Let's use the following , , an ue-2. The first prisoner counts the total score for (Similarly you can also show that a = (-I)" a" + (-Ir- l Q,,_I+ ... + (-IYal + ao = lIx is the necessary and sufficient condition for a to be divisible by 11.) ;;"-:-H::-' -------tnt: The first prisoner can h odd number of c see t e number of red and blu h IS H' t: Th ounts and the other has even numb feats of all other 99 prisoners. One color has mt: at a number is odd sim I er 0 counts. x%3 instead p y means x%2 = 1. Here we h . ave 3 colors, so you may want to consider 24 25 Brain Teasers A Practical Guide To Quantitative Finance Interviews Chameleon colors (3x + 2,3y,3z + I) = (3x',3y'+ 1,3z'+ 2), A remote island has three types of chameleons with the following population: 13 red chameleons, 15 green chameleons and 17 blue chameleons. Each time two chameleons with different colors meet, they would change their color to the third color. For example, if a green chameleon meets a red chameleon, they both change their color to blue. Is it ever possible for all chameleons to become the same color? Why or why not?16 Solution: It is not possible for all chameleons to become the same color. There are several approaches to proving this conclusion. Here we discuss two of them. Approach 1. Since the numbers 13, 15 and 17 are "large" numbers, we can simplify the problem to 0, 2 and 4 for three colors. (To see this, you need to realize that if combination (m+I,n+l,p+l) can be converted to the same color, combination (m,n,p) can be converted to the same color as well.) Can a combination (0,2,4). ~(O, • (I, 2, (3x, 3y + 1,3z + 2) => (3(x -I) + 2,3(y + 1),3z + I) = (3x ',3y '+ I, 3z'+ 2), onex meets one z { (3(x -1) + 2,3 y, 3(z + I) + I) = (3x',3 y'+ I,3z '+ 2), onex meets one y So the pattern is preserved and we will never get two colors to have the same module of 3. In other words, we cannot make two colors have the same number. As a result, the chameleons cannot become the same color. Essentially, the relative change of any pair of colors after two chameleons meet is either 0 or 3. In order for all the chameleons to become one color, at least one pair's difference must be a multiple or 3. 2.8 Math Induction (0,2,4) be 30 converted to a combination (O,0,6)? The answer is NO, as shown in Figure 2.3: 1,5)~ one y meets one z Induction is one of the most powerful and commonly-used proof techniques in mathematics, especially discrete mathematics. Many problems that involve integers can be solved using induction. The general steps for proof by induction are the following: • State that the proof uses induction and define an appropriate predicate P(n). • Prove the base case P(I), or any other smallest number n for the predicate to be true. • Prove that P(n) implies P(n+l) induction Figure 2.3 chameleon color combination transitions from (0,2,4) argument, for every integer n. Alternatively, you prove that P(l), P(2), "', in a strong and P(n) together imply P(n+I), Actually combination (1,2,3) is equivalent to combination (0,1,2), which can only be converted to another (0, I, 2) but will never reach (0,0,3), In most cases, the real difficulty lies not in the induction step, but to formulate the problem as an induction problem and come up with the appropriate predicateP(n). The AIPI Phroachh 2. A different, and more fundamental approach is to realize that in order for ate c ameleons to become th I ' : e same co or, at certain intermediate stage two colors h must ave the same number T thi . . ' must h th bi . 0 see IS, Just imagme the stage before a final stage. It as e com inatton (1,I,x). For chameleons of two different colors to have the same number their module f'" b 13 3' 0 .} must e the same as well. We start with 15:::: 3x, = y+l, and 17=3z+2 cham I h 'II b . e eon, w en two chameleons of different colors meet, we WI ave three possible scenarios: simplified version of the problem can often help you identify P(n). Coin split problem You split 1000 coins into two piles and count the numb~r of coins in each pile. If there are x coins in pile one and y coins in pile two, you multiple x by y to get -'Y. Then you split both piles further, repeat the same counting and multiplicat.ion process, and add the new multiplication results to the original. For example, you split x to XI and e., y to Yl + Y1Y2' The same process is repeated until you only have piles of I stone each. What is the final sum? (The final 1 's are not included in the and jc, then the sum is XY+X X I 2 sum.) Prove that you always get the same answer no matter how the piles are divided. 16 H' mt: consider the numbers in module of3. 26 27 Brain Teasers A Practical Guide To Quantitative Finance Interviews SoIUfiO~:Le~ n ~e the number of the coins and fen) be the final sum. It is unlikely that a so~ut1onwill Jump to our mind since the number n = 1000 is a large nwnber. If you ar~n t surefihow to approach th~ problem, it never hurts to begin with the simplest cases ~nIt7 todmd a pattern. ~or this problem, the base case has n = 2. Clearly the only split IS + a~ t~e fi~al sum IS 1. When n == 3, the first split is 2 + I and we have .:ry = 2 and Solution: Let m be the number of the rows of the chocolate bar and n be the number of columns. Since there is nothing special for the case m == 6 and n = 8, we should find a general solution for all m and n. Let's begin with the base case where m = 1 and n::::: 1. The number of breaks needed is clearly O. For m > 1 and n = 1, the number of breaks is m -1; similarly for m = 1 and n > 1,the number of breaks is n -I. So for any m and n, ~~is2~~~t ~~I:I:Ill.further gi~e an extra mu1tip~ication result 1,so the final sum is 3. total sun: will bO ~~e; ~he(hmt that when n coms are split into x and n-x coins, the n -xn-x)+j(x)+j(n-x), 4 coins can be split into 2+2 or 3 IF' e + 6. , 'Of either case we can apply x (n-x ) + j( x)+ fen-x) sum and yields the same final if we break the chocolate into m rows first, which takes m -1 breaks, and then break each row into n small pieces, which takes men -1) breaks, the total number of breaks is (m-1)+m(n-l)=mn-1. If we breaks it into n columns first and then break each Claim: For n coins, independent of intermediate splits, the final sum is n(n -1) 2 prove it using strong induction. 17 So how do we prove it? The answer should b I have proved the claim for th b e c ear to you: by strong induction. ease cases n=234' ,. A ssume t hee clai n = 2 ... N -I . c aim IS true . " COins,we need to prove that .t h ld f apply the equation fen) _ () lOS or n = N coms as well. Again If N coins are split into x coins N ~x coins, we have - x n-x + f(x)+ fen-x). j(N)~x(N-x)+ We have shown the number of breaks is mn -I for base cases m :?-I, n = 1 and m=l, u z l. To prove it for a general mxn case, let's assume the statement is true for We for cases where rows < m, columns S n and rows::;;m, columns < n. If the first break is we and total number of breaks is I+(mxnl-I)+(mx(n-nl)-1)==mn-1. j(x) + j(N-x) 2 Soindeectitholdsforn~N as well and j(n)_n(n-l) , th I' 2 IS true for any n 2: 2 , Applying e cone usron to n --1000 ,we have j(n) ~ 1000x999/2, A chocolate bar has 6 rows and 8 I ' dtIVIidual squares by making a numb co umn s (48 sma 1I l x l squares). You break it into In ~wo.smaller rectangles. For example ~~;:; b~eaks. Each time, break one rectangle into ar IOta a 6x3 one and a 6x5 one Wh' ~ irst step you can break the 6x8 chocolate IS the total n urnb er 0 f b reaks needed in order to break the coco hi' ate bar Into 48 s ,at II rna squares? !(n)-",1+2+"'+(n_l)=o n(n-I) 2 28 Here we use the results for rows:$ m, columns < n. Similarly, if it is broken into two pieces 1111 x nand Although induction is the standard approach used to solve this problem, there is actually a simpler solution if you've noticed an important fact: the number of pieces always increases by 1 with each break since it always breaks one piece into two. In the beginning, we have a single piece. ln the end, we will have mn pieces. So the number of breaks must be mn-1. Chocolate bar problem and J(4)-J(])- m x nl and m x (n - nl), then the )xn, the total number of breaks is 1+(m1xn-I)+((m-ml)xn-l)=mn-1. So 1 the total number of breaks is always mn -1 in order to break the chocolate bar into mx n small pieces. For the case m = 6 and n = 8, the number of breaks is 47. = N(N -I) 2 JO)-J(2)'2 along a row and it is broken into two smaller pieces (m-11l ~x(N -x)+ N(~ -1) + (N -x)(N -x-I) " J(2)~I, column into m small pieces, the total number of breaks is also mn -1. But is the total number of breaks always mn -I for other sequences of breaks? Of course it is. We can ' - 3 should give you enoug h hi hint to realize the pattern is Race track Suppose that you are on a one-way circular race track. There are N gas cans randomly placed on different locations of the track and the total sum of the gas in these cans is enough for your car to run exactly one circle. Assume that your car has no gas in the gas tank initially, but you can put your car at any location on the track and you can pick up the gas cans along the way to fill in your gas tank. Ca~ yo~ alw~~s choose a starting position on the track so that your car can complete the entire Circle? 18 Hint: Start with N = 1,2 and solve the problem using induction. 29 Brain Teasers A Practical Guide To Quantitative Finance Interviews Solution: ~f you get stuck. as to ~ow to ~olve ~he problem, again start with the simplest ca~es (N -1,2) and c.onslder usmg an induction approach. Without loss of generality, let s assume that the circle has circumference of 1. For N --, I th e pro bl em .IS tnviat. .. I J US! s~art a~where the gas can is. For N == 2, The problem is still simple. Let's use a figure to visualize the approach. As shown in Figure 2.4A, the amount of gas in can I and can 2 expressed as the distance the car can travel, are XI and x2 respectively, so Xl + X2 = I~ The corresponding segments are YI and Y2' so YI + Y2 == 1. Since XI + x2 == I and YI + Y2 = I, we must have x > y or I I x2 > - Y2 ( Xl < YI an d X2 < Y2 cannot both be true). If XI ~ YI ' we can start at gas can 1, which has enough gas to reach gas can 2 and get more gas from gas can 2 to finish the wh I . I O' ' and pick up gas can I I hoe Cl~Ce. therwise, we will just start at gas can 2 a ong t e way to fimsh the whole circle. which the statement holds. So the statement also holds for N == n + 1. Hence we can always choose a starting position on the track to complete the entire circle for any N. There is also an alternative approach to this problem that provides a solution to the starting point. Let's imagine that you have another car with enough gas to finish the circle. You put that car at the position of a randomly chosen gas can and drive the car for a full circle. Whenever you reach a gas can (including at the initial position), you measure the amount of gas in your gas tank before you add the gas from the can to your gas tank. After you finish the circle, read through your measurement records and find the lowest measurement. The gas can position corresponding to the lowest measurement should be your starting position if the car has no gas initially. (It may take some thinking to fully understand this argument. I'd recommend that you again draw a figure and give this argument some careful thoughts if you don't find the reasoning obvious.) 2.9 Proof by Contradiction x, In a proof by contradiction or indirect proof, you show that if a proposition were false, then some logical contradiction or absurdity would follow. Thus, the proposition must be true. Irrational number X, Can you prove that J2 is an irrational number? A rational number is a number that can be expressed as a ratio of two integers; otherwise it is irrational. Xi A Figure 2.4 Gas can locations on the cycle Yi B d an segments between gas cans . The argument for N == 2 a Iso gives us the h' show that if the statement holds for N _ tnt for the induction step. Now we want to N = n + I. As shown . F' - n, then the same statement also holds for III tgure 2.4B we h Yl+Y2+"'+Y ==1l':orN ' ave XI+X2+"'+x ,=1 and 11+1 11 ==n+l. So there muer avr 11+ has X Y , That means h e must exist at least one i, lsi:::; n + I, that I . . w enever the car reache' . (Forl=n+l It goes to . Li s Xi' It can reach x. With more gas , 1 == Instead). In other word 1+1 X,+I to one gas can at the .. s, we can actually "combine" .r. and h POSItion of x. with ' t e gas can i+I). But such binati an amount of gas x·+x (and eliminate com matron reduce th N I 1+1 S e == n + I problem to N = n, for j 30 Solution: number, common the end, This is a classical example of proof by contradiction. If J2 is not an irrational it can be expressed as a ratio of two integers m and n. If m and n have any factor, we can remove it by dividing both m and n by the common factor. So in we will have a pair of m and n that have no common factors. (It is called J2, irreducible fraction.) Since m/ n = we have m = 2n • So m must be an even number and m must be an even number as well. Let's express m as Zx, where x is an 2 2 2 integer, since m is even. Then m2 = 4x2 and we also have n = 2x , which means n must be even as well. But that both m and n are even contradicts the earlier statement 2 that m and n have no common factors. So J2 2 must be an irrational number. ~ Rainbow hats Seven prisoners are given the chance to be set free tomorrow. An executioner will put a hat on each prisoner's head. Each hat can be one of the seven colors of the rainbow and the hat colors are assigned completely at the executioner's discretion. Every prisoner can 31 Brain Teasers see the hat colors of the other six prisoners, but not his own. They cannot communicate with others in any form, or else they are immediately executed. Then each prisoner writes down his guess of his own hat color. If at least one prisoner correctly guesses the color of his hat, they all will be set free immediately; otherwise they will be executed. They are given the night to come up with a strategy. Is there a strategy that they can guarantee that they will be set free?l9 Solution: This problem is often perceived to be more difficult than the prisoner problem in the modular arithmetic section. In the previous prisoner problem, the prisoners can hear others' guesses. So one prisoner's declaration gives all the necessary information other prisoners need. In this problem, prisoners won't know what others' guesses are. To solve the problem, it does require an aha moment. The key to the aha moment is given by the hint. Once you realize that if we code the colors to 0-6, (t x, ) %7 must be among 0, 1,2, 3, 4, 5 or 6 as well. Then each prisoner i-let's label them as 0.6 as well-should give a guess gi so that the sum of gi and the rest of 6 prisoners' hat color Chapter 3 Calculus and Linear Algebra Calculus and linear algebra lay the foundation for many advanced math topics used in quantitative finance. So be prepared to answer some calculus or linear algeb~a problems-many of them may be incorporated into more. complex problems-Ill quantitative interviews. Since most of the tested calculus and linear algebra. knowledge is easy to grasp, the marginal benefit far outweighs the time'y0u spend br~shll~g up your knowledge on key subjects. If your memory of calculus or lmear algebra IS a little rusty, spend some time reviewing your college textbooks! Needless to say, it is extremely difficult to condense any calculus/linear algebra books into one chapter. Neither is it my intention to do so. This chapter focuses only o~ so~e of the core concepts of calculus/linear algebra that are frequently occurrmg m quantitative interviews. And unless necessary, it does so .~itho~t covering the proof, details or even caveats of these concepts. If you are not familiar WIth any of the concepts, please refer to your favorite calculus/linear algebra books for details. codes will give a remainder of i when divided by 7, where g; is a unique number between a and 6. For example, prisoner a's guess should make This way, we can guarantee at least one of gi == Xi for i = 0,1,2,3,4,5,6. We can easily prove this conclusion by contradiction, (since ( s, + t;x, )%7" i and i = 0,1,2,3,4,5, and 6, then e, and ':ol at least one of g must equal t i 0 to be set free. Xi' A If e. "x" then X, are both between 0 and 6), But if (~X)%7" LJ , (go + LX ,,0 k )%7 == O. (tx, Basics of derivatives Let's begin with some basic definitions and equations used in lim.its ~d derivatives. Although the notations may be different, you can find these materials III any calculus textbook. )%7" s, "X, 3.1 Limits and Derivatives i Derivative: for all 0, 1, 2, 3, 4, 5, 6 ,w h'rch iIS c Iear I'y rmpossi ibt e. So . S a result, usmg this strategy, they are guaranteed Let y = f(x), The product rule: d(uv) dv du -=u-+v-. dx dx dx The quotient rule dy , Lly , then rex) = dx = t':'o LIx = If u == u(x) and v = v(x) and their respective derivatives ( uv-u )'_ 'v+uv' ~(: )+~-u:)jv', (~)=u'7v' The chain rule: If y = f(u(x)) 19 ' ( H' t L' . tnt: et s assign the 7 colors of rainbow with cod ) e 0-6 and Xi be the color code of prisoner i. Then %7 must be 0, 1,2 3 4 50r6 How I., , " . many guesses can 7 prisoners make? L>, 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+!<x .. --;0 X Local maximum or minimum: suppose that J(x) is differentiable at c and is defined on an open interval containing c. If J(c) is either a local maximum value or a local for any r>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 .<-+:og'(x) not in the d Ir b k" (k k+ 1 '* I), where C IS any H x-.a g(x)· - I'umev.r e - e <-->'" li~x2Inx=Iimlnx=li x-->~ a) integrals: du~g'(x)dx r f(g(x))' 1, Solution: This is an example of integration d(uv) = vdu + udv ~ (x x IIx)dx+ Inxdx, li to lim ,HO', the original co and !!~o.In x ==-co. ,~ d(lnx)ldx , d( 2) I dx ==lim X in definite with u~g(x), g '(x)dx ~ f(h J/i(aj i f(u)du A, What is the integral ofln(x)? X~ - owever, we can rewrite x-.O· ff(u)du , co an d I'Img(x)==hm2x:::=00,so X-a) lim x-2 == that rule: x-+O' X -2 , ff(g(x)),g'(x)dx= Integration by parts: JUdv ==uv- JVdu d( ')1 e dx eX -x~2x ==}!!!'d(2x)ldx ==~~2==oo e format of lim f(x) ecomes obvious L'Hospital's U constant. Substitution I d s ru e oes not appear to be applicable At first look, L'Hospital' t_O lim eX ==00 and x~"'2x I we can app y the L' Hospital's rule again: It SInce f'( x ) , _ ==lirn!...- lim __ The result still has the property that -"-",,, lim f(x) an rule ==00. Applying L'Hcspital's rule, we have lim--== x~a g(x) f k u du ==--+c Integration by substitution: lim;" t~'" f(t)dl x-->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'<'1 a/'t" Since it's true for all e Isquare from the intersection as well. So z va ues, we have V:;ploere -- 141l (')3 2" = .!L V 4 Intersect,OJ!:::::> 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:<; n. fe-"l2dx~J%- If you've forgotten the pdf of the standard normal distribution or if you are specifically asked to prove is Jz;e-"l2dx=l=> 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<O and x 2':x 2':0 if x o Il . and e z z.we have »c-D, (n-l»O,(1+x)"-2 Hence, n(n-I)(1+x)"-'x22:0 2 >O,x 2':O. and J(x)=(I+x)">I+nx. If Taylor's series does not jump to your mind, the condition that n is an integer may give you the hint that you can try the induction method. We can rephrase the problem as: for Solution: The solution to this probl can be proven using Taylor's seri eLmuses Euler's formula, e" ==cos19+isinB which ,e nes, et's look h ' e ,cos8 and sin 8, Wehave at t e proof Applying Taylor's series to eiU = I iIJ (i1J)' + +-+ I! 2! IJ' IJ' (i1J)3 ('IJ)' 1 31+-;-+ . 4. If cosB=l __ + 2! 4T-6T+'" . OS 87 sm8=19 __8 +_ 3! 5! -71+''':::}isin8=i 3 . 0 IJ' 3 4 ..·=I+i·O 0 .BS II 21 '31+-+1-+ ... . . . 4! 5! 8 __ i~ }1 . every integer n 2':2 , prove (I + x)" 2':1+ nx for 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 <0<1 h (X,,-X )2 ,were xf is the solution to !(x)=O. J(a,+b,)/2). x2 =. Solution: Let J(x)=x2-37 x;-37 2x o we set b,,, =b" and 36-37 2x6 =6.083. =6 . If you do not remember Newton's meth d . O ,you can directly apply Taylor's function f(x)=-/; with f'(x) =.lx_112. 2 If = 0, or its The X/HI-XI bisection method converges linearly, ::; 0 < 1, which means it is slower than - ---k~t Newton's method. But once you find an Go/ bo pair, convergence is guaranteed. 1 ... =X - "J( x" -X,,_I x" )-J( xn_1 ) J(x ). It replaces the f'(x " XI " and applies the iterative step ) in Newton's method with a linear approximation f(x,,)- [(x" I). Compared with Newton's method, it does not x" -X"_l require the calculation of derivative f'(x,,), which makes it valuable if f '(x) is difficult --- to calculate. Its convergence rate is (I + (6.083 = 37.00289, which is very close to 37.) a,,, =(a,+b,)I2; absolute value is within allowable error, the iteration stops and x='(G" +bJ/2. th 2 J(37)~ J(36) + 1'(36)(37-36) O. At each step, we check the sign of J( (a" +b")/ 2) > 0, we set a,., = a, and b"., = (a" + b")/2; If I( (a" +bJ/2) x .. , e onginal problem is e . I I· J() 0 Xo =. 6 is a natural initial guess. Applying N ' qurva ent to so vmg x = . ewton s method, we have x =x _ J(xo) _ 1 0 J'(x ) -xoo If J«a,+b,)/2)<0, =. Secant method starts with two initial values xO' 37 to the third digit. IS Bisection method is an intuitive root-finding algorithm. It starts with two initial values aoand bo such that J(ao) < 0 and J(bo) > 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"<". »e (III,",=e"'=x I and r: are real and 'i which means I(x) is a Solve ordinary different equation y'+ y = --\-, y(1) = 1, where x> O. x x Solution: This is a typical example of f1 3. If rl and = I(x)?(x), then the general solution is y = cle'lX + c2e'2X ; I. If I'mear + b dy +c = d(x) has no closed-form solution. But if we can find a dx solution "- Yr(x) d' d for a--?+b-.!+c=d(x), dx dx then y=y,(x)+ y,(x), where , - , ' d'y dy the general solution of the homogeneous equatIOn a""""d7"+b-;;;+c=O, IS IS a , d'y dy general solution of the nonhomogeneous equatron a dx2 -r b dx +c = d(x). mear equation, then any y( ) _ () arbitrary constants is a I t' x - CIYI x +C2Y2(X), where c\ and c2 are , so U Ion to the homo li Wh b geneous mear equation as well en a, and c (a*O) are constants' d ' mstea of functions of x, the homogeuow linear equation has cia de. se lorm sOlutIOns: Let r: and r be th 1 2 e roots of the characteristic equation ar2 + br + cu~ 0 9 v B The Constant c is not needed' 48 In th' IS . case Since itjust , I sea es both sides of the equation by a factor. 9 . A quadratic . ' equation ar"+hr+c=O . has roots given by qua d 'c railC I -b+..}b'-4uc lonnua r=o should either commit the fonnula to memory or be able to derive it using (r + bI2a)' = 'a . You (b' - 4ac)/4a' . 49 Calculus and Linear Algebra A Practical Guide To Quantitative Finance Interviews Alth~ugh it may be difficult to identify a particular solution YI'(x) in general, in the Inner product/dot special case when dCi) is a simple polynomial, the particular !'olynomial of the same degree. y is defined as What is the solution ofODEsy"+ y'+ y = 1 and Solution: In these ODEs, we again have a complex solutions r~-1/2±J312i y"+ y'+ Y = b ~ c --1 (a~-1I2 , fJ-- solution is often a = x? Euclidean an d b' - 4ac = -.)' < 0 so we have "/2) an d th e general' solution ., IS '\Ij Y '"+Y+Y= a +m+(mx+n)=x:::>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:; (<~nd row:\} of Q ~ Q · Q ts orthogonal if and only tt the onhonof]nalization r oml an orthononnal s dccOtnlO!iition PI. ~ ocess (often improved to ' et of vectors in R·. The Gram-Schmidr . ca~ refer to a linear algebra textb·:~e:r~ nume.rica l stability) is often used for QR 5'> }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<E >' 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 =<I> 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 >< 13x51 ~~ ~ Your card has a nwnber larger than the dealer' s· EJ. your card has a number equal to the dealer's. . El : Your card has b ' anum er lower than the dealer's. Again by symmetry. P(£) = p I (£,). pro ba b'l' I uy that two cards h · So we onlY need to figure out P( E2 ). the Arnon th · · ave equal value Let's g e remammg 51 cards on! say you have randomlv selected a card. t1lt! probability that the two ca.rds h)' 3 car s will have the same value ~s your card So Lhat yo u wm · ·ts J>( £ ) == (1- P(E ))I?_ ave(lequal valu c Js · 3/5 I. As a result, the probability · 1 2 - - 3151 )12== 8/i7. 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 ·· <~&am. If )·ou d .d· , comp1tcated co d' . .mcrem· 1 ec• I! to star! wu, .I a · n lllonal P"ob b' l· • 5Imp1er version of' tt a 1 1ty to so 1ve the problem. go back and th1n~ ·- . 101-' lll! number of pa c1l1Cil'nth. o ssengers to ·h 1e problem t 11 · . ~·J . . .•. nur t1le probl~m i~ I . . s ow a pattern b . d . , s a mg Wllh two passengers anu nn mluJIIVC t~n~wer . lluch Simpler than that F y tn uctlon, you can solve the problem rnor~ . ocus on eve nts an d symmetry and vou will have 62 £ 1 : Seat # I is taken before #I 00; Solution: Let's start at one point and clockwise label the points as I, 2. · · ·, N. The probability that all the remaining N -1 points from 2 to N are in the clockwise semicircle starting at point 1 (That is, if point 1 is at 12:00, points 2 to N are all between 12:00 and 6:00) is 1/2'' ' 1 • Similarl y the probabi li ty that a clockwise semicircle starting at any point i, where i e {2, .. ·, N} contains all the other N -I points is also l I 2.v-1 • Claim: the events that all the other N -l points arc in the clockv.~se semicircle starting at point i, i = l. 2~···, N are mutually exclusive. In other words, if we. starting at point i and proceeding clockwise along the ci rcle, sequentially encounters points i + l, i + 2, · ·. , N, 1, · · ·, i - 1 in half a circle, then starting at any other point j. we cannot encounter all Hint: Consider the events that starting from a point 11, you can reach all the rest of the points on the circle clockwise. n e {I •... , N} in a semicircle. Are these events mutually exclusive? 4 • 63 Probability Theory A Practical Guide To Quantitative Finance Interviews other p.oints within. a clockwise semicircle. Figure 4.1 clearly demonstrates this conc lu s ~ on. If startmg at point i and proceeding clockwise along the circle. we sequent_tally encounter points i + I, i + 2, .. ·• N, 1., ... , i -1 within half a circle, the clockwt~e a~c between i -1 and i must be no less than half a circle. If we stan at any other pomt, m order to reach all other poiots clockwise, the clockwise arc between i- 1 and are always included. So we cannot reach all points within a clockwise semicircle starling from any other points. Hence, all these events are mutually exclusive and we have ! p( UE,l \' N •· f = IP<E, )~P UE, Ji= Nx l i 2"''-1 (N • I • n1 possible first entries, • • n 2 possible second entries for each first entry, n possible third entries for each combinatio n of first and second entries, etc. 3 Then there are a total of n1 • 172 • • • nk possible outcomes. Permutation : A rearrangement of objects into distinct sequence (i .e., order matters). n! Property: There are 1 =N I 2"'- different pennutations of n objects, of wh ich n1 are n1 !n2 !...nr! 1 alike, I ~f:lc sa~)~ argumct:t can be extended ~o any arcs that have a length less than half a circle. the r.a~to o~ the arc _leng~h .to the Circumference of the circle is x ( x ~ 1I 2 ), then the probabthty ot all N pomts tmmg into the arc is N x XN-1 . 172 are alike, · · ·, n, are alike. Combination: An unordered collection of objects (i.e., order doesn't matter). Propeny: There are ( 11 ) r r = n! different combinations of n distinct objects taken (n-r) !r! at a time. t( 17 Binomial theorem: (x+ y)" = k k=-0 ) xky"-• lnclusion-Exclosion Principle; P(£1 u £ 2 ) =P(EI) + P(£2)- P(£,£?) P(£ 1 u £ u £ ) = P(£1) + P(£2 )+ P(£3 ) - P(£,£2 ) - P(E1EJ)- P(£2£ 3) + P(£,£2 £~ ) 2 3 and more generally, +(-1) N+l P( EI E2 ... E.'J ) Figure 4.1 N points fall in a clockwise se .. mJclrcle starting from ; 4.2 Combinatorial Anal . Many problems in prob b't· YSIS d'fll . a t tty theory ca b . . 1 crent \\·ays that a certain evem n e solved by stmply counting the number ot often rdt!rred 1·o as combtnatorial . can occur . hcmat1c · thcorv ot, cow1t1ng · IS· . · The mat 1 c~)ver the basics of combinator"tal ania ~sts (or combinatorics). In this 'seclion we will , . ana YSIS. ' Uasac prmciple of counting· Let <'1 b · • e a set of 1ength-k sequences. If there are where L ,, ( 11 <.. P(E,, £ 1! ..• £,. ) has ( ~ \) terms. 1 ,, Poker hands Poker is a card game in which each player gets a hand of 5 c~rds. There are 52 cards in a deck. Each card has a value and belongs to a su1t. There are 13 values, 2, 3. 4. s. J·••k qu~cu ~~ r.~ au: 6. 7, 8. 9, 10, ~!J<"lc dub b~~11 ,r,:un .n.l J. Q, K. A. and four suits, • , 4, ., , + . 65 Probability Theory A Practical Guide To Quantitative Finance Interviews What are the probabilities of getting hands with four·of-a-kind (four of the five cards with the same value)? Hands with a full house (three cards of one value and two cards of another value)? Hands with two pairs? Solution: The number of different hands of a five-card draw is the number of 5·element 52 suhscts of a 52-clement set, so total number of hands = ( ) = 2, 598.960. \5 Hands with a four-of·a-kiod: First we can choose the value of the four cards with the same value. there are 13 choices. The 5th card can be any of the rest 48 cards (12 choices for values and 4 choices for suits). So the nu mber of hands with four-of-a kind is 13x48 =624. Hands wit~ a Full House: In sequence we need to choose the value of the triple. 13 . h . f' ch01ces~ t e su1ts o the triple, ) choices; the value of the pair, J2 choices; and the 3 l/41 suits of the pair, (; 13x(;} Jchoices. So the number of hands with full house is 12x(~) = 13x 4x 12x6= 3, 744. Hands with Two Pa irs· In .. LJ) ~· · sequence we need to choose the values of the two pa1rs. h · ~~ 4j\ choices~ the suits of the second pajr. (4 1 , ) ( 2. choices·· the ·s UJ' ts 0 f t e first pair, , 2 2 chotccs: and the remaining d 44 ( 52 . car • -4 x 2, since the last cards can not have the same value as etther pair) ch · • S h otccs. o t e number of hands with two pairs is (~H ~H~Jx44 = 78x6x 6x44 =123,552. To calculate the probability of ea ·h . . . b c r' we only need to dtvtde the number of hands ot each kind by the total possibl · e num er o hands. Hopping rabbit A rabhit sits at the bottom of a stairc . . two stairs at a time How d'ffiase Wtth n stau s. The rabbit can hop up only one or top of the stairs?5 · many 1 erent ways arc there fo r the rabbi t to ascend to the ' Hint: Consid~!r an induct' ; I . IOn approach. Befo th ell 'ei the (n-l)th statr or the (n-'>)th st · r~ e final hop to reach the n-th stair the rabbit can be ai • • a1r assummg n > 2_ Solution: Let's begi n with the simplest cases and consider solving the problem for any number of stairs using induction. For n =I , there is only one way and /(1) = 1. For n == 2, we can have one 2-stair bop or two !-stair hops. So .f(2) = 2. For any n > 2, there are always two possibilities for the last hop, either it's a !-stair hop or a 2-stair hop. ln the former case, the rabbit is at (n- 1) before reaching n, and it has /(n-1) ways lO reach (n -I). In the latter case, the rabbit is at (n- 2) before reaching n, and it has f(n - 2) ways to reach (n-2). So we have f(n)=f(n-2)+/(n - 1). Using this function we can calculate f( n) for n = 3, 4, · · · 6 Screwy pirates 2 Having peacefully divided the loot (in chapter 2), the pirate team goes on for more looting and expands the group to ll pirates. To protect their hard-won treasure, they gather together to put all the loot in a safe. Still being a democrutic bunch, they decide that only a majority - any majority - of them (2:6) together can open the safe. So they ask a locksmith to put a certain number of locks on the safe. To access the treasure, every lock needs to be opened. Each lock can have multiple keys; but each key only opens one lock. The locksmith can give more than one key to each pirate. What is the smallest number of Jocks needed? And how many keys must each pirate cany?7 Solution: This problem is a good example of the appJ i ~ation of combinatorial a naJ ys~s in information sharing and cryptography. A general versiOn of the problem was expl~1ned in a 1979 paper "How 10 Share 0 Secret" by Adi Shamir. Let's randomly select 5 ptrates from the 11-member group; there must be a Jock that no~e of them h~s the key to. Yet any of the other 6 pirates must have the key t~ this lock smce. any 6 ptrates can open all locks. In other words, we must have a "spectal" lock to whJch none of the 5 selected pirates has a key and the other 6 pirates a~! have keys. Such 5-pirate g~oups .ar~ randomly selected. So fo r each combination of 5 ptrates, there must be such a special lock. The minimum number of Jocks needed .IS (IJr) = 11!! !:::: 462 locks. . Each lock has 6 keys, 56 5 which are given to a unique 6-member subgroup. So each pirate must have 4 62 x 6 = 252 kcvs. That's surely a lot of locks to put on a safe and a lot of keys for 11 .. each pirate to carry. 6y · ed that the seqtl•'ncc is a cPC!tJCnce of Fibonacci numbers. ou may have recogmz "' J~t • • H'mt: every su bgroup o f 6 p1ra · tes should have the same kcv to a umque lock that the other 5 pirates do • not have. 1 67 Probability Theory A Practical Guide To Quantitative Finance Interviews Chess tournament A chess tournament has 2'' players with skills I > 2 > · · · >2n. It is orgaruzed as a 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 T-1 -2 -_ 2 x (2n-2 -1) ,-1 _ n_ _ • We can repeat the same 2 1 2 1 1 process untt'I thc (n -l)th d · . roun • m whtch there are 22 (= 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) - 1] -- -I - ?1 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 + ? ? 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 2"" 1 players 2"' 1 players A 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<:sJ J I • 1 How many people do we need in a class to make the probability that two people have the same birthday more than 1/2? (For simplicity, assume 365 days a year.) I be calculated using the Inclusion-Exclusion Principle: I Birthday problem 5 We want to fi nd the number of those sequences that have no duplication of birthdays. For the first individual we can choose any of the 365 days; but for the second, onJy 364 ' . remaining choices left, ... , for the rth individual, there are 365 - r + 1 chotces. So for n people there are 365 x 364 x · · · x (365 - n + l) possible sequences where no two . I s It, s obv10us that P( E,) = \i i = l, ... , 5 . So P( £,) =I. L S. 1~1 365 X )64 X · ·· X (365 - n + 1) P( E' 1E'! ) is the event tl1at both 1ctter 1· and 1etter 1,. have the correct envelope. The 1 probability that ;, has the correct envelope is l/5; Co~ditioned on that i has the correct 1 envelope, the probability th t 1· h a ~ as the correct envelope is 1/4 (there are only 4 en\'elopes left). So P(E,/.) = ~ x ~ == (5 ) 5-1 2)1 5! )=2!(5-5! 2)! members of, P(E,. E,) 5 There an! ( \2 in LP(E, E, ) , so we have 1 individuals have the same birthday. We need to have , 365 < 112 for the odds to be in our favor. The smallest such n is 23. 100th digit What is the 100th digit to the right of the decimal point in the decimal representation of (l + J2 ) 3000 ?10 l Solution: If you still have not figure out the solution from the hint, here is one more hint: (I + J2 )" + ( 1- J2)" is an integer when n == 3000 . Applying the binomial theorem for (x + y)", we have (l+-'2)" =t.(:}"-•-'2' =. 't)~}·-•-'2' ~ + ,_, Hint: ·n,e complem\!nt is that at least o I . . ne ettcr IS maJied to the correct finn. 70 ]IJ Hint: (I - ) : }· J2 ): + (l - J2 r : 6 . What will happen to (I - .fi )~n as 11 ' J2' becomes large? 71 Probability Theory A Practical Guide To Quantitative finance Interviews Law o(tota/ probahiliry: fo r any mutually exclusive events {r;}, i=l ,2, .. ·,n, whose n So (I + v£ r;:; )" +(J -Ji)" -2 - (nJl"-1 "Lrt , whrch· .rs always an .mteger. It is easy to "" union is the entire sample space ( F, n Fi = <1>, "if i :;t: j; 1=1 k=!;;;s.~ k P(E) 2 see that 0 <(1- fiiooo << w-' 00. So the JOOth digit of (l + .fi)" must be 9. UF, = n ), we have " = P(EF;) + P(EF;) + .. . + P(EF,,) = LP(E I F, )P(F,) /cl = P(E IF; )P(f;) + P(E I f;)P(F; ) + · ·· + P(E I F,,)P(F,,) =P(E)P(F) ~ P(EFc ) = P(E)P(F(.) . Cubic of integer Independen t events: P(EF) Let X be an integer between J a d I o'2 h 15 . . with II ?" n 'w at the probability that the cubic of x ends Independence is a symmetric relation: X is independent ofY P(E IF1 )P(F) Bayes' Formula.· P(F, 1E) = , Solution: All integers can be e d A . xpresse as x = a+ IOb, where a is the last digit of x. pplyrng the binomial theorem, we have ~ = (a+ 1Ob) 1 = 0 J + 300 2b + JOOab2 + OOOb;. 1 ' ,L P(E IF,.)P(F,) ,.., ·c 1 rc;. 1· c:> = Y is independent of X. I, · · ·, n, are mutua IIy exclusive events whose union is the entire sample space. 3 The unit digit of x onlv d d :l 3 this requ'rc t d .{ epe~ son a . So a has a unit digit of 1. Only a= l satisfies t men an " =1 Smce aJ - I 1J1 . . , so "'e, must · - • e tent h dtglt only depends on 30a·b = 30h. have that 3b ends in l wh' . • ' tch reqUi res the last digit of b to be 7. Consequentlv the last two d. . ·Integers between '' 1 and 10'2. rgtts otxshouldbe71 ' wh'hh .. of 1% Jor r: IC as a probab1ltty 4.~ Conditional Probability and Bayes' formula Many .tinanctal transactions are res onses .. . most l1kely incomplete- · r .P to probabtlr ty adjustments based on new-and tn10m1at1on. Co d·r .. popular tt:s! subjects in quant't t' . n .1 JOna 1 probabthty surely is one of the most . . .. 1 a tve mtervrews s · h' condtltonal probability defi ·t· , · o m t 1s section, we focus on baste lilt tons and theorems. Conditional p b bT ro a 'tty P(A I B): If P(B) > 0, then P(A / 8) = P(A B) is the fraction of B Outcomes that are also if P(B) .· outcomes. Multiplicntion Ru/1!: P( El £ , ... E == , ) P(EI)P(E2 1EI)P(£J I E,£2) ·· ·P(E., 1£, .. . £ ,). As the following examples will demonstrate, not all conditional probability problems have intuitive solutions. Many demand logical analysis instead. Boys and girls Part A. A co mpany is holding a dinner for workjng mothers ~ith at least one so n. Ms. Jackson, a mother wi th two children, is invited. What is the probaffitity tl1at both children are boys? r, > J ~.. .... , k Solwion: The sample space of two children is given by n = {(b ,b), (b,g),(g,b),(g,g)} (e.g., (g , b) means the older child is a girl and the younger child a boy), a.nd each outcome has the same probability. Since Ms. Jackson is invi ted, she has at least one son. Let B be the event that at least one of the children is a boy and A he the event that both children are boys, we have P(AIB)= P(A nB) = - P( {(b,b)})~ == 11 4 =~ . P(B) P({(b,b),(b,K),(g,b)}) 314 3 Part B. Your new collcaoue, Ms. Parker is known to have two children. If you see her walking with one of her ~hildren and that child is a boy. what is the probability that both children arc boys? " trrnt: rlrc h~ttwo digits of rJ . I on y depend on the last two digits ofx. 73 Probability Theory A Practical Guide To Quantitative Finance Interviews Soltllion: the other child is equally likely to be a boy or a girl (independent of the boy you've seen), so the probability that both children are boys is 1/2. Notice the subtle difference between part A and part B. In part A. the problem essentiallY asks given t~ere is at least one boy in two children, what is the conditi onal probabi lit)· that ??lh chtldren .a.re boys. Part 8 asks that given one chi ld is a boy, what is the cond1t10nal probab1hty that the other child is also a boy. For bo th pans. we need to assume that each child is equal likely to be a boy or a girl. up heads. So P(B I A'') = (1/2) 10 = J/ l 024. Plug in all the available information and we have the answer: P(A I B)= P(B I A)P(A) = 1/JOOOxl ~o.s. P(B I A)P(A) + P(B I Ac)P(A'' ) 1/1 OOOx 1+999 / 1000 X 1/ 1024 Fair probability from an unfair coin If you have an unfair coin, which may bias toward either heads or tails at an unknown probability, can you generate even odds using this coin? All-girl world? In a primitiv~ society, every couple prefers to have a baby gi rl. There is a 50% chance ~hat each chtld they have is a girl, and the genders of their children are mutually mdependent. ~f each co~ple insists.on having more children until they get a girl and once tfrhey .have a ~~rl .they. W ill stop havmg more children, what will eventually happen to the act ton of g1rls m th1s society? Solwion: · . . b· bT It was surprisino . 0 that many mtervtewees-mclude many who studied ~ro ; ~,Ity~have the ~ms~onceptioo that there wi ll be more girls. Do not let the word ~~c er an Ia wrong tntUition misguide you. 'lbe fraction of baby girls are driven b" tM ure, or at east the X and y chromosomes b . . ' not Y the couples' preference. You only need to look at th k . [I equal probability ~f :~~~ ~r:atlon: 5?% and independence. Every new-born child has So the fnction of g· b::> . Y or a gtrl regardless of the gender of any other children. 1 < · · · · 'II stay stable at 50%. 1r s orn IS always SOo/c0 and tl1e r.HactJOns of g1rls m the soctety w1 Unfair coin You are given 1000 coins i\.m h . coins an: t~tir coins. y ~ ·ra d onT t -~n, 1 com ?as heads on both sides. The other 999 coin turn::; up heads. What i~ ~h~mr~bc ~~se a com an~ toss it I 0 times. Each time. the P ability that the com you choose is the unfair one? 0 Solution: Un like fair coins, we clearly can not generate even odds with one toss using an unfair coin. How about using 2 tosses? Let pH be the probability the coin will yield head, and Pr be the probability the coin will yield tails (PH+ p., =l ). Consider two independent tosses. We have four possible outcomes HH, HT, TH and 1T with probabilities P(HH)=PHPH• P(HT)=P"Pr• P(TH )=PrPH• and P(TT)=PrPr· So we have P( HT) =P(TH). By assigning HT to winning and TH to losing, we can generate even odds.12 'r I..J ~ J. r ){I 0 I , 'I i. r Vo Dart game Jason throws two darts at a dartboard, aiming for the center. The second dart lands farther from the center than the first. If Jason throws a third dart aiming for the cenler, what is the probability that the third tluow is farther from the center than the first? Assume Jason's skillfulness is constant Solution: A standard answer directly applies the conditional probability by enumerating all possible outcomes. If we rank the three darts' results from the best (A) to the worst (C), there are 6 possible outcomes with equal probability: Sulwiun: This is a chssic co0 d't' 1 1 11 I A beth~ event that ~~~ ·c hos ? ~ probability question that uses Bayes , theorem. Let · · ·en com ts the unfa·tr one, then Ac is the event that the chosen (:Otn •s a tair ont!. Lt:t IJ be th e event that aH ten tosses tum u head A lv Bayes· theorem have P( .l l B) :: P(B I A)P(A)::: P(B I A)P(~ s. PP. ''e . . P(B) P(B I A)P(A) + P(B; A'.)P{A<'). 1 he pnor.> 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!J<J.Eing wtlh_g /li(Ued Corn by Qucntm F. Stout and Bette L. Warren. Annals ofProbab1hLy I:!Il QS·n. PP· 2 12-222 12 75 2& Probability Theory A Practical Guide To Quantitative Finance Interviews Outcome 2 3 4 5 6 1st throw A 8 A c B c 2nd throw B A c A c B 3rd throw c c B B A A don't know anyone else's birthday and all binhdays are distributed randomly throughout the year (assuming 365 da,i's in a year), what position in line gives you the largest chance of getting the free ticket? 1 The information from the first two throws eliminates outcomes 2, 4 and 6. Conditioned Solution; If you have solved the problem that no two people have the same birthday in an n-people group, this new problem is just a small extension. Assume that you choose to be the n-th person in line. In order for you to get the free ticket, all of the first n -l on outcomes I, 3, and 5, the outcomes that the 3rd throw js worse than the 1st throw are outcomes 1 and 3. So there is 213 probability that the third throw is farther from the center than the first. individuals in line must have different birthdays and your birthday needs to be the same as one of those n -l individuals. This approach surel~ is reasonable. Nevertheless, it is not an efficient approach. WlJen the number o~ darts 1s smalL we can easily enumerate all outcomes. What jf it is a more complex verst on of the original problem: p(n) =p(first n -l people havenosamebirthday) x p(youn among those n -l birthdays) 364 365_ x __ x .._ · (365n +_ 2) XnI _ ;,..___ _ -365"-l ~ason thro_ws n (n ~ 5) darts at a dartboard, aiming for the center. Each subseguent dart 15 J~~9~e_ceo.terJhan e fir·t dart. If ~ason throws the (n+ i) rh pr~b@y that It IS also farther from the CeQ!er-t-hanhisJir:,t? dart~~wn ;~ - -· - - This q~estion is equivalent to a simple question: what is the probability that the {n --- 1)/h throw lS not the hcst among all { 1) hr ? s· fi n + t ows · mce the Ist throw is the best among the trst n throws, essentially 1 ~m saying the event that the (n + l)th throw is the best of all (n +I) throws (lefs call it · -~ - --- · · · - ._ A,,~, ) ts mdependent of the event that the Jst throw is the best ot the first n throws {Let's call 1·t A ) 1 f . . 1 .....:. n act, A,., IS mdependent of the order of the first thr II ows. Are these two events real!, . d d ? .. is not obvious to you that A . . ) tn epen ent · The answer is a resounding yes. It tl . , _, IS Independent of the order of the first n throws. let's look at ll another way· the order of th ti . . · e trst n throws is independent of A . Surely this claim IS consptcuous. l3ut indep, d . . ,, .. , I/( n + I). the probability h en ence ts sym~etnc~ Since the probability of A,/., is . . . t at (n + l)lh throw IS not the best is n l(n + I) _u !·or the o. ngmal versi.Otl th d · · ree arts arc thr · · n chance of being the best thr , A own. mdependentJy, they each have a J. J 1 worse than the first dart Th U\\~ s ong as the thtrd dart is not the best throw, it will be · erc 1orc the answer is 2/3. · It is intuitive to argue that when n is small, increasing n will increase your chance of getting the free ticket since the increase of p (yours among those n -I birlhdays) is more significant than the decrease in p(firsl n -I people have no same birthday). So when n is small, we have P(n) > P(n-1). As n increases, grad ually the negative impact of p (first 17 - 1 people have no some birthday) will catch up and at a certain point we will have P(n+l)< P(n). So we need to find such ann that satisfies P(n)> P(n-1) and P(n) > P(n +I). 365 364 P(n-1)=-x-x···X 365 365 P(n) 365 365 11 I !ere vuu cnn · . agam use syrnmctry argument· . each throw 76 ·- · x~ 365 ~65 365 365 364 365-(n-2) 365-(n-l)x~ P( n + 1) = xx ... x x 36~ 365 365 365 365 ~ Hence, .'~I u movie theater. a whimsical m l t~rst P~rson in line whose b'nhd an~ger announces that she will give a free ticket to the ttckct. You UTI! given the o t a~ ts the same as someone who has aJread) bought a pponurutv to chouse ·. . . . . • any POSitiOn m Ime. Assurmng that ) 00 365-(n-3) n - 2 = 365 x 364 x- .. x 365-(n-2) x~ P(n) > P(n -1 ) => Birthday line 365 P(n) > P(n + l) o 365 365 - (n-2) n - 1 n-2 365 x 365 > 365 n - l 365 - (n - I) n 365 > 365 x 365 :::=> n 2 2 - 3n - 363 < 0 } on= 20 n -n - 365 > 0 You should be the 20th person in line. H. If • · - to get the free ticket. the first (n-1) people in line must not have mt: you are the n-L•l person m 1me. . f h the same binhday and you must have the same bmhday as one 0 t em . 14 . IS equally likely to beth~: best. 77 Probability Theory A Practical Guide To Quantilalive Finance Interviews Dice order Amoeba population We throw 3 dice one by one. What is the probability that we obtain 3 points in stricth· increasing order? 15 • Th~r~ S~Jl~tlion: To have 3 points in strictly increasing order, first all three points must be ?ttlere~t numbers .. Co~ditioned on three different numbers, the probability of strictly mcrcasm~ order ts stmply 1/3! =J /6 (one specific sequence out of all possible permutations). So we have P = P(diffcrcnt numbers in all three throws) x ?(increasing orderl3 different numbers) "'· (lx %xi)x7;=5/54 is a one amo~b~ in a pond ..Aft~very ~inute the am?eba may die. st~y the same, spht mto two or s~o three wtth equal probabilitLAII its offspring, if it has any, wil l behave the same (and independent of other amoebas). What is the probability the amoeba population will die out? Solwion: This is just another standard conditional probability problem once you realize w~ need to derive the probability conditioned on what happens to the amoeba one mmute later. Let P(E) be the probability that the amoeba population will die out and apply the law of total probability conditioned on what happens to the amoeba one minute later: P(E) Monty Hall problem = P(E I F;)P(F;) + P(E I F2)P(F;) + .. · + P(E IF,,)P(F,,) . For the original amoeba, as stated in the question, there are four possible mutually excJusive events each with probability l/4. Let's denote F; as the event the amoeba dies; MDonty Hall problem i~ a probability puzzle based on an old American show Lei's Make a eal. ,The .problem ts· named after the show ' s host. Suppose you're on the show now. . d an tyoure . a car; behind the other two. , y gtven d . the chotce of 3 .doors. B eh'md one door IS goa s. ou on t know ahead of lime what is behind each of the doors. F; as the event that it stays the same; F; as the event that it splits into two; ~ as the event that it splits into three. For event F;, P(£ IF;) = I since no amoeba is left. You pick one of the doors a d . one of the other two d nh a~nounce lt. As soon as you pick the door, Monty opens option to either kee ' oors ~ l ~t le k~ows has a _goat behind l.t. Then he gives you the What is the probab·f·~ oufr o~tgt~al cholc~ or switch to the third door. Should you switch? 1 1 Y 0 wmnmg a car tf you switch? P(E I F;)=P(E) since the state is the same as the beginning. For F1 , there are two amoebas; either behaves the same as the original one. The total amoeba population will die only if both amoebas die out. Since they are independent, the probability that they both wiJJ die out is P(£) 2 • Similarly we have P(FJ =P(E)". Plug in aJI the numbers, SoluJion: If you don't switch wh 1 . of showing vou a goat so ' etbler.~ou Wln _or not is independent of Monty 's action , your pro abthty 0 f · · \vould argue that since there are onJ . wmnmg IS 1/3. What if you switcl~? Many the probability of winning ·s /? B Y~ 0 ~oors left after Monty shows a door w1th goat. 1 1 -· ut IS this argument correct? , It yo.u h.Jok at the problem from a differ . .. . a s~Yttching slrategy. you win the car if ~nt pe~:sp~ctlve, th_e .answer becomes clear. Us~ng whJCh has a probability of ~ (Y , . and only 1f you ongtnally pick a door with a goat. .> ou p1ck a do or wtt· h a goat Montv shows a door WI'th another noat so the 011 . . :::. ' e you swttch t h ' . .• · . . . picked the dnor with the car h' must ave a car behtod tt). If you ongmally S , w IC1\ 1las a probabTty f 1/3 . . h. 0 your probability of winning b , . ,· h' . 11 o , you wtll Jose by sw1tc mg. ) sv.ttc mg ts actually 2/3. 21 ° 2 the equation becomes P(£) = 1/ 4x I+ 1/ 4x P(E) + 1/4 x P(£) + JI 4 x I'(El this equation with the restriction 0 < P( E)< I~ and we will get P( E)= Solve J2-) : : : 0.414 (The other two roots of the equation are I and - fi -1 ). Candies in a jar You are taking out candies one by one from a jar that has 10 red candies, 20 blue candies, and 30 green candies in it. What is the probability that th~re arc at least I16blue candy and l green candy lefi in the jar when you have taken out all the red candies? Solution: At first look, this problem appears to be a combinatorial one. However, a conditional probability approach gives a much more intuitive answt:r. Let T,, 7;. and T.~ Hint: (f there are at least 1 blue candy and 1 green candy left. the last red candy rnusl have been removed befor~ the last blue candy and the last green candy in the sc<Jucnce of 60 candies. What i!> the probability that the blue candy is the last one in the 60-candy sequence? Con<.lilioned on that, what is the probability that the last gre~n candy is the last one in the 30-candy sequence {10 red, 20 green)? What if the green candy is the last one in the 60-cand)' sequence? )' ,, 16 15 Hint· T · · . in a SC. 0 O~larn. 3 ~lniS Ill Strictly incr~in r • • · quen~..~. stnclly mcreasing order is one ~~~er, th~ 3 P<>1ms must be dif'ft.!rent. For 3 diO"'erent po~ntS posstble pennulations. 0 78 79 I Probabil ity Theory J be the number that the last ed bl · hav - t I I bl - -- ..!_;__, ~:..an _s:_een candtes are taken out respective!)'. To . , e a deast ue candy and I green candy left when all the red candies- are taken out v. c nee to have T < T. and T T I , r h r < !! n other words, we want to derire P(T < T. 11 T < T ) The . ' ~ ' .. x · re are two mutually exclus1ve events that satisfy T, < r, and T, < T~: : ~ < 7" < T. and T < T < r. J 0 ~ ' K II ' <T, n T, < T,) = P(T, < T,. < T,) + P(T < T < T.) ~ r !! h T, < 1;, < 7',. means that the last cand · :. f(T, are c · Y IS green ( T~ = 60 ). Smce each of the 60 candies . II · J'k A Practical Guide To Quantilat ive Finance ln!erviews d qua Y ' c1Y to be the las1 cand d 30 Y an among them 30 are green ones, we hare P(l~. - 60) = - . Conditioned on r - 60 60 ;: - ' we need P(T, < T,, I Tn = 60). Among the 30 red and blue candies each cand i . becomes the first one to toss an H. ln that case, A has ( l- P(A 1H)) probability of winning. So P(AIH)=l l 2x0+11 2(1- P(A[H))~P(AIH)= l l3 Combining all the available information, we have P(A) = l /2x l/ 3 +I /2(1- P(A)) ~ P(A) = 4 / 9. Sanity check: we can see that P(A) <I /2, which is reasonable since A cannot win in his first toss, yet B has I /4 probability to win in her first toss. ., • y s again equally likely to be the last candy and there are 20 blue candies, so P(T < r. 1T = 60) _ 20 30 20 ' " ~ - 30 and P(T, < T, < T) =- x Sjmilarl\' f/ 60 30 we have P(T, < r~ < 1,.) = 20 x 30 . 60 40' ° , , He nc~. 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 Coin toss game . d h . , an 8 'alternattvely toss a fa. . e com, then A, then B ) Th Jr COin (A tosses the coin first then B tosses h d fl0 ll . . . . e sequence f h d . , ~a . owed by a tail (Hr subs uence 0 ea s aod tatls is recorded. If there is a tall wms. What is the probability~· A ): the game ends and the person who tosses the at wms the garne') l7 SoJwion: Let P( ·I) b 1 · p 8 , c t h.~ probability that A ,· . . ( ) ::. I - P( A). L~t' s condition P(A) , Wtns, then the probability that B wins IS (n~ds) und 112 probabi litY~~( .... on A s"[II~ toss, which has J/2 probability of H J> tails). Two players A 1 ( A)= 112P(A I H)+ 112P(A IT} If -A' s firsr to ;,. T lh 0 · · ...... en o · HT ~ubsrqucn . ') ess~!lt!1!J.!.Y becomes th fi , . . , c~.: ·' owe have P(A 1T) _ -~~~s (An HIS required Jor the It·· 1' ~ - P(B) =1- P( A) / s first toss en l . · · of gcltin, T . t s tn If. lct >s further cond't' g . m that cuse A loses. For the 1~~on on B'_s. first toss. B has l/2 probability __ - probabthty that B gets H. B essentiall}' ~~ · s- ,, lrnt:-:-------condition on th~ I - resu t of A's fin;ttoss and use S)• m 80 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 13 !L 2 P = pPa) + qP => P~ ~~ - P = 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 ~ : 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 <m inducuon 3 ' ~ = I/ ? and p . e thrrd throw has l/2 b .. = - prob·abT ·1 tty 1.! =112. 1 (n+l)-1 probability: . gtven P,.l) =- --- -- P,••,~, that Pn.k '\1 k = 1 = -n -l ' Vk = I' ?- ,· · · ' n- I, we need to prove 1, 2, · · ·, n. To show it, simpl y apply the law of total n =P( miss I(n,k)) P,,,k + P( score I(n,k -1) )P,)-t +- ~t~l k~l n~l ~ + = 1 The equation is also appl icable to the P,...• and P, ....n' although in these cases k- = 0 n Basketball scores · step: For the , case when pro abrhty of scorino. So we ha,e 11 = 4, let's apply the °law of total ~ flint : At!aiu don I patr~m b ~. ·, . 01 et the number 100 . > mcrcasJng n; and rov scares you. Start with . P e the pauem usinu ·ndu t' smallest n, solve the problem · trv 10 tmda o 1 c ton. · · J and (1- ~ = 0, respectively. So we have P,,, = n ~ , '<1 k = 1, 2, .. ·, n - I and '<1 n ~ 2. 1 Hence, ~oo.so =I 199. Cars on road the probability of observing at least one car on a highway during any 20-minute time tnterval is 6091625, then what is the probability of observing at least one car during any !f 5-minute time interval? Assume that the QrQ.bability of seeing a car a~~.Y._moment _i~ uniform (constant) for the entire 20 minutes. - Solution: We can break down the 20-minute interval into a sequence of 4 nonoverlapping 5-minute intervals. Because of constant default probability (of observing a car). the probability of observing a car in any 5-minute interval is constant Let's denote the probability to be p, then the probability that in any 5-minutc interval we do not observe a car is 1- p . 84 85 Probability Theory A Practical Guide To Quantitative Finance Interviews The probability that we do not observe any car in all four of such independent 5-minute 4 intervals is (1- p) = I- 609 / 625 = 16/625, which gives p = 315. 4.4 Discrete and Continuous Distributions In this section, we review a variety of distribution functjons for random variables that are widely used in quantitative modeli ng. Although it may not be necessary to memorize t~e _pro~erties of t?esc distr.i ~utions, havi ng an intuitjve understanding of the dt~tn~utJOns ~nd havmg the ab!ltty to quickly derive important properties are valuable sktlls tn practice. As usual, let's begin wi th the theories: Common function of random variables Ta~le 4. I summarizes how the basic properties of discrete and continuous random vana bles are defined <)r calculated. These are the basics you shou ld commit 1o memory. Random variable (.A) CUJnulative distri bution function/cdf Probability tuass function /pmf Probability j_ensity function /pdf Expected value/ E[Xl Continuous19 Discrete F(a) ~ P{X <a} pmf: p(x) = P{X -- Expected value of g(X)/ E[g(X)] ~ Standard deviation of XI .\'lei( X) Table 4 .1 Ba · SIC = x} I xp(x) I: g(x)p(x) f. f (x)dx ~ Name Probability mass function (pmf) Uniform P(x) = Binomial P(x) = x p (l- p) · , P(x)= Geometric P(x) - clx ! Negative Binomial P(x)= g(x)f(x)dx - 2 Jvar(X ) properties of discrete and continuous random variables b+a -- (b - a+ l)J - I 12 (n) ' np np(l - p) ,_, e- )J (A.tY x! X= ' r- 1 p (l-p 2 x = 0, 1,- · ·,n 0, },.. · (x-1) , )'-' - 20 • x= r ,r+ l, ... ._ At - -- - A.J_.) - ] 1- p p IT r p r(l - p) - / _j - Continuous random variables · 1d f the commonly encountered continuous distributions. Tabl e 4.3 me u es some o . . · ., . 1 Uniform distribution describes a random variable unifonnly dtstnbutc~ ove~ th~ m~cTV~ . ·1 theorem normal distribution/Gaussian dtstnbutton IS [a, bl . Because of t11e centra I I1011 • · . . . d th 1s c · · 'b · E ponential dtstnbutJOn mn e by far the most popular contmuous d1stn utJOn. ~ - . . .. f ·r . h . constant arrival rate A. Gamma dJstnbutJon With . I . an:lVa time 0 an event 1 II . as~ . . 1)1 of the amount of time one parameters (a, ;. ) often arises, m practice, as the d~s~ ul. 0 ~ d • has to wait until a total of n events occur. Beta dtstnbuttOns are used to mo e1 events r Table 4.2 includes some of th . random variable reprcst:nts the most Widely-used discrete distributions. Discrete unifonn values in the set J Cl • e occurrence of a va lue between number a and h when all l · a+ 1 .. · b} have 1 I r~prt!scnts the nu be f · ' equa probability. Binomial random variabc m r o successes in a se . J. "7"--- -- - - - quence of n experiments wh<:n each trta 15 II) P{.Y var(X) Table 4 .2 Probability mass function, expected value and variance of d1screte random variables r: SIP E[X] J , x =a,a+ l,···,b b-a +l = (1- p)-"-1 p , x = 1,2, .. . pdf: f(x) = - F(x) £[X]/] E[X ; ]- (E [ X]) For continuous random variables P(X • - x) =O, Vx e (- -::.o~ 7JL Poisson d [. xf(x)dx pi_x po E[(X F(a)::: Discrete random variables 86 the time since the fast event. Geometric random variable represents the trial number (n) toget the fi~t success when each trial is independently a success with probability p. Negative Binomial random variable represents the trial number to get to the r-th success when each trial is independently a success with probability p. -- ~-Pi:t)>O Variance of XI vur(X) independently a success with probability p. ~qisson random vari~ble repres~ts the. n_~mber of e~ents. oc~~rl~& in a fix~d period of time with the expec~~~ . numb~~ o~ occurrences l..t when events occur with a lnown average ra1e .t and arc mde_P.enden~ of s \'}= fl{ .X < x} · n "~ · define the parameter (expected value) since it is ·· Here we use the product of arrival rate ). and ~m1e I to the definition used in many Poisson process stud1es. 87 Probability Theory A Practical Guide To Quantitative Finance Interviews that me constrained w1th.in . the shape parameters a and p. . . a defined .mterval. B~a d.Justing it can model different shapes of probability density functions. 21 Name L' niform i Probability density function (pd.f) I -' h E[X] a-5x $ b -e Exponential ). - .lr . .,_(! ' &a ~ 2a1 • x e (-oo,oo) x?!O A.Y(AX )a-1 f(a) Beta b+a 2 (b- a) 2 : fJ (r l/ 2 I / ,.(' X ?! 0. f(a) = r I 12 - ( .t-p)= I Normul .J.e var(X) I (I Gamma 60 55 ., J I I 5: ... e·Y ya-1 f(a + fi) u-1 (1- )P-I X X , 0< X< J f(a)f(P) alA. a/ 2 a 5 X 55 60 Figure 4.4 Distributions of Banker A•s and Banker B's arrival times ap ~ a+jJ 0 2 (a+P+l)(a+P)j Table 4.3 Pro b ab11 y ens1 ·ty funct·1on, expected value and var·f ance of continuous random variables .l.t d Meeting probability Two bankers each arrive at the station at some random time between 5:00am ••;d ~~ am (arrival time for either banker is uniformly distributed). They stay exact Y 1 minutes and then leave. What is the probability they will meet on a given day? ·~ Probability of triangle distribution on the stick), . l (each cut point follows a ~m o~2 A stick is cut tWJce random Y ts can forrn a mangle? what is the probability that the 3 segmen •th of the stick is I. Let's r , let's assume that the !eng Solution: Without Joss of genera Jt) 'x and the second cut as .Y • · also label the point of the first cut as _ _ _ ----::7"r-----~l 1 If x < y then the three segments are x, y-x and 1-y. Th~ conditions to fonn a triangle are .'io/111irm: Assume banker A arrives X minutes after 5:00 am and B arrives Y minutes ~~ 5:00 am. X and Yare independent unifonn distribution between 0 and 60. Stnce , if onl~ I X - sta) l" lc;; 5.exactly five minutes, as shown in Figure 4.4, A and B meet tf and on)1 ~...,. x A , y 37' y-x / / 1/2; '· So the probability that A and B will meet is simply the area or the shadowed reg:"t: di\'idc<.l by the area of the square {the rest of the region can be combined to a square " 1 SiLc lcngOl 55): 60x60- 2 x (l / 2x 55 x 55)= (60 + 55)x (60- 55) = 23 . 60x60 .' :~"'P '· """ "'~'" 144 60 x60 I ... _ ·1• ·b · · uuon "widely Used ;n modet;ng loss g;ven default ;, "" lam' h:v Wllh Bay""" '"";stks, you wHt a!SQ «<ogn; 70 ;, as a popu tac !I Fo ex ,;.k managem~n · co~jugate prior funcll 1 011 · lfyou - n Jl;nt let the fi<SI CUI point be X, the second one bey, use the figure to show th~ distribution of x andy. 89 Probability Theory A Practical Guide To Quantit.ative Finance Interviews The total shadowed area represents the region where 3 segments can form a triangle, which is 1/4 of the square. So the probability is 1/4. Property of Poisson process Yo_u are waiting f~r a bus at a bus station. The buses arrive at the station according to a P01sson process. With an average arrival time of I 0 minutes (A == 0. t1 min). If the buses ~ave ?een runnmg for a.lqngji_n)~ and you arrive at the bus station at a random time, what IS your expected waiting time? On average, how many minutes ago did the last bus leave? Solulion: Consider~ng the importance of jump-diffusion processes in derivative pricing and the r~le of Potsson. processes in studying jump processes, let's elaborate more on This is another example that your intuition may misguide you. You may be wondering that if the last bus on average arrived lO minutes ago and the next bus on average will arrive 10 minutes later, shouldn't the average arrival time be 20 minutes instead of 10? The explanation to the apparent discrepancy is that when you arrive at a random time, you are more likely to arrive in a long time interval between two bus arrivals than in a short one. For example, if one interval between two bus arrivals is 30 minutes and another is 5 minutes, you are more likely to arrive at a time during that 30-minute interval rather than 5-minute interval. In fact, if you arrive at a random time, the E[X 2 ] expected residual life (the time for the next bus to arrive) is for a general 2E[X] distribution. 25 ~~~onentlal random .van~bles and the Poison process. Exponential distributjon is wide!~ sed to model the hme mterval between independent events that happen at a constant average rate (arrival rate) )·.. f(t)-- {le-J.t (I~ 0) · 0 (t < 0) · · J/ j The expected arnva · 1 ttme 1s ,, and the variance js 11A! u · · · . . . . · smg mtegrahon, we can calculate the cdf of an exponenhal dtstnbutton to be F(l) == P( r <f)= 1- e_, . and P( r > 1) == e - rt , where r .ts the random vunable for arrival time 0 · . . . . . memorylcssncss· P{ . · 1 n~ umque property of exponentLal dtstnbutton IS · t' .. r>_.~.+l i r>s}=P(r>t}. 23 That means if we have waited for s tme umts. I 1le extra wanmg time has th! d' . . e same IStnbuttOn as the waiting time when we start at time 0. When the arrivals of a series of ' . . distribution with arrival rate ). h e\ents each m?ependently follow an exponenual '• 1 e number of arnvals between time 0 and t can lx modeled as a Poisson process P(N(t)- ) - e_;., J..lx 24 ·d -x - - - . x = O, I ... The expect~: number of arrivals is itt and the varia11 . , . x! ' of exponential distribution th be ce 15 ~lso J..t. Because of the memory less n~ture • e num r of arnvals between time s and 1 is also a P01SS0° proCI!SS P(l\'(t- .\') =x) = e--<tt-f) (A(/ - s ) r Moments of normal distribution If X follows standa~d nor'!la.~ distribution (X- N(O, I) f) wh.at. i.s E[X"] for n = I. 2. 3 and 4? 1 •. : r - ' _. I I l /v\ . ... ~ .= ) tr / _ \ i\ - · 1 Solution: The first to fourth moments of the standard normal distribution are essentially the mean, the variance, the skewness and the kurtosis. So you probably have remembered that the answers are 0, 1, 0 (no skewness), and 3, respectively. Standard normal distribution has pdf f(x) = --i=e ·. 2 . Using simple symmetry we ...J2ff 1-e-r ndx = 0 when n is odd. For n = 2, integration by parts are have £[x"J =[ x"1 ..& often used. 'fo solve £[X") for any integer n, an approach using moment generating functions may be a better choice. Moment generating functions are defined as _L e'x p(x), M(t) = E[e'x] = if x is discrete r { ( e'xf(x)dx, if xis continuous x! laking advantage ot the memo ·I the expected waiting time · 7J.. ess pro~rty of exponential distribution we know that 1 property stills applies s IS .. == IOmm l!_~u look back in time. the memooje.SS . o on average the Ia t b - . . · s us arnved 10 minutes ago as well. Sequentially taking derivative of M(f), we get one frequently-used property of M(l): M '(t) = !!_ £[e''' ]= £[ Xe'x] => lvf '(0) = E[ X], dl 2 M "(I)=.!!_ E[Xe'x 1=E[X 2e'·\ ]=> M "(0) == E[X l. P{r>s+t lr>s} = e-~' ·•o;e-;.., ;: Morl! rig11rously /\'(I). d fi · 1s e 10ed as ~0 dt :=ce-"'-· - P(x > 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) = f. J ' L• ""' ab C (X L..... ' . I ov 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<traance: . I .. have 4 ends ( 2 x 2) and you can connect any two of them. 1here arc 2 / - - 2 So the expected .number of circles is Cov(X.Y) I f .rand y an: independent. Cov( X . Y) == 0 and I Solution: Again do not be frightened by the large number 100. If you have no clue how to start, let's begin with the simplest case where n = l . Surely you have only one choice (to connect both ends of the noodle), so £[/(1)] =1. How about 2 noodles? Now you • ~Var(X) Var(Y) Cm·( f. La,.\',. L b ) ~ ) := You have 100 nood les in your soup bowl. Being blindfolded, you are told to take two ends of some noodles (each end on any noodle has the same probability of being chosen) in your bowl and connect tbem. You continue until there arc no free ends. The number of loops formed by the noodles this way js stochastk Calculate the expected number of circles. math induction / Recursive 1 (' See the pattern? For any n noodles, we will have l:.lf(n)] == 1 +I 13 + 1 5 + · · · + l /(2n - l). \Vhich can be easily proved by inductiC?n. Plug 100 in, we will have the answer. X ) I • · p( ,\ · Y) = 0 onlv means ,,\' and y ar J e uncorrelated: -~' they rnay well be depend~:~~ 93 Prob<tbility Theory A Practical Guide To Quantitarive Finance Interviews Actually after the 2-noodle case, you probably have found the key to this question. If 2 you start with n noodles, among ( n ) = n ( 2 n - I ) possible com bi nations. we halt 2 n n(2n- I) =-2n-l . d . ? n- 2 probab'l' 1 tty to ytel I Circle and n -1 noodles and probability 2n -I . 1 112 chance to get Y e {4, 5, 6}, in which case you get expected face value 5 and extra throw(s). The extra throw(s) essentially means you start the game again and have un extra expected value E[X]. So we have E[X I Y e (4,5,6)] = 5 + E(X]. Apply the law of 27 total expectation, we have E[X] = E[E[X I Y]] =tx2+tx(5+ E(X]) ~ E[X]= 7 . 1 yield n -I noodles only, so E[f(n)J = E[f(n -I)] + - -. Working backward, you 2n-l can get the final solution as well. to Card game What is the expected number of cards that need to be turned over in a regular 52-card deck in order to see the first ace? Optimal hedge ratio Solution: There are 4 aces aod 48 other cards. Let's label them as card 1, 2, .. ·, 4a. Let You just bought one share of stock A and want to hedge it by shorting stock B. How m~~Y shares of B sl~ould you short to minimize the variance of the hedged position? As~umc that the vanance of stock A' s retum is a~; the variance of B's return is th~tr ~orrdation coctlicient is p. X == { 1, if card i is turned over before 4 aces ' 0, otherwise a;: The total number of cards that need to be turned over in order to see the first ace is 4R X =1+LX,, so we have E[XJ = I+ 48 L E[ X,]. As shown in the followinB sequence, Solution: Suppose that we short ,L shares of B, the vanance · • • of the portfolio return ·ts 2 1 var(J I -/uH) = a I - 2pha.~ a H + h- a2II each card i is equally likely to be in one of the five regions separated by 4 aces: Th~ best hedge mtio sho ld IA2A3A4A5 u · · · var(rA-hrJj). Take the first order partial mtntmtze I~ I~ dcri,·ati,·c with respect to hand set it to ze . Dvar - 2 2 a 4 ro. - - pa a + 2ho = 0 .::::::. h -:: p- · 8h tl H Jj (J/1 So the probability that card i appears before all 4 aces is 1/5, and we have £[X,] = 115 · confirm it's the minimum w-. · ~can a 1so check the second-order partial derivative: c - var _ _ ,,....., > 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~_, B 0 'I'. to obtain the i-th type after (i -1) distinct types have been collected. So the total number I I x,, i =1, 2, ... , N, be the number of additional coupons needed • '• 0 I ' I N of coupons needed is X =X,+ X 2 +··· +XN =LX, '... -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 X )? What are e cum . X v · ... X)'' (X X expected value of Z, =ma-x " 21 .... , • . 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.v<x) and f x (x) to P( Y,, ~ x) =(P(X ~ x))" ~ F;~ (x) = 1- (1- Fx (x)t =1- (1- xY' ~ fr. (x) = nfx (x)(l - F.r (x))"- = n(l- x)"1 ------·---------- y 1 1 1 and EfY,,l = r nx(l - xY'- 1dx= r n(l-y)yn-1dt=[y"] -__!!__[y',... 1 ] =-- . 0 1 1 o n+l n+l (z,z) (y,z) z 1 (y.y) (z,y) '' '' Correlation of max and min Let X 1 and X 2 be llD random variables with unifonn djstribution between 0 and I, Y=min(X.. X 2 ) and Z=max(X~:X1 ). What is the probability of Y~y given that Z ~ z for any y, z e [0. l]? What is the correlation of Y and Z? ,\'olwion: This problem is another demonstration that a figure is worth a thousand words. /\s shown in Figure 4. 7, the probability that z ~ z is simply the square with side length z. So P(Z~z) =/. Since Z=max(X.,X~) and Y=min(X.,X~ ), we must have Y~Z for any pair of X1 and X 1 . So if y>z, P(Y~y jZ$;z)=O. For y~z, that X, <llld xl satisfies r ~ )' and l ~ z is the square with vertices (y, y),(z,y), (z, z). and (y. z), which has an mea (z- Yi. So P(Y ~ y P( y ~ y 1 z ~ z ) _ { ' ( =- J') 1 2 Iz 0, • n z ~ z) = (z - y) 2 . Hence if 0 5 z ~ 1 and 0 ~ y ~ z mherwise Now let's move on to calculate the correlation of y and Z corrt}', 7.):::: cov( }'.ll_ == std( }') xstd(Z) E[tZ] - E[Y]EtZl JE[Y1]- E[Y f x ~ E[Z21 - £[2]2 ' 0 Figure 4.7 Distribution of X, , X 2 , their maximum and minimum. J I 2 _2 Using previous problem's conclusions, we have E[YJ= + =3, E[Z]=2+i-3. 2 1 11-1 (l ) and r (7) = nzn- l =2z, we can From the pdfs of Y and Z, fr. (x) == n(l-x ) =2 -x 17. w 3 dz=~ whichgiveusthe ~ 2 2 1 E[Z2]alsoget E[I;,L]= .h2(!-y)idy=3- 4=6 and '-~~ -1 z 4' ' r variances: var(Y) = E[Y r2 2 ]- l E[Y] = 62 ,ro calculate £(Y2L ( 1' 2 1 2 ( 2 ) .. _ _1 J =Is and var( Z) =4- ·3 - 18 3 33 r r- -.1'1 I -)dvdz To solve this equation, we we can use £[YZ] = 11 Y.t.; d ,.t. - · . 4 7 F 1 the figure we can see that when need /(y, z). Let's again go back to Ftgure · · ron .. · b babthtv Osz~1andO~ y~z, F(y,z) istheshadowedareawtt pro ' 2 22 F(y,z) == P(Y ~ y"' Z 5. z) = P(Z :f z)- P(Y ~ ynZ ~ z) =z- -(z- y) = q- y :.f(y,z) = ,:Oz F(y,z) = 2 and E[Yl) = 1[2yzdydz =.(' z[y'J;dz =£z'dz = ~. • , wonder whether it is a coincidence for n =2.' h is You may have no11ced that var(Y) var(Z) and • ·h that is tru~ wi1hout rc~ortmg to . about " Y 10 thmk actually tru~ for all .mteger n. You may v.ant . _ ~ ) calculation. Hint: var(.t' = var(l x) for nny random vanable .\ ( , 1 \1 ) \ ~ I •l 1- '/ ' I f\2 { JJ 100 z y = 'rvv 1-. ~ 1 ,.:. = - · 101 - Probability Theory A Practical Guide To Quantitative Finance Interviews An allernative and simpler approach to calculate E[Yl] is again to take advantage of sym metry. Notice that no matter x, s x2 or 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 < 05 0.25 0.4 0.4 > 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 . <~nly Jl state .i is accessible f Y . . " - J o = 1), then P(~ < oo) > 0 ) if and 1 Irom j . and .J· is acccssrble . ron1 state . from In f' · States i and J· commumcate if i is accessible 1 a~.:ccsstble form state I. but they tlgurc 5. 1·. state 3 and I communicate. State 4 is state 4 · no communrcate Since · . not accessible from state I JS do w~ sav: that sate t r..rs recurrent . f f, acccsstble fromj ( Vj, P(T, < 'l.>) ~ ; ;~;ry stat~j that is ac~essible from i, i is also 0 00 not rccurn.·nt ( ] j P( . 1 ) " < ) - 1). A state IS called transient if it is ' 1" < 00 > 0 and P(T1 r~~urrr.:nt. Statl!s I "> ··rld " ' < o:>) < 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 . <It ov ~ham 1s• an a ·bSorbtng state ,. u . P solutiOJ;s :thdttv: tfhe pr0 b• a bT 1 · · ~· ._,,,,_ are unique tty to reach a speci fic absorbing 0 equation s a - 1 , . state(s) 1 ~ .... und u -,f. a · • - · a, =0 for all absorbtng L..I ' P.J for all transient s·tate~. t. -fhe"e . · " equatwns can be eas1'I ~ Player M has $1 and player N has $2. Each game gives the wi.nner $1 from the other. As ~better player, M wins 2/3 of the games. They play until one of them is bankrupt. What IS the probability that M wins? Solution: The most difficult part of Markov chain problems often lies in bow to choose the right state space and define the transition probabilities P,1 's, Vi, j. This problem has fairly straightforward states. You can define the state space as the combination of the money that player M has ($m) and the money that player N bas ($n): {(m,n) }={(3,0),(2,1),(1, 2),(0, 3)}. (Neither m nor n can be negative since the whole game stops when one of them goes bankrupt.) Since the sum of the dollars of both players is always $3, we can actually simpl ify the state space using only m: {m} == {0, 1, 2,3}. The transition graph and the corresponding transition matrix are shown in figure 5.2. I rG;I /3 C@2 /3 &J l l 2 3 1/3 213 ~ ~ Pon P~ ' Po 2 Po. p 1, p11 P = {P }= IJ P~.l) p~ , . P~•J Po.• p,~ Pu P~'! P:• P:.: fl 2..• 0 01 Yc 0 ~ ~J Figure 5.2 Transition matrix and transition graph for Gambler's ruin problem The initial state is X = 1 (M has $1 at the beginning). At state 1, the next state is 0 (M 0 loses a game) with probability 1/ 3 and 2 (M wins a game) with probability 2/'J. So 1\0 =I I 3 and Pl ,2 = 213. Similarly we can get Pz.l == 113 and Pv =2 / 3. Both state 3 (M wins the whole game) and state 0 (M loses the whole game) arc absorbing states. To calculate the probability that M reaches absorbing state 3, we can apply absorption Probability equations: 107 Stocha~til: aJ Proccs-; and Studmstil: Calculus =l, u\. - 0 , and A Practical Guide To Quantitative Finance Interviews 3 3 ' p, a , al ="" p a a, = ~ .) ~ I J~O 1 ,1 E~ {7.l 2}, the game essentially starts over again. Now we have all the neccssari ly 1 J=O information for P(A). Plugging it into the original equation, we have Plugging in the transition probabilities using either the transition graph or transition matrix. wehnve a, = 1!3x0+2 / 3xa2} => { 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<ur C\)in until eitht:r HHf! I:) lt: probability that you uct an IIHI/ . b. or THH occurs in the sequence. What 0 ~:-~......__---._ __ __ _ su St:quencc before THH?~ : Hint: Thi~ nrnbl . 1f ;, :· ~:m w..:~ n111 require til d · bCI\Wettnn· 1/H/f . l' rawml! of a Marko ~h · · P•11h:m and a T! Ill pattem 1-1 . ~. . • v c arn. Just think about the relationship . 0\\ Ccln we get 'in HliH ' sequence before a THH sequence? f lO p . d of tixed triplets for the ·h . a an C. (Ditlicult) Let's add more fun to the tnplet game. 1nste~ two 1 . th · 0 wn tnplets. Player 1 c oases . P ayers, the new game allows both to choose ei~ . t The players again 1 nplet first and aMounccs it· then player 2 chooses a different tnp1e l. ·h chos ·~n tos3 th . • ~ s The p ayer w ose c . e coms until one of the two triplet sequences appear · tnplet appears first wins the game. 111 Stochastic Process an<.l Stochastic Calculus A Practical Guide To Quantitative Finance Interviews If both. ~layer I and player 2 are perfec I probnbtltty of winning, would you go fi t y rational and both want to maximize their probability of winning'fl trst (as player 1)? If you go second, what is yow common misconception is th '.llhcr sequences. !'his misconception is oftat there is always a best sequence that beats Sl'qucnces arc transitive: if sequence A en founded on a wrong assumption that these s~qucnce Band sequence 8 has a hi I has ~.higher probability occurring before ;l·qu~~t:~ "' has a higher probabili~ le~/rob.ablltty occurring before sequence C. then rans.tttvtty does not exist for this game. c~rnng before sequence C. In reality. such ?.JuyLT 2 ~:an always ~.:boose another sequ o ~atter what sequence player 1 ch.ooses, l~e key, as v.·c have indiCitkc.i in Part Bc~ce wtth more than 1/2 probability ofwinning. a. c; lh..:~fi~l · coms • of - -laverj~ ' _ Js 'to choose · o·r the s~encc ~·~ t'-"O - the -·.. Iast t wo coms t.:uch pair of st.:yUcnces: • que.A!.~e. We can compjje the following table for ,\'olulioll.· A 2's winning --HHH ProbabiJit) J'HH HTH N ,.. I,. ~ HHT I-- [IH .! - Plaver 1 1t8) II ·-.....:.: "' 112 ;>"'"' 7/10 E[N,] = E[Nn IF; ]P[F;] + E[N" I F1 ]P[F2 ) + ·· · + E[ Nn I F,)P[ F,,]. Since all the colors are symmetric (i.e., they should have equivalent properties), we have P[~] = P[F;] =.. . = P[F,,] =1I n and E[Nn] =E[Nn IF;]== E[ N, I F;]= E[N,. j/·;,J. That 5/12 2/5 L/2 So how do we calculate E[N" 1 F;) ? Not surprisingly, use a Markov chain. Since we 1/2 1314 1/3 t/2 l/2 315 113 3/8 1/2 112 7/l2 1/2 5/8 only consider event F; , color 1 is different from other colors and colors 2. · · · • n become equivalent. In other words, any pairs of balls that have no color I ball in~olved ~re equivalent and any pairs with 8 color 1 ball and a ball of another color are eqUivalent rf the order is the same as well. So we only need to use the number of balls that have color I as the states. Figure 5.5 shows the transition graph. ~ -~ It 1_.., l/2 7/ 12 112 1/2 HTT 3/8 F 315 1/2 1/2 rlT 1/3 1/2 Ius 5/ 12 3/W o\ total expectation, we have represent E[N,.]. ( 2~ , 7110 !213) ./ 1/4 1/2 1/3 I 315 l/4 1/2 112 ,, 718 It I W .. v ile. ntcre!>tCd rer.d llltln.l( rinl~-P d .· . a er may find lh f II . , . . . • n. - (Ma~. Jl)•J7). fl ~~ ..ara ox1~al Situations'' b , V C e 0 owmg paper hetptul: "Waitmg Tunc 1 1 p. .>3. In lhts section. we wi~l · . ·d~ombas. The Americ:an Suui.flidan. Vol. 5 I. 0 1 112 n Y IScttss the intuition. , F;, i =1, 2, .. ·, n, be the event that all balls have color i in the end. Applying the law of HIT TTT 1/2 ~15 1/8 Table 5.1 Player 2's winnin ' . .., . g Probab,hty Wtth drffi . As sho,,·n rn Table ). I ( erent corn sequence pairs · · you can , t~ c hOtces 3r~ 111av , ? ' con lrln the result bt:SI s, · • \:r- can always choos, a · s yourself), no matter what player l's · \:ljll~nces ·" ·sequence t0 1 bold .lave better odds of winning. The . • th·.t t P1nyer 2 can choo<-" 1 · n Oil1<.:r to m· .· · "" 10 •esponse t 0 1, . · JriT Till . , <~XIIllll.c his odds of \\'i . s cho1ces are highlighted m 1 · .md 1 HT. Ev~n in these cases nl·rung. player l should choose among HTH. . P ayer -? has 2/3 pro ba b'llity . of winning. N 11 l1/JO f 2~ ·- 5/8 l'hls problem ... " 'a u.•.l ,.fitcul! .I - Solution: Let N be the number of steps needed to make all balls the same color, and let 112 ~ ·Ulu ~'\-pi:1.·t~J balls, repaint the first to match the seco nd, and put the pair back into the box. What is the expected number of steps Wltil all balls in the box are of the same color? (Very difficult) 2/5 l/2 1/4 A box contains n balls of n different colors. Each time, you randomly select a pair of means we can assume that all the balls have color 1 in the end and use E[N" I F;J to HHH h"'HH HTH IHHT rrTH tfHT . 1/8 Color balls Figure 5.5 Transition graph for all n balls to become color 1 Staten is the only absorbing state. Not.!_ce that then~ is.;!.~state 0_. otherwise it ~ill n~v~~ reach F, · In fact, all the tra.rv•ition probability is com.litJOJlCd on Ft_Es well, whtch mnk\;s the tr~~itton probability p I F.I higher than the unconditional probability P,... l and . • j F.-0 and p = l i n. (Wtthout P• 1-1 IF1 Iower than P,., . I·or cxamp1e. P1.o 1 1.0 .. 1 conditioning each ball is lt'kcl)' to be the second ball, so color I has ll n probabtllty of be. ' · ·· bbT · 1h· roblcm ~ng , t~e second ball.) Using the conditional transJtton pro .a 1 .'t}. c P essenttally becomes expected time to absorption with system equattons. ' 1.1 •1 E{N, i F;]= l+ E[N,_,I f;]xP,.,_1 1r;+ E!N, I r ;Jx P..• IF;+ ElN,~~I r;J xP...•I I ~ · 113 Stochastic Proccs~ and Stol:hastic Calculus A Practical Guide To Quantitative finance Interviews To calculate p'·'-' 1 F." 1et , s rewnte . the probability 't/k =0, I, ... , to make the derivati on step clearer: as P(x.. , - ~i- l l x~ =i. l ·; )= P(x, P(x~< +t =; - 11xk == i. F;), Using these recursive system equations and the boundary condition 7.1 =(n -1)2 • 4 =i, x"~ ' =i-l, F;) =i, F;) P(x~ ::: P( F; l x~ +l =i - l, xk =i)xP(x.~-~, i-11 x* P(F; I x* - i) x P(x :: P(f,' !x,""1 =1' -J)x P(xk~ l P(F; I x~< - . I II X11 ~< i) x P(x* ,·) =i ) i) =i) ~~ !x j(l~ i)_ = n n(n -1) - ( n - i) x (i -I) . ~ . iI n . - n( n - I) .r hl: fir~t \.'quatlon is simply the d fi . . 1s the I' · e Jmlton of condit'1 . app IC<Hion of Bayes' theorem· th th' d ~na1probability; the second equation denve P( F• •x~ =I') =I.I ,~, we again •need e to lr uequation a pp rJes the Marko v property. JQ_ -.... ' th~.· balls ha\'l! different colo -t -·· Se_$.)mmetry. We have shown that if all rs, t len we b·tve P[ F] ' - - ' =P[0L= · .. =P[F1= l l n. What is ~ ~ prohabilityofendingina giv~n 1s. •simpl Y ·; • .o sc~ that ,.,..e l: cob1or. 1abeled as c' ·r -1 1· 0 f h t e balls are of color c? Jt 1 11 1 1 c i- I . . can a el the color 0 f h , . • - • · • • • 1 (even thoul!h they are · r: eac of the i balls of color c as baIIs wJII . end v. ith col -. . . tn .act the same co Ior) · N ow .rCs obvious that all 0 1 cJ wuh probabilit ' 11 probabilities of c 's wJ · h . ) n. The probability for c is the sum of ' , . lrc gt\'es the result I·; 11. h Similarly we have P(F. I . 1 hasiccount' x." ~ l ·-) ) = (i -1)/ n. For P( · rng method. There arc n(n -l) . xk ., ='-I I x" = i), we usc a 11 halls In ord poss1ble pe·rmL1t at'IOns to choose 2 balls out of . . ·· er ~~or one color 1 b· II \\ h1ch has· i chotces; · to change the first ball dneeds b. c0 1or, t he second ball must be color 1, 1 0 ' e another col h' Su /'(x ":: . i . 11 . .) i(n - i) or, w tch has (n- i) choices. . .\, _, =--. •• pnn~oap 1L'S. we cnn get Pt t:. 1 =i l x -:: i /•' ) _ ~n - i) x 2i ' . I - n(n-1 ) • f' (.th, = i + l p·t = i.F; )= (n - i ) >< (i+l ) Plugging int(l /!l .\ I F.J , d . .. n(n - 1) ' ' an srmplt tying E[A I F. ~ . , (II - i) ·... ]. )( / _ ' , j as £,, we have 1 • II( 11 - I ) + ( n ~ i)(i + I . }L,.., + (n- i)(i - I)Zt-1 . I 14 5.2 Martingale and Random walk Random walk: The process {S, ; n ~ l} is called a random walk if {X,;i ~I} are liD {identical and independently di stributed) random variables and S, =X, + ··· X,, where The term comes from the fact that we can think of S as the position at time " n for a walker who makes successive random steps XP XP · .. n = l, 2, · · · If X, takes values 1 and -l with probabilities p and 1 - p respectively) S" is called a simple random walk with parameter p. Furthennore, if p =t, the process S 1s a symmetric random walk. For symmetric random walk, it's ea'iy to show that E[S~, ] =O and var(S,) = £ [S :J-E[S, )2 =E[S:]=n. ~ymmetric random walk is the process that is most 5 1 otten tested in quantitative mterviews. The interview questions on random walk often revolve around tinding the first n for which S, reaches a defined threshold a, or the probability that Sn reaches a for any given value of n . Martingale: a martingale { z,; 17 ~ 1 } is a stochastic process with the properties that E[ Znl]<ooforallnand £[2n•J 12 =ztJ) z11-J 11 =Ztl - 1' ... .. z,= z,]=z . Thc propcrtyofa II martingale can be exte nded to E[Z.,;m> n iZ, =z",Zu-1= z"_" ... ,£, = z,] = :,, which 6 means the cond itional expected value of future Z 111 1s the current value Z". Asymmetric random walk is a martingale. From the definition of the symmetric random ={S" + I with probability 1/2 . so E[S""',! S, = s~, , .. , , .)'l = .~·, } = s,,. SII -1 with probability 112 2 2 (1 + 1)] I [( C' 1)2 + ( s· 1)1] ( n + l) S - n S - 11 is a martingale 1 = 2 .._1 + •I walk we have S "+ 1 n(n-1) · Apply ing the :xtl111.! z" =0, we can get Since £( •)211 +1 - 11 l II - - - ' II t as well. ,·~ cas~ '. Even this step is not straiuhtforward. You need to plug in the and try a few starting with ' =: n - I Th o I lta'lning Z l ... l cancel out. , · e panem will emerge and you can see that all tle tenns cot · .. • · · lnd ·t· d · 1 · If I' r( 'I ) - 11 then we uc 100 again can be used for its proo[ !'ar(S,) = I ar(Z,I"' I. In ucuon s ep. a •• - • have r · · d pendent of ~ 1·510 , ur(S•• l= l'or(S +.T ) = l or(S ) ..- l ctr(.'t )=n + l smcc .t.,. e • ~· Do not l'. • ... • ··• A rt 10 ' gale does not need to be a Markov conrllse a martingale process with a Markov process. ma PrOcess; a Markov process docs not need to be a martingale process, either. 11 5 Stochastic Process and Stochastic Calculus A Stopping rule: For an experiment with a set of liD random variables XP X , .. ·, 2 a stopping rule for {X,; i ~I} is a positive integer-value random variable N (stopping time) such I hat for each n > I . the event {N 5 n} is independent of X, ..1 , X,. , • · ·• Basically it 2 says that whether to stop at n depends only on X,X 2 ,-· ·, X, (i.e., no look ahead). Wald's Equality: Let N be a stopping rule for liD random _var~~les X ~k ··· and let -- .. ·s. =: X1 + X~+· ·· +-X 1• • then EfSvl = E[ X]E[N]. -- Since it is an important-yet relatively little known-theorem, let's briefly review its proof. Let /, be the indicator function of the event {N ~ n}. So SN can be writ1en as 00 S .. =LX,I,. where 1, =I U•l if N (!: n and 1, = 0 if N 5 n -I . From the definition of stopping n1les. we know that }11 is independent of X , 11 X, ._,. • • • 1 (it only depends on X"X 2 .···,X,_,). So E[X,!,]=E[X,]E[l.,]=E[X]E(In] and E[S. ] =Er tx..t.} t.E[XJ.)= ~£[ XJ E[I.,J =E[ x)t, E[ 1.. )= E[X ]E[Nj . 1 A martingale stopped at a stopping time is a martingale. - --- . I Gu"de I To Quantitative Finance Interviews Pract1ca .. 7th meter) to 0; then the problem becomes a Let's set the curren t pOSitiOn (the I . 83 17 We also know that both S,. and lk 1h t tops at etther or - · symmetric random wa a s · g time is a martingale, artin ale stopped at a stoppm . - n are mal1ingales. Stnce a m g . h N being the stopping time) are 2 h v +X + .. .+ X . Wlt s. and S - N (w ere .v = A 1 ~ " • _ 83 p be the .\ N the robability that It stops at a - ' P martingales as well. Let Pa be ~_ and N be the stopping time. Then we probability it stops at - f3 = - 17 ( Pf1 - 1 p a), s; s have } { p = O.l7 £[S,]=pux83-(l-p())xl7=So=O -O => £[~]=1441 2 E[S ]- N]=E[p x832+(1-pa)xl7 2]-£(N]=So -O) s a . d f the bridge (the I OOth meter Hence the probability that he will make ldl toh thexpelelct:d number of steps be rakes to · · ·ts 0· 17 ' an t·de e· 1441 before' reaching the begmmng . · 1 d of the bn ge lS · · reach either the begtnnmg or t 1e en . metric random walk starttng · t a ooeneral symprobabJirty . . that ·tt st ps· at a We can easily extend the solutiOn _ fJcase. > ).aThe 0 0 from 0 that stops at either a (a> 0) or f3 ( . . time 10 reach either a or -fJ instead of -P is Pa = f3 /(a+/)). The expected stopptng ° is E[N]=aP. ~ Drunk man A~ drunk n.1an is at the 17th meter of a tOO-meter-long bridge. He has a 50% probabilit~ ot_staggen~g forward or backward one meter each step. What is the probability that he Will mak~ 11 t~ the end of the britlg~ (the 1OOth meter) before the beginning (the Oth meter)? What 1s the expected number of steps he takes to reach either the beginning or the t:nd of the bridge? So.lmion: The probability pan of ~he problem--often appeariryg in different disguises- - is umong . I he most popular martmgalc problems asked by quantitative interviewers. lnter~sttngly, few people us ..· a clc1.1r-cut martingale argument. Most candidates cith~r u~ ~~ra~kov. chain with t:-ro absorbing states or treat it as a special version of the gamblt!r s rwn problem wJth P = 1/2. Th~::;e approaches yield the correct results in the end. y~:t a martingale argument is not only simpler but also illustrates the insight behind lh~ prohkrn. Dice game 'd h face value. If a roll gjvc.s 4. 5 11 you are pat t" c the game slops. . What 1s the I 1 Suppose that ) 'OU roll a dice. For eac ro ' 2 . If you get 1 or .>, or 6. you can roll the dice agam. · expected payoff of this game? the problem. A to so 1ve . I w of total expectattOJ ' : alitv si nce the Solution: In Chapter 4, we used the a I ·d '·- is to apply Wald s Equ ·b·lbility of simpler approach-requi~ing more knowe~c~t: rolL the pr~ccs: has: 1/2 ~:~ and we problem has clear stopptng rules. For t ic distnbuttOn \\Jth P . . . 0 !lows a geome r . N .fl . X I 7 I 2 fht:: tota1 St()pping. So the stopping ttme d iacc value is Ef :::: · have E[N} = 1/ p = 2. For each roll, the expccte . E[N]expected payoff is E[SN] = E[XI - 7/2 >< 2 =7. · 1 /2 Ticket line 0 ~~"''ut"S ~ J~~~~~ ..r••ben otlf G. ~ndGallager. applk.'illiuns of Wald's Equality. please reter to the book Disaete Stocllu~ti£· b~ ., I I6 . . kets. n of them have only. $5 waiting to buy ttc change to start At a theater ticket oflice, 2n people me b'll The ticket seller has 110 bifls and the other n people have only $l 0 1 s. 117 . l G 'de To Quantitative Finance Interviews A Prae11ca u• Stochastic Process and Stochastic Calculus with. If each person buys one $5 ticket, what is the probability that all people will be able to buy their tickets without having to change positions? This problem is often considered to be a difficult one. Although many can correctly formulate the problem, few can solve the problem using the reflection principle.8 This problem is one of the many cases where a broad knowledge makes a di fTc renee. b ,\'olution: Assign +I to the n people with $5 bills and -I to the n people with $ 10 bills. Consider the process as a walk. Let (a,b) represent that afte r a steps, the walk ends at b. So we start at {0,0) and reaches (2n, O)after 2n steps. For these 2n steps, we need to choose n ~h.~r>S us + I. so there are ( 2 l .:.·i) J property b = I, .30 <a< 2n, given that the path reach.es (2 n, 0) is also ( 211 n-1 Jand the number of paths that have the property h?! 0. '\10 <a < 2n is -l · n ) ?.n \ 2n ) = ( 2n n- J ..-.. ····... ····... -2 ...../ ···... .~ .... ·..··..·"':' ··... ··....·· 2 n = n! possible paths. We are interested in the paths that n ) n!n~ have thl.! property b?! 0, '\10 <a< 2n steps. I~ ~asier jo_calwlate tht· _number .Qf ~ompl.\!mcru,paths.lhat$,LCh h =- l.- 30 < a< 2n. As shown i.n Figure 5.6, if we reflect t.h~.: path across the line y =- I after a path first reaches - t , for every path that reachc~ (~n. (J) al step J n, we h~~e one corresponding reflected .P~th. {ha.tieaCF\es l2n,- 2) at step 2n. I or a path to reach (2n, 2) . there -;;e ·(n ·;t;ps of + 1 and (n + 1) steps~I. 211 2 So there are ( = n! such paths. The number of paths that have the n-1 (n-l)!(n+l)! [ --------1 l _~(2n ) = _ 1 n ) n+ l n ) ( 2n '\ n+l l n / lienee. the .r.rQba?ility that all people will be able to buy their tickets without having to postltons IS 1/(n + 1). chclJlg~o: . .15 the reflection of the solid line Figure 5.6 Reflected paths: the dashed ltne after it reaches -1 Coin sequence d ber of coin tosses to get 11 . . What is the expecte nwn Assume that you have a fatr com. heads in a row? . ds in a row. ln ber of coin tosses to get n hea . H) Solution: Let E[f(n)] be the expected num ,. =3 (to get the pattern HH . · · d the case when:: n . M kov charn the Markov chain section, we dtscusse . d t· 011 approach. Ustng the 1 ar A ah •ra l uc t £[/'(3)) -- 14 · n '"' For any integer n, we can canst·d cr an m _? £(/(2)]::: 6 and approach, we can easy get that E(j(l))- -) "...1 _ As always, let's prove the 2· ·15 th t Elf(n)) == 2 3 S we onl) guess for the general formula a .:_. . ul 1'S trUe for n == 1,2, · 0 hown tne torm a · d' a(lram formula using induction. We have 5 ,.2 _ 2 The fol\owmg 1 ::. ,,, 2 £[/ (n+l)]= 2 · need to prove that if Elf(n)] = 2 - ' r E.[J(n +1)}: . holds tOT shows how to prove that the equal JO0 P=l/:_. ~ P~I /2 1 Consid('r n rand<l 111 · · ,. \\a· Jk srart•% at . · · · n. S = n. and rcachmg h 1n 11 steps: s, ""b. Denote N,(a,b) as the numl)cr of po~~iblc paths from (0 ) .. ' ,a to 111. b) an d ·'. (a. b) as the number possible paths from (O.a) to I rJd' l that at M'mc step k ( ~ > o ) ,. )· , ·1 · ' ' t~l. .30 • IU UIII\' ~ I 18 • • •'. ~ ( , tn other words. ,v (a. b) are the paths that con tau I .. II. The renee lion principle ays that if a. h > 0. then '\ I a. I> 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·<lymg when the second game. oses a game or whe h . G ISt..' hl.: collects $2" (' ,.th b b. . n e wms n games in a roll in which _. v\l pro a 1l11y 1/ 2" ) N , . . . . • h~fore each toss <:LP t.>W ~ambler . . . .~, . ow l~t s m.la_gme. mst,§ad.of ()QC •ambler. w11. h n h·.mk.1o11 of S 1 as - -well·- At! JOJOs_lue...g,ame h . · and bets_Qfl· ~he_s~m~eg_uence of n heads gnme and the total amount~f · er t e H h game, 1 gamblers have participatedm ih: game is fair. the exn.•cted val monfeyh t~ey have put in th e game should be $i Since each . , ~"~ ue o t e1 r total b nk 11 · . · . .a. ro ts $1 as well. In other words. tf w~ 0~::nott: x, as the amount of mon . II h ey a t e parttc f then (x, - i) is a martino tpa mg gamblers have after the i-th game. 0 a1e. ~~~- l.et 's add a stopping rule: the whole . . ~ hr:-t to g~l n he11ds in a roll !\ . game wdl stop tf one of the gamblers becomes So '' ~• ~·t'JI haw E[(x - i)J = ()· •martmgale stop ped at a stoppmg . time is a martinl!alc. 1 11 t11e scquen (t- n + I) -th player is the fi . ) ce stops after the i-th toss ( i ~ n ). the 1 I . ' trst player who • 11 t I\.' (r- n) players before him " b gets heads in a roll with payoff 2". So all · \\\;nt ankrupt· tl (1· tn a roll "ith pavofr 2"-1. . . ' le - n + 2) -th player gets (n - I} heads )' n" • ) "" the /-(h pla I ' 1) \J r:> fixed <.~nd x -:; ;. 2" 11-1 ) er gets one head wi th payoff 2. So the total . +-1 -1· .•. + 2' :::: 2" +1-? . I • 1 Hence, F[(x ·- i)] = ' ) li d _ 1 . - · - - £f/l ::: 0;:;:>£[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 <h nmnic sect1on barely scratches the surface of dynam•c programnu g. . rol b. Profc:Gnr topics. I'd recommend the boOk Dy11amic Progr ammillg and Optunal Ctmt > lllnllln P. Bertsekas. . . . ~ the In " ~ . . . di ·cuss1on. we on\) cons1dt:r 1 oencra 1, x~, can mcorporate all past relevant 1nfonna11on. n our ::; Present in[!ormat1on · by assuming Markov property. 121 '" Th' ti~g~a1_nming IS .. ________________________.....................---------------------A Practical Guide To Quantitative Finance Interviews Stm:ha:-tic Process and Stochastic Calculus Basically the state of next stage x.h , is determined as a function of the current state x,. current decision u" (the choice we make at stage k from the available options) and thl' ranuom variable w.. (the probability distribution of wk often depends on xk and u1). 2. A cost (o r profit) function th at is a dditive over tim e. 1 ·\t:~ pt lor the last stage (N), which has a cost/profit g "' (xN) depending only on x, . the cust!> 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 t<lll suhprobkm £{g, (x )+ "" g (\· . )} '. \ ~ ~ . .(•ll, .llk N- 1 . ... T.J DP algorithm: To solw tl " b . . . . v' . . _ 11:: a:;1c ptoblcm J~.(x11 ) ; min E{gN (x,.,) + L gt( x~ . u 1 .1'tl.· • -- ~-arl w1th J •. (x~) - g (x }. and , IT f • ( ' - - . . . . . . . ·: . . L· · _ . _:_ go backwm w mm tm tzmg cost-to-go functwn .I; (.\J r· .l,( xt ) - min l!{g ~ { 11 --:-) . - ,.l •·• • ~ · t ·u , + .l;..,C/(:rl. uk,l1·i H}.k = Q, ... ,N-L Then the J,(\ , 1 gen\!rtH~.::d 11-om lhi!\~Jgorith;n is the ~pccted opti~lal cost. - r\ltlmugh the algorithm looks CO! I' . . .. . ic progrum min~ pt·oblems I llp lCated. _the I!){UJttOn is straightfonvard. for dynal11 r the !in.d SH;ue 'whi ·11. Slloul~ start wnh optimal policy for every possible state o. "" ' ~.; 11<.ts t 1e htgh 'st • . nt ul untcrtuint)) tirst and th. . l: amount of mformation and least amou .1 . • ~.:n \\·ork backw· d d · t11e 1:11 Pl>lt~ic:s unJ ~:ost-to-•'o fun . . . ·<.1r towar s earlier stages by applymg 1ton~ until you reach the · · · 1 : : ~ N • tl1ltJa stage. ow kt s u~e ~e\ cml ~:xample . I 0. h s s ow ho\>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~<m: Let (;, j) represents the state that the ~ ff h. h can be negative when R k' · ') be net payo · w tc oc 1es has won} games. and let .f(t,J our " know that there may be - I 0 f the game. \\C we lose money at state (i j). From the ro cs , . that whene,·er the be ' ' d . ide on a strateg) s 0 tween 4 and 7 games in total. We need to ec v • l23 .. S1ocha:-.tic Process and Stochastic Calculus . 1Gu1'de To Quantitative Finance Interviews A Practtca s~.:ri~:s is over, our final net payoff is ei ther +I 00- when Red Sox wins the championship-<)r - 100-when Red Sox loses. lo other words, the state space of the final stage includes {(4, 0), (4,1), (4,2), (4,3)} with payoff /(i,j)=JOO and f(0.4), (1,4), (2, 4), (3,4)} with payoff f(i ,j)= - 100. As all dynamic programming qu~stions, the key is to start with the final stage and work back wards-even though in this case the number of stages is not fixed. For each state (i , j), if we bet $yon the Red Sox forth~ next game. we will have (f(i, j) + y) if the Red Sox wins and the state goes to (i ·I I, j), (lr (.f(i. j) y) if the Red Sox loses and the state goes to (i, j +1). So clearly we have wins .. also calcuJate the bet we need to place at each state, wh ich is essentially our strategy. lf) ou are not ac(;ustomed to the table format, Figure 5.8 redraws it as a binomial tree. i.! format be familiar with. If you consider that the boundary conditions are 4 you should 4 j ( , O): /( . I),. /(4, 3), /(4, 2), /(0, 4), /(I, 4), /(2, 4), and /(3, 4), the ~IIH.k·rly mg ass~:·t ctther inc reuses by l or decrease by J after each step, and there IS no tnh:n.·st. a ·s,·,nple b'lllomta . I tree pro bl em and lhe het we plncc ,. . . then , 1. . thl.! , probkm .10 bt:comcs . . ddta dynamic hedging. In fact, both European options and Amencan opt tons ca n b~ so l\ l.!d nun1er'1 " II . .· d . C" Yusmg ynam1c pmgramming approaches. ~.tc~ tun~ ~ th~ 3 wins 4 100 ~ 1 100 ~ -5 2 100 e \,; 3 2• 4 -100 -100 -100 -1 00 i :=: ~ :> j + I) )12. .v=(f(i+1,j)-f(i,j+l))!2 4 For examplt:. we have /(3. 3)=/( , 3)+ /(J, 4) = IOO -I OO =0. Let's set up a tabk 2 2 with the columns r~presenting i and the rows representing j. Now we have all the information to fill in /(4, 0), /(4, J), /(4. 3), /{4, 2), /(0, 4), /(1, 4), /(2. 4), /(3, 4). as well a:; /(3,3). Similarly we can also fill in all j(i,j) for the state· wh~re i .;:= :\ or .i == 3 as shown in Figure 5. 7. Going further backward, we can fill in the net payo ffs at every po!'sible state. Using equation Y=(J(i+I, j)-f(i, j+J))/2. we can 2 1 0 0 ;. f(~ +.1 . J) = f(~, ~)+ Y~ ==:> {f(i, j) =(f(i+ 1, j)+ f(i, /(1, /+ 1) .::: f(t,j)-yJ Red Sox Red Sox - 1 "· Ci :i ~ ~ e ~ 8~5 -100 ~ 1 7~~ 1-100 'Q Q 2 104 ~00 2 3 -8• .!3 ~~s~ ~-~ 1-2• 100 4 -100 -100 -100 -100 :2 a: .. eo 0 () I Red Sox Red Sox wins 0 1 0 0 3 1 . 2~ 3 2 bets 4 62.5 87.5 100 ~ :i 37.5 50 50 f0 3 12.5 25 50 100 0 50 100 3 -87.5 -75 -50 0 100 4 -100 -100 -100 -100 0 ~ e "3 v I - 8 ~ 37.5 37.5 25 25 -62.5 -37.5 2 0 131.2~ 31.2~ 25 12.5 2 g a: Cll 4 3 'Q 100 0 2 31.2~ 75 -31 .3 1 0 1 37.5 1 4 3 0 ~ ~100 2 1 0 4 Figure 5.7 Payoffs and bets at different states 100 (4,0) 100 87.5 (3,0) < ( 1 0) 10~0) (3.1) (2,0) 37.5 50 (J~J) 0 0 (2.2) ( 1.1) -37.5 ( I .2) -50 - 100 -100 (2,4) (I ,3) (0,2) < (3,4) (2.3) -15 -62.5 IUU tUl (3.2) (2.1) ·31.25 (0, I ) 100 (4.2) 15 62.5 31.25 (~.1) -1 00 -87.5 (!A) (0,3) -100 {().-$) Figure 5.8 Payoff at different states expressed m a binomial tree 125 » A Practical Guide To Quantitative Finance Interviews Stta:hastic Process and Stochastic Calculus Dynamic dice game Dynamic card game casino comes up with a fancy djce game. 1t allows you to roll a dice as many times as you want tmh:ss a 6 appears. After each roll if 1 appears, you will win $1 ; if2 appears, you will win $2; ... ; if 5 appears, you win $5 ; but if 6 appears all the moneys you ha\'~ won in th~ game is lost and the game stops. After each roll. if the dice number is 1·5. you can decide whether to keep the money or keep on rolling. How much arc you willing tu pay to play the game (if you are risk neutral)? 12 J\ 1 Solution: /\ssuming that we have accumulated n dollars, the decision to have another roll or not depends on the expected profit versus expected Joss. If we decide to have an extm roll. uur expected payoff will become I 6 I 6 I 6 ., 1 6 I 6 l 6 5 6 - (II -+ I) + - (11 + 2) + - (n + J) + - (n + 4) + - (n + 5) + - x 0 = - n + 2. 5 . We haw another roll if tht: expected payoff ..?_ 11 + 2.5 > n, which means that we should 6 keep rolling if th~ money is no more than $14. Considering that we will stop rolling v. h~n 11 ~ 15, the maximum payoff of the game is $19 (the dice rol Is a 5 after reaching the state n=I..J). We then have the following: /(19)=19, .f(l8)=18, /(17)= 17. /(16) =16. and /(15) =I 5. When n $14, we will keep on rolling. 50 . I s • ELf (n) Ins 14] = 6LEff(n + i)l. Using this eq uation, we can calculate the value lo~ ·-· Elf(n)j recursively for all n =14. 13, ···, 0. The results are summarized in Table 5·: . •Sine~ £f./"(0)] -· - 6· 15· we are II 18 ILJ (nJ ·~ 10 5 I hr.l: If Y~• 16 15 14 13 12 II 14.17 13.36 12.59 11.85 11.16 8 9 91 · 7 6 5 4 3 2 9.34 8.80 8.29 7.81 7.36 6.93 0 6.53 )] 13 j "(O .. ) - () the boundary condttiOns .r - , As shown in Figure 5.9 (next page), using . for E[f(h. r)1 , \ VC can j (h, 0) = b, Vb, r = 0, 1, ... '26, and the system cquatton · f band r ' rccurswely calculate E[f(b, r)] for all patrs 0 . F:[ {(26. 26)} = $2.62. The expected payoff at the beginning of the game lS ' · · 6.JS - ff f th yo 0 e game when the player has accumulated n dollars dccid~ hl have another roll . ' hi(!h.:r II~~~ lhe llfll(llltll be for~: th~ 11 A. h · the expected amount you have aHer the roll should bt: ·r-. 6 · s t c number of do 11 ars ·Increases. vou risk losml!. · more~ 1-none", 1 • app..l1\, ~~~ \\hen the amountm\l"d 1 12t. _!._[f(b,r-1)])· E[f(b,r)] =max ( b-r, -E[f(b-l,r + b+ r · b b+ r ·11·mg to pay at most $6.1 5 for the game. Wt UU)t) 17.00 16.00 I 5.00 Table 5.2 Expected pa l! 17 . d d 52 cards (26 red 26 black). The Acasino offers yet another card game With the stan ar one (Drawn cards are cards are thoroughly shuffled and the dealer draws cards o;e ~ytime .you like For each not returned to the de~k.) You can ask the dea~e~ to~~~:u :se $!. What is tl~e optimal red card drawn, you Win $1; f~r ~a_ch black car araoff a~d how much are you willing to slopping rule in tenns of maxtmlZlng expected P Y pay for this game? . b d'fficult by many interviewees. Yet it is a Solwion: It is another problem perce1ved to e 1) t the number of black and red simple dynarnic programming problem. Let (b, r represen . 1Y. BYsyrrunetry • we have cards left .m the deck, respecttve . le'ired cards left =hI ds red cards drawn- black cards drawn = blac k car · .1' keep on playing. If we ask the At each (b, r) , we face the decision whether to stop or . h · there IS . b- If we keep on got ng, b+r dealer to stop at (b , r), the payo ff ts r. . in which case the state changes to probability that the next card will be black. .. ·u b red-·in whJch case the state (b-1, r) -and - '- probability that the next card Wl e . b+ r . ected payoff of drawtng more changes to (b , r -1). We will stop if and only tf the exp . . cards is less than b- r. That also gives us the system equauon. o11ar reaches a ccrtam • · number. you should ·' stop rolling. · [I r American optiOns. tion as the one o ou probably have recognized this system equa ) decide whether you want to exercise the option at slate (b. ' · ,. .y f:,ssct!fi u.Jl\ \ "OU , . 127 • A Practical Guide To Quantitative Finance Interviews 5.4 Brownian Motion and Stochastic Calculus .t-u~· Prn..;.•ess <~nd S!Ocha~tic In this section, we briefly go over some problems for stochastic calculus, the counterpart of stochastic processes in conti nuous space. Since the basic definiti ons and theorems of Bro-wnian motion and stochastic calculus are directly used as interview problems, we' ll simply integrate them into the problems instead of starting wi th an overview of Calcu lus definitions and theorems. Number of Black Cards Left 2 3 4 6 6 2 3 4 5 4 7 8 9 6 7 8 5 6 3 4 5 0 2j 0 !101 0 ~5 1.34 2 3 (lJii D'lC iJ&.1 l DO 1 44 ~.07 I' 22 20 21 'i' .ll 11 • 19 20 21 11. ~ , Brownian motion 17 18 19 20 <I A. Define and enumerate some properties of a Brownian motion? IS 16 17 18 19 :l : <• ;· ~ I 13 14 15 16 20 18 19 16 17 18 14 15 16 12 13 14 11 12 14 15 16 17 12 13 14 15 16 17 11 12 13 14 15 9 10 II 12 13 7 8 9 10 11 5 6 7 8 9 10 IT fllJ ;l 54 II 71f I 1' 1.55 2 15 3 4 t• 0711 o4s OSfl os1 123 I s s 2.23 3 5 4 6 s s e 7 9 8 5 6 7 1.4 3 1.84 2.36 3 05 4 5 o.7s o.ss 1 21 I 52 1 92 2 43 3. 10 4 111 l 025 a~ 3 11 12 9 10 1\ B 9 10 6 7 8 5 6 4 10 11 12 13 14 15 16 17 1* 10 11 12 13 14 15 115 ,. 8 7 9 14 15 10 12 11 13 8 10 9 11 6 12 13 5 6 7 8 9 10 11 1 04 1.30 1.61 2 00 . 2.50 3.15 4 5 0 32 0 42 0.54 0 66 0 1.12 1.38 1.69 2 08 2 57 3.20 4 6 5 7 8 9 \0 11 6 7 8 9 10 11 ' l. 5 6 7 8 9 10 I. 2.22 2. 7o 3. 28 4 o 3 s e 7 0 191 60 9s 1.13 1.35 1 2.29 2.75 3.33 4.06 5 6 0.86 1 02 1.20 1.42 t .67 1 .98 2.36 2.61 3.3s 4.09 s a ll •o o~ o ,., liOQ cIJI'j o •• o ·2e o 39 o 52 o.66 o.8...) "' Ql" 0.43 ose ~ .81 0.99 39 0 49 0 60 0.7J O 89 o.Js 45 o.s5 o.s7 80 0 33 042 051 06 . • I 0.73 031 .4 o.s? 0 39 0 7 029 036 0 067 . ·4 4 0 53 062 )2d .,._ A4• 0 .41 049 058 . D(J? 1114 (1 22 0:!0 0 13 :; :m 0.28 OOrJ o 13 t n 25 0 QQB c 012 18 o 24 !:a$ 0,. 0 11' 02'., II~ 4 1)11 0:1«1 035 046 0 59 0.74 0.91 D.Cfl 0 0 11 C!<! 0 2:/1 On!. n t, 18 s 056 o 1 1.o 1 134 1.75 2.30 3 6 D 1t 0.22 0 35 0.49 11< '6 6 0.86 I II u:r~ ~ 01~ II~ D~:; ° 0.32 039 0.46 ·~ ~ 1Q 0 '" ... 0... 0 ... ... D 13 !1 1d o23 o 2s . 120 1. 46 1.77 215 2.63 324 4 l.06 1.28 1.53 1.84 6 ~ 1.15 1·33 1.55 161 2.11 248 2.93 3.48 415 1.39 1.61 0 0. ~ 0'1 ~ o~:.e 11 _ . 04~ o,.. t3 o a7 • .4B 0 55 0.63 o 72 0.83 c 94 1 07 2 1. 1 1.38 1 .57 1.79 2 recite all the details. A continuous stochastic process W (I), t;::: 0, is a Brownian motion if W(O) =O; • The increments of the process W(t1) - W(O), W(t 1 ) -W(r,), ... , W(tJ-WU.. o~" • I ~ "",. '" ~•t til 2.'5 2 72 '1: ) .> J.22 o.-<""' 032 0·3t e: oO.S6 e c o 68 o 77 o 8 7 o ·99 1. 12 12e 1 .43 1.s 2 1.85 z ll 2 4i '• '- I!' , ..... 43 0 9 .. •..... 025 o.G4 Oa2 0 .92 IO 1.68 1"0 2 162 4: ; :. 01111 0 0.30 035 041 047 . 4 1.17 1 .32 1 46 " ~ 111 1 29 0 0 97 1.08 1 22 1 3 7 1.54 I 7~ MIV lUI! ll •:: ,e o 2c o 24 o 053 o.so o.ss o 77 o .e6 ' "' l > on a ll ::.1 ~ C? .01,'1 OlS _...._.::..:::::...£.;·~ - 'VO $ ' • 187 2 .17 2.54 2.99 3.63 4'iJ • ~• ~ •.>7 0 33 0 39 ·J 45 0 52 TI1is is the most basic Brownian motion question. Interestingly, part of the det.mition, such as W(O) = 0, and some properties are so obvious that we often fail to e 0 06 .73 0.85 . 7 0.78 090 1.04 1.21 So~ttion: ~ 7 0 79 093 1.08 1.27 148 1.74 2 OS 2 42 2.87 3 43 4 13 5 ow 1 • 073 0.84 096 1 IO l.26 1.45 1.67 1 93 2.24 2.60 3 ().1 357 0.43 0.54 G.S l 063 0. 59 0 68 0.78 0.89 1.0 1 1. 16 132 Ollli G 14 0 II 024 0 "" u 0 3;," 0 4 1 0 . 1 51 1. 73 1. 99 230 2.66 309 CO) DO$ 1111) 23 • J 21 19 13 10 l l ~ 12 ~ ··· ~ t, are independent~ Each of these increments W(ti+I)- W(tJ - N(O , '••I -t,) . lS normally distributed with J, distribution Some of the important properties of Brownian motion are tl1c following: continuous (no JUmps); E[W(I)j ~ 0; E[w(I)' ~ t; W(t)- N(O,t); marting"l< property J £[W(t + s) IW (I)]= W(t); ~ cov(W (s), W(t )) s, VO < s < 1 ; and Markov property (on continuous space). Thete are two other important martingales related to Brownian motion that are valuable tools in many applications. ·2-' 3~ 0 39 0 45 0.5 1 05 7 0.64 072 081 01!1 f.IZJ U.. .. 28 0:,2 037 043 . 0.90 1.01 l.i3 Fogure 5.9 Expected payoffs t d. ' " o.s. o." o 68 o." o.es a tfferent states (b , rj •.. 26 1 42 •,.59 178 095 ' ·'" "" '-'' ' " ~1)1 I •~ oc : • Y(t) = W(t / -I is a martingale. • Z() I { } =exp A.W(t)- 11t 2t , where). · 15 constant and W(t) is a Brownian an)' motion, is a martingale. (Exponential martingale). AB . . . since it i!> 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 <- B which accounts for 1/8 of the density volwne. (All 8 regiOnS separated by 1 I I' ) x= 0, Y =0, y = x, and y = -x have the same density volume by symmetry. =exp{-UV(t)-fA·t}exp{-y-i 2s} E[ exp{,ZW(s)}] =Z, exp{ -tA-2s} exp{t 4 2s} =Z, 0.15 . B. \Vhat is the corrdation of a Brownian motion and its square? .\olution: The solution to this problem is surprisingly simple. At timet, B, - N(O,t). by symmetry, Ef B,J = 0 and E[B;'] =0. Applying the equation for covariana .~ 1/) c ~ 0.1 Cov(X, Y) = E(XVJ- E[X]E[YJ, we have Cov(B, , B/) =E[81J] - E[B,]£[8,2 ] =0-0 =0. So the correlation of a Brownian motion and its square is O, too. 0.05 C. Let B, be a Brownian motion. What is the probability that B > 0 and B < 0? 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 <111 m cpcndl.'ncL'. "·~ can rd(Jrmulat" th ~..: e equatton as PI il1 "> 0. B, < 0) == P(B O . I> )P( 13,- Bl < O)P(j B~ - Bl 1>1 Bl D =l 12xl l 2xL2=1 18 ?llh ) · \tO, q So t: (t'xp'.i. JJ(·)']. iabl• 1 ' .\ c ts th~ moment generating function of normal random var' ·• N(O. , 1. ' 130 Figure 5.10 Probability density graph of (61. Bz-81} 2n e -lr 'r.I 'J~d.xdy = c:l~r ~ ~ rdrd(J = 7I 4Jr - 3I 2n [··· 2;r . . s, Stopping time/ first passage time _ ·ach either -I ur I? Brownian motion to rc A. What is the mean of the stopping ttme ,or a . ._ be roved by applynlg 1\o ~ So1Utiun: As we have discussed, B;' -I is martingale. It can P . r. , lem.ma: - t) dr == 2BdB dt +dt == 2B,dB,. l El(B2 , 1 ' dt+- "'B 2 aB, I at 2 o ' . {i·R-Ior-Jl. At . 1 Let T =mm · ' So d(/3; -I) has no drift term and is a martmga _e. l' " A martingale stopped at . . . • pertv sull app tes. conttnuous time and space. the rollowmg pro ~ cJ(B;, - t)= 8( B2 - I) , dB+ D( 8 2 -1) I }31 !:itocha~tic A Practical Guide To Quantitative Finance Interviews Process and Stochastic Calculus s;-Tis a martingale and E[.BJ. - T]= sg- 0=0. a stopping time is a marting_aJ~! So The prohability that B, hits I or -I is I . so BJ. =I => E[T] = E[ B; J::::: I . h .h r oo and E [ r ) = x x \1. ~ rf) . essentially the expected stopping time to reac eJt er x o ¥ • ' - 2- 2N(x t .roo) =1 the expected value of r x IS oo. Although we have P( r.r 5 oo) ' HVnJ B. Let W(1) be a standard Wiener process and r., ( x > 0) be the first passage time to y --------------------- ------------ ----------------*: I level x ( r, =rnin{t; W(t) = x} ). What is the probabil ity den sity fu nct ion of r, and the ex pected va lue of r., ? • I // ' Solution: lhis is a textbook problem that is elegantly solved using th~ reflecli~m. principle, so we will simply summarize the explanation. For any._W.ien~!:_f?ro~_Qg!hs. that reach X before I ( f~ ~ I), they hay~ ~qual probability ending_abQVe X Or below X rll I I I I timet,. P(r.$1JV(I)~x)==P(r.• ~1,W(t) $x). The explanation lies in the re!k~ticm principle. As shov\'11 in Figure 5. JJ, for each path that reaches x before I and is at a k,e) Y nbon.' x at time t, we can switch the sign of any move starting from r, and the reOected path will end· at 2x- y that is below x at time 1. For a s tandard Wiener proces..; (Brownian motion), both paths have equal probability. P(r ::; 1) =P(r 5: t, W(J)~x)+ P(r,. ~ rJV(t)~ x) = 2P(r.. 5 r,W(I) ~ x) f =2P(W(f) ~ x)~2 _!_ e -~..:n, dw · .J2m . rocess and its reflected path Figure 5.11 Sample path of a standard Weiner P . P( .. rT<;,t ) r . . t) = dW(t). If X sturts at 0, · -·ith no dnft, t.e. JX( ·n i e l Suppose that X js a Brownian mottOn w . . S? What if X has <.In 1 m, · · \\b(lt is the probability that X hits 3 before hltttng ~ · I . I =2 ., &ie_ ". '~dw==2 [,r, .J2; e-··'l 2dv=2-2N(x 1Ji). 3 · Tak~ the derivative with r~o:spect to I , we have t: V ~= riPfr. S t} .. d! _ dP·:r, ~I) d(x i J/) - r'- 1~, - d( ·I r) d ::: 2N '(x I J() x ~ t -.v 1 ::::::> 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 <n Taking the dcrivauve 0 ·, r .T . can envc the probability density function of .\/ (I) . £[ N] =ap. P( ) be the probability a martingale. Let I. x . I (!Cr a When X has drift m the process is no longer · 1 Although X 1s 0 0 00 , • . . _ h X ."C at ume · that tht! process bits 3 before h1ttmg -5 w en = 133 A Practical Guide To Quantitative Finance Interviews Stochastic Process and Stochastic Calculus maningale process, it is stiJI a Markov process. So P(t, x) =P(x ) is actually independent . 4. we have oft. Applying the Feynman-Kac equatton mP,(x)+ li2Pv (x ) =0 for -5 <x<3. Ito's lemma We also have boundary conditions that P(3) =I and P( - 5) =0 . mPt(x )+ I 12 P.u(x) = 0 is a homogeneous linear differential equation with two real roots: r1 =0 and r. =-2m. So the general solution is P(x) = c, e0 ·' + c2e -2"'.1 = c, + c~e·~, . · App lying the boundary conditions, we have , II j= 1 c ~ c.e {l '1 T r , < '' ., -~'0 ' ::;> c. -e e -e ' c = I /(e-ow -e Jn., ) I!J;" /( ..(,, , I Om ) :.:::> P(O) = c1 + c2 = e -<i el 0"' - .:: " "' I Om ] A diff~rent and simpler approach takes advantage of th e exponential martingale: 2 Z(t)=exp{A.W(t) - tA. t}. Since W(t)=X(I)-mt , X(t) - mt is a Brownian motion as . L X (t) . of the chain rule in ordmary calcu 1us. e1 Ito's lemma is the stochastic counterpart X)dW(t) and f(X(t),t) be a . fy' dX(t ) - fJ(t X)dt + y(t, • be an lto process sat1s _ mg ' f(X(I) I ) is an Ito process satisfying twice-differentiable fllilctwn of X(t) and f. Then ' 2 /J ar 1 y2(t ,X)-2 0 j dW(t) . df= of +/)(t, X)!1 +dt+y(t, X ) afJx ( ar ax 2 Ox of of I 2 X) a2f Driflrate = - + fJ(f, X)-+-r (t, 3x2 at ax 2 o r: well. Apply ing the exponential martingale, we have E[exp (ti(X -ml)-t.A?r)]=l for . and Zl -_ "' B1· A. Let 81 be a Brownian motJOn any constant A.. To remove the terms including time 1. we can set It= -2m and the eq uation becomest ~~xp(=-2~n.:r) ~_: I. Since a martingale stopped at a stopping time 1 ~ Z1 a martingale process? • eiOm amarunga k:.w~have P,exp(-2m x 3) +(l- ~) exp(-2mx-5) =1=> e ., 10 -I ...(,"' -e a . ts z ? Is I • . bout o Since fr is · . t) which is symmetriC a Solution: As a Brownian mot10n, B{ - N(O, ' an 0 and variance . about 0 and has me a constant at t, z, ==.JiB, is symmetnc var(B,) = t 2 ~ N(O , . More exactly, Z, 12 . Applying Ito's ) · value 0 it is not a martmga1c. Although zl has unconditional expected ) alz I ·I 2Bdt +JiJB,. azI dB+azl dt + 12 x ___!-Jt =,t I ~2 • lemma to z =JiB ) we have dZI = as I o/ v. I I ' d not I I I • ! I .. B I IS 'l'ty t • the dnft term 2 I r· ror all the cases that B1 -:1:- 0, w h.ICh has probab1 1 1 ocess · zero. s Hence, the process Z == vfr:Bt ·IS not a martinga e pr /J< D. Suppo~l.' that X is a generalized Weiner process dX = dt + dW (t)) where W(l) is a Brownian motion. What is the probability that X ever reaches -1 ? · Wh t . the mean and vanance of 0 Svlutivn: lo solw this problem, we again can use the equation £[exp (-2mX ) :: I prohll'm with m =- I. lt may not be obvious si nce we only have c~n~ app~~~.:nt boundary· -·! · To apply the stopping time, we al so need a correspon?~n~ pn::,lll.\'l' boundary. To address this problem. we can simply use +oo as the posJllH: hounJar) and the equation hccornes from the pr~::vious 1 . I B. Let W(I) be a Brownian motwn. Is W ( ) ' l.t1 \' bt' anlt•'IYOC~5.S gi,enb} equation dX(l) -= P(t .X)dl l- y(t , X}dW and f (x) bcafunctionod l~lm:..• function l'(t.x) ~ E[j(X ) v _ . . . . . h~ rarti• r ..., , - ·'I . then J (t . x) ~~ a mart in ga le process 1hat sat •sfie;) 1 ~: "'. . ti' ~~ I a~ II utll ..., nt1:tlcquation -- P(t .x)~~ - · ( ·) V . . . T _ f( r l ior it . A~ r I ••~ --::- =0 and term .mal condlliOil ,, ( . X J') X. I 1 - cJS • ~ a martingale process'! . roci!SS ·r ' and onlv. if the ) JW(I) i~ a martmga1e P A generahzed . .ener process uX .1. W1 = a(x •r )dl ... b(x, l c drift term has coefficient a(x. I) = 0. 135 1)4 Stochastic Process and Stochastic Calculus Solution: Applying Ito's lemma to cY f (W(t), 1) =W(t) 3 • we have of = '~w )1 c:f Bt - 0, oW(t)l = 6W(t), and df(W(I), t) == 3W(l)dt + 3W(t)2 dW(I). So again for the cas~~ W (t) :1:0, mart~ngale Chapter 6 Finance awe!) - (' · which has probability I. the dri ft term is not zero. Hence W(I) J is not a process. ' It used to be common for candidates with no finance knowledge to get hired into quantitative finance positions. Although this still happens for candidates with specialized knowledge that is in high demand, it's more likely that you are required, or at least expected, to have a basic grasp of topics in finance. So you should expect to answer some finance questions and be judged on your answers. Besides classic textbooks, 1 there are a few interview books in the market to help you prepare for finance )nterviews. 2 If you want to get prepared for general finance problems, you may want to read a finance interview book to get a feel for what types of questions are asked. The focus of this chapter is more on the intuitions and mathematics behind derivative pricing instead of basic finance knowledge. Derivative problems are popular choices in quantitative interviews-even for divisions that are not directly related to derivative markets- because these problems are complex enough to te$1 your understanding of quantitative finance. 6. 1. Option Pricing Let's begin with so me notations that we will use in the following sections. T: maturity date; t : the current time; -r == T- t : time to maturity; S : stock price. at time t; r: co~tinuous risk-free interest rate; y: continuous dividend yield; a: an~ual~zed asset volatt!ity; c: price of a European call; p: price· of a European ~t~t; (: ~r~.ce of .an. A~lencan call; P: price of an American put; D: present value, at I , ot tuture dt'vldcnds, K. stnke price; PV: present value at 1. Price direction of options How do vanilla European/Amerkan option prices change when S, K. r ' CJ, ,., or D changes? Solution·· Tile payoff o f a ca .1S max(S - K •0) c.u ,,.1d thepavoffofa put is max(K - S.O). • • •• 11 AE · J· 1·11ne whtlc an Amcncan L.., opt' uropean option can only be exercised at the . exp1ratJon · · 1 •,e ·an figure out tu.ll Jon can be exercised at any time before matunty. IntuJtlVC Y " ~ . . " ., the price of a European/ American call should decrease when the stnkc pnce mcn.:a~\;s ~orb . end /nvestnrcmts by Z"i Bodie. Ale:-; as•c financt: theorv and financial market knowledge. I rccomm . b John C Hull is a ' . . . . c: ml Other Derwot1ves Y ·. . , Kane and A1an J. Marcus. class· for denvatwes, Optwn.t , rutures 0 . and derivative pncmg. I d 1 1 •c. f you want to gain a deeper understanding of sJOchastlc ca cu us rtcomm1 d • d II) b'-' Steven E. Shreve. : F' en ~toclrustic Ca/CJJiulfor Finance (Volumes 1an J ced and Quantitative 10 Ad I F:· or example, Vuult Guidi! to Filrunce Interviews and Vuult Guitle '""n<·e Interviews. 136 vltn A Practical Guide To Quantitative Finance Interviews Finance you pay K now instead of Kat the maturity date, which is lower in present value); and the third component is the value of the put, which is often considered to be a protection against fall ing stock pnce. Clearly the second ~hethlro corripo.nents arebOlhpo·sitive. Sot he l·.uropean t:ail \hould be wor1h more than its intrinsic va lue. Considering that the corn.:sponding Ameri can call is worth at least as much as the European call, it is worth more than its intrinsic value as well. As a result, it is not optimal to exercise the American call before maturity. Argument 2. Le t's compare two different strategies. In strategy I, we exercise the call 4 option at time t (I < T) and receive cash S- K. Alternatively, we can keep the call, short the underlying stock and lend K dollars with interest rate r (the cash proceedings from the short ~ale, S, is larger than/(). At the maturi ty date T, we exercise the call if it's in the money. close the short position and close the lendi ng. TabJe 6.2 shows the cash tlow of such a strategy: It clearly shows that at timet, we have the same cash flow as exercising the call, S- K. But at time T. we always have positive cash flow as well. So this strategy is clearly ben~r than exerc~sing the call at time 1. By keeping the call alive, the extra benefit can be realized at matunty. " - S and S Let .), 2 = 0' then C(A.S) ~ A.C(S) + (l- A.)C(O) = A.C(S) since C(O) = 0. c hC(S t)+( l-A)C(S2) C(AS,+(l-A)S2) 0 Figure 6.1 Payoff of a European call option . C(S - K) If it is not exercised until 15 If the option is exercised at time t, the payoff at 1 ' · d . ·k ·utral . E- [ -rrc("1 ) un er ns -ne to 1) 1s e ' r maturity, the discounted expected payoff ( _ ,., J ·1· · measure. Under risk-neutral probab1 1ties, we T Cash flow .-£!.111 option Sr ~ K Sr>K 0 0 ___ Sr-K where the inequality is -Sr Let S ::. e'' S and A. = e-rr, we have C( A.S) =C('1 t Ke"r Kerr s Lend K R1 r -K -- ,._-Sr S ·K - Kerr -Sr > 0 Kerr = K>O Table 6.2 Payoff of an alternative strategy without exercising the call - Argum:nt. 3 · L~t'.s us~ _a .mathematical argument relying on risk-neutral pricing and .J~nsen s 10 ~~uahty.-Jt f (X) is a convex function~ 5 then E[f(X )] ~ f(Ef X]). From F~gure 6. 1, n· s. ~bviOus that th~ payofT (if exercised when S > K ) of a call option (. (S J- (S- K) ts a convex function of stock price with property C(J.S, + (I- J..)S~) < ).C(S,) + (1 - 2)C'(S2), 0 <A.< I. ··~ :: "-'lime S -:. A s . . ~ .lunct~nn 1.11 our d iscu~sion Ot l1 , 1. · · ·· · ~ W ISe, the ca ll surely should not be exercist:d. } (.\ ) is t·onve); if and only if/().x ! (I ·- A.)y)s;J.j(x)+(I-J,)j(y),O<.i.<l.lf i \.\ ' .. U, 'fix, th.. f( X ) is ~.:onve:-: . .,l ~e-rrc( £[s,.]) =_e-rrc(errs,). I Short Stock i ota! .._ So E[e-'rC(Sr)] = e-" £[ C(Sr )] also have £[S, ] =S,e · [Tom Jensen's inequality. - -rr ") <e-r-rc(errs,) ~ e ~ [ , c; )] 1:- C(., . - _ ~ Y < r under the ·Smce the dtscounted .' _,., 1 · s no less than C(S,) .:_or an. 1 payoff e E[C(Sr) b f re expiration. 1 -- ·- • • .. . . . I t xercise the option e o . ruk 'utral measure, 1t 1s never opttma 0 e . f the stock pncc. . - . l a convex functwn o . . k ll . non-dividend paying stoc. · 1"' i Should point out that the payoff of a put IS a so BUt ·tt ·ts often optimal to exercise · an American put on acrty that f (},S) , -< 1·• P(~') In fact ' ' · difference is that P(O) == K so it does not have the prop ly to American puts. ' . 1 calls docs not app P(J..S) ~ AP(S). So the argument for Amencar . , II option for .. f Amcncan c<~ . . . . . 1 cxerctse o an . . h before an__ex· SHmlar analysis can also show that ear Y _ 'bl' for the wne ng t _ · I except po:sst ) d.lVI·dend-paying stocks is never opt1ma _,_ __ dividend date. - . k with strike price $8? is · ·d d paymg stoc . $90 j<: pnced B A European put option on a non-dJVI en ·tock with strike pnl:c ~ . . the same s . currently pnced at $8 and a put optton °~ th se two options? at $9. Is there an arbitrage opportunity extstmg m e. . . 141 A Practical Guide To Quantitative Finance lntcrvi~w~ Finance Solution : In the last problem, we memioned that the payoff of a put is a conv_ex function in stock price. The price of a_p_ut o.Q_tio~ as a functiou of tb~ strike price ts a co~ function as well. Since a put option witl1 strike 0 IS worthless, we always have P(O) + ?..P(.K) =A.P(K) > P(A.K). For thi s specific problem, we should have 8/ 9 x P(90) = 819 x 9 = 8 > P(80). Since the put option wjth strike price $80 is currently price at 8, it is overpriced and we should short it. The overall arbitrage portfolio is to short 9 units of put with K = $80 and long 8 units of put with K = 90. At time 0, the initial cash flow is 0. At the maturity date, we have three possible scenarios: Sr ~ 90, payoff= 0 (No put is exercised.) av dO=dV--dS as av 2 av av 1 2s2a v)dt +O'Sav dW(t)--(pSdJ+aSdW(r)) =<a;+ pS as + 2 a as2 as as av 1 2 1s2 a v )dt =(-+-a as2 01 2 . . . ·i ce it has no diflusion term. lt should have It is apparent that this portfoho IS nsk-free ~ ~ h . - r V- ov S)dt. Combining these resu lts we ave risk-free rate of return as well . dO- ( as ~~v 90 > S'l' ~ 80, payoff= 8x(90-Sr) > 0 (Puts with K = 90 are exercjsed.) s, < 80, (av +.!_0"2S2 fJ at payoff= 8 X (90- ST)- 9 X (80- s/') = s1 > 0 (All puts are exercised.) The final payoff~ 0 with positive probability that payoff > 0. So jt is clearly an arbitrage opportunity. Black-Scholes-Merton differential equation Can you write down the Black-Scholes-Merton differential equation and briefly explain how to derive it? Solution: If the evolution of the stock price is a geometric Brownian motion. dS = JiSdt +aSdW(t), and the derivative V =V(S,t) is a function of S and t, then applying Ito's kmma yields: s av 1 2 a2v av ' = -a,+ J1 -as +-cr S -;::-:;-)dt + crS-dW(t) 2 cs· as ' IV ( av . J where W(t) is a Brownian mouon. The Black-Scholes-Merton differential equation is a partial differential equation that . av _1al s2 _ a2v == r v should be suh:;ficd by V: .av . :. . . ._ + rS -+ C.t as 2 as 2 2 2 av av av +.!.a2sl ~=rV, ~ )dt = r(V- ~ S)dt ~ at+rS as 2 oS) as u which is the Black-Schotes-Merton d'1fferential equation. . . ·e of the 9is_c.a.unted uation is a specta1 c.ls . b .d Th~ Black-Schole~-J\:1.erton diff~rent~ eq Fe nman-Kac theorem builds the .n ge Feynman-~ac ~?-~o~~~--- Tl~e dJsco_u:~~nd ~ial diilercntial equations and applies to between stochastic differential equatJO p . l alllto processes in general: . _ {J( X)dt + y(t , X)dW(t) and f(x) · b uatton dX(t)- 1• · Let X be an Ito process gtven Y eq _,\1 ,,f( Y ) IX =x], then V(l,x) ts a · V(t x) - E[e · 1 ' be a function of X Define functlon . ' .-fl. t'al equation . fiJes the partial dt eren t martingale process that sat1s ~+/3(t,x)av +_!_y2(t,x) a~V2 =rV(t,x) 2 at ax 2 - .. and boundary condttJOn -~ V(T - )-j(x) forall x. ,x - {J(r X)= rS and , ' · Uoder risk-neutral measure, dS = rSdt +a.), K equation becomes the Bl ac k-Scholes. d Feynrnan- ac r(t ,X)=aS, then the dtscounte "/ i/V . av o ~ t ,...~ ~2-= ,v. . -+rS-+~v • ~(· 2 Merton differential equatiOn ol as 1.. w "_X "'dW(I) Let ,, - • To derive the Black-Schoks-Merton difter~ntial equation, we build a portfolio with two components: long one unit of the derivative and short ()V unit of the underlying stock. as fl · av en le port oho has value I I = V - -S and the change of rh u as n follows equation Black-Scholes formula ,·th continuous dividend yield Y . an calls and puts v.t The Black-Scholes formula tor Europe IS' . ,.. ~.(d) ., -rrN(-d )-Se·· 'Jr - 1 C=Se-\'rN(d .)-Ke-rrN(d 2) and p=: Ke 2 ' H3 I Finance A Practical Guide To Quantilative Finance lnlerviews I 2 Jn(S K)+ (r~ 12)r d - ln(Se-yr I K)+ (r + a 12)r - ___: _ I ___. . .:. --...:_ ....,..;.y+ _a _ ~_ 1 where a-h - - Under the ri sk-neutral probability measure, the drift of stock price becomes the _risk-free interest rate r(t) : dS =r(t)Sdt + aSdW(t ). Risk-neutral measure allows the optiOn to be priced as the di scounted value of its expected payoff wi th the risk-free interest rate: a$ _ ln(S I K ) +(r- y -a 2 !2)r -d _ 1 d2 r - ' a-vr: avr V(t) = E[ e- j' ''")<!" V (T) S(t)]. 0,; t ,; T, where V (T) is the payotT at maturity T. N(x) is the cdf of the standard nonnal distribution and N '(x) is the pdf of the standard normal di stribution: N(x)= [, ~ e->'212 dy and N '(x) = -v2~ ~ e-x 212 . When r is constant, the formula can be further simplified as V(t) = e-rr E [V(T)\S(t)] · v 2ff r c_tll~undcrlyl_f2g asset js a futures contruct then yield 1 foreign currency, then yield y =,.,,where . - -- 'i Under risk-neutral probabilities, dS = rSdt +aSdW(t). Applying Ito's lemma, we get y ::- r. If the underlying asset is a is the foreign .risk:free interest rate. - d(ln(S)) = (r - 2 a 2 I 2)dt + adW(t) => lnST- N(ln S + (r - a /2)r,0' f) · 2 2 So Sr = se<r-u 12lr+q..fic, where e _ N(O, t). For a European option, we have A . What are the assumptions behind the Black-Scholes formula? (r-q7/2}r+a..fic - K V(T) Solution: The original Black-Scholes formula for European calls and puts consists of the equations c=SN(d,)-Ke-rrN(d2 ) and p= Ke- rr N(-d )-SN(-d, ), which require the 1 followjng assumptions: I . The stock pays no divideods. [0,. ) l ( "' ={ Se 0, , . 2 K => £ > ln(K I S)-(r -a / 2)r =- d 2 and a~ v E[V(T) IS)= £[ max(S7. - K ,O) IS)= [ 3. The stock price follows a geometric Brownian motion with constant drift I' and volatilityo-: dS=pSdt + aSdW(t ). ·../ = Serr r: & 1 -~ e .J 6. There arc no risk-ti·ec arbitrage opportunities. v ~ow can ym~ dcr~ vc the Black-Sl:holcs formula for a Eu ropean call on a non-dividend pay •ng stock usmg nsk-neutral probability measure? Solwion: The I3lack-Scholcs formula I' stock is · Let i = e - a .Jr , then d £ = d i , £ v 5. All securities arc perfectly divisible. · fully E or a uropean call on a non-dividend pay•ng Se'r fl d 2 ( Se <r-~ 12)r+a..fic K) ~ -(c-!ia)" /2 d2 · ! here are no transaction costs or taxes; the proceeds of short selling can be mvested. 8 'f Se(r-a212)r..,a!ft > K 1 otherwise se<r-o·t2>r+u..fic > 2. The risk-free interest rate is constant and known. \ / 4 ' 1 e- (-:·..fiq/ 12dc =Serr lr~l -:]'2; dc - K - [ _ 1_ l e-'212 de J2; l -c 12d£ r;:::-- e Jl ...;2tr =-dl :::=:> 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-q2 12)T+u .fi'T'&- K ) and II' 2 Vf=lnK, E= .!.a2) au+]_ a J fiu =0. x=y+(r-~a'}'= Ins+ (r -~ "')f Finally, let of- OT + the eq uation becomes - and r=O, Sr =eY'. 2 6 rr Th e BIack -SchoIes- Merton d.Juerential equation Ler X =lf 2 =~BV and a v =av rav '~==av(J_avJ=.:_!_av +J_ av (av) =.:.!.av +-1 o2V For European calls, the boundary condition is u0 (Sr) =max (S,.- K,O). &1 2 e- cl/2 d E . tl the same as the equation for Now, it's clear that the equation for u(S, r) IS exac Y _, A'(d. ) V(S ) _,r u(S r)- SN(d)- Ke n 2 E[V(T) Is] in question B. Hence, we have ,I =e ' I as well. So the original equation becomes a heat/di f:ft s· . ou I 2 0 u r:or heat 1 •on eq uat1on- =-a -r · or 2 . 011 l l (')- u equatiOn-= -a or 2 ax2 ' where · u == u(x, r ) ·ts a f unction of time r and space van·able x· 2 ax l with boundary condition u(x,O) == uc,(.r). the solution is . . ent rice at $1 that pays no dividend. D. Assume zero 1nterest rate and a stock wtth curr . p an exercise the option and When the price hits level $H ( H > 1) for the fi(S\ ttme you c receive $1. What is this option worth to you today? solve the problem by assuming that Solution: First let's use a brute-force approach to . der rJ·sk-ncutral measure: · B wn·an motton un 1 the stock price follows a geometnc ro d(ln S) =- -+ aldt +aJW(f). dS=rSdt+aSdW(I). Since r=O, dS==aSdW(t)~ • When 1 = 0, we have S0 ::: 1==;. ln(S0 ) == 0. u(x,r)==& fun(IJI)exp( (X - 1f1)20 7 2,rra 2a 2 r ) 1/f. J l 7 ft TI'~ log is token to ~Oil\ ~rt the !,tComctri [3 · . . . . · - {- f rs used 10 com~:n th ~ cq t. :c rownran lllOiron to an anthmt'lic Brown •an mot1on; r - . ~ ua ron 1rom a backwa d · · d't on at r 0 (the boundary,..,. d"t· r cquatron to a fornard equation with initral con ' 1 wn I lOll at I =- T ::::> 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 -<t:. J as the negative boundary for stopping time), we have Pexp(ln H)+ (1- P)exp(-oo) = Px H ==I=> 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 1t1on<; :.re 1 (CIJ o and /(// 1 1 U · 0 I . ~· h H tS 1' 0 = p >. H • ( l - ,. I ' u- s -I ..j I' "' · I I II , !ttn~ t •e martmgalc. the probabilily that it will ever reac es you derive the delta? d" "dend paving stock has a cl~an 11 a non- tVt , • k b . tr ,i.ltlfl!' Solution: The delta of a European. ca. onthough. many make the Jntsta e Y ~.: c . expresston: 6 = N( d 1). • For the denvatlon.· 1.:19 148 Finance A Practical Guide To Quantitative Finance Interviews N(d1) and N(d2 ) as constants in the call pricing fonnula c =SN ( d 1 ) - Ke-' r N(d~) arKJ simply taking the partial derivative on S to yield N (d 1 ). The derivation step is actual~· more complex than that since both N(d1) and N(c/2 ) are functions of S through dl and d 2 . So thecorrectpartialderivativeis :;=N(d1 )+Sx ~N(d1 ) - Ke-rr ~N(d1 ) . 0 Take the partial derivative with respect to S for N(d1) and N(d j_ N(d 1) = N '(d1)~d1 = - 1- as & as e-i/1212 x l sa.[; = 2 l S cr .J?:;; e- rl1: i2 ea../rd1e-c 2 rt2 .. •• • ... •• 1 I sa..J2;; 0.6 j .19 dj -·-·-·-·-·-·-·---·-·-·-·-·- ·- ·- ·- ·-.::· 0.5 ~ ' ... I ' •• / Hence, the B. What is your estimate of the delta of an at-thc-rnoney call on a stock without dividend? What wil l happen to delta as the at-the-money option approaches maturity date? Solution: For an at-the-money European call, the stock price equals the strike price;. S 1-' d (r + cr~ /2)r r cr r . F. re =n.::o 1 = ..r;. -= (-+-)vr>O and 6 =N(d ) > 0.5. As shown lO •Jgu 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 << K ), approaches 0 an.d the shorter the maturity, the faster the delta approachesO. 9 d. J - uJ"; => N'(d, ) = ~(/' 11: \"(/) iJd 1 _Od1 . K I , , ' ' ·-- oS ISO oS I .• I ,: 1 t. > 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 or 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 . ( "s negattvc. As shown in Figure 6.4. when N d2)-:::. 0 and V '(d ) _ · ' - 0. Hence. 0 ~ 0· Wh en S>>K, N(d1 )~I and 154 \ -15. ,' 04 1 75 \"•. I ro (.? ···\ -10 I A. When will a European option have positive theta? Soluli?n: For American options as well as European calls on non-dividend paying a:isds, ~heta IS always negative. But for deep in-the-money European puts. their valuts may mcrcase as t approaches T if all other factors remain the same. so they may haw positive theta. A put option on a non-dividend paying asset has e= 'ir)O' + rKe_,., N(- d2). If the SN 2 r put option is deep in-the-money ( S << K ), then N ' ( d1 ) ~ 0 and N ( - dl ) ~ l. lienee. ISS Finance A Practical Guide To Quantitative Finance ln!erviews 0-:::: rKe-'' > 0. That 's also the reason why it can be optimal to exercise a deep in-themoney American put before maturity. smile for the Black-Scholes pricing model? For deep in-the-money European call options with high dividend yield. the thela can be positive as well. If a call option with high dividend yield is deep in-the-money ( 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 <7 s~ - u dld2 . 2oc -- e x p(-d2 12) -d,d1 -oa ~ a a 2 1 . ne u Is always positive. For most out·of-the-mo Y call options. both d, and d7 art: .. , S dd > 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 f<lmliJar wnh the construction and payoff of basic option-based '.'·~.dtng stratcg.H~s-co,·cT~d call. protective put, bull/bear spread, butterfly spre-ad. stradd le. etc J·urthl:mlorc it·,. · ·· ·ou · • . ou are upp1ymg for a derivatives-related pos1t10n. Y· It I o ~.:.alcuktl.:: the d~\ tJvcs r , · 1 · · d f ·t · - ~:{lUI~~ lle LctbOJ7. in1egral mle, a fonnula for differentiating a e 10' t int~gml "ho~< lint its 1 • :- .m~ uncttons olthe differential variable: I ·o r"~'f(···,. -) - 1 , • oh ~ t"t: ,, , ( ·-)d.r •: ?- dx -F { (bt ; ) . .:)- - /(a(:),.:)~ f.' • (' . 158 ~ ~ Straddle Explain what a straddle is and when you want to purchase a straddle. .. . bo h . II option and a put option with Solwion: A straddle includes long posttiOns 10 1 a ca k Th ayoff of a long the same strike price K and maturity date Ton the same stoc · to~kp rice moves. In straddle is I Sr - K I. So a straddle may be used to bet on large s p I "J't , Jf an . . fi0 r making bets on vo att I ~ . ~racttcc, a straddle is also used as a tradmg strate.gy ld b much higher than the Investor believes that the realized (future) volahhty shou e t , ddle for ~xample, ·•mplted · volatility of call and put opttons, . · he or shc Wt'll Purchasc as ra A Practical Guide To Quantitative Finance Interviews Finance 12 the value of an at-the-money call or put is almost a linear function of volatility. If the investor purchases an at-the-money straddle, both the call and the put options have the price c:::::; p : : :; 0.4a,S.Jr, where a, is the implied vo latility. lf the reahzed volatility and the stock price S is close to K, 6 is extremely volatile and small changes in the stock price cause very large changes in 6 . In these cases, it is practically impossible to hedge a cash-or-nothing call option by delta hedging. ar >a,, 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:-<planation is that both Jn S1 and In S2 follow nom1al distributions. so In f =In S2 -In Sl follows a nonnal distribution as well and 1 follows a lognormal distribution. More rigorously, we can apply the Ito's lemma to I= s2: sl rv _ -s~ of =J_ ci.f _ 2S2 elf rl 1 _, ,wl s::. 'cs s 'as 2- s3}as 2 = 0• aSoS =-s2 1 !, df = _ 2 1 , dS, + :, dS, + s2 d , i:;;,( 2 1 dS, )' + ±:;;,( s2 s s I I sl I 1 dS, )' + ~~~' dS,dS, I You are constructing a simple portfolio using two stocks A and B. Both have the same expected return of 12%. The standard deviation of A's return is 20% and the ~tandard deviation of B's return is 30%; the correlation of their returns is 50%. How wiJJ you allocate your investment between these two stocks to minimize the risk of you r portfolio? s J s l t, I =(,u1- f.'l + al2- pala2) fdt - a I. fdW1.1 +a2fiU~Aw, l = (P2- f.JI + a ,Z - pa,a!)fdt + )al2- 2pa a + 1 I To make s and Portfolio optimization -p~ S t-a~ SdH~.J +112 S2 dt +a'l-idW 2 + a 2-l.dt- pa a S2 dt - f = S 2 S1 a martingale set ' _ fl1 •.I s~·. , with undedying asset price ~1 x fiaW l · 2 t ,.l [S ] =0 and we have E ___!_:3_ =-S1 • s,,l s. easure. The value of the exchange option using Sl as the numeraire is c. == i:[max[ST.l _ · 2 s I /-11 + <7, - pa1a2 s'.2 is a martingale under the new tn JlJ . . . I, 0 . wh1ch ts JUSt the value of a call opuon s = sl "k . s ' strr e pnce K =1. Besides option pricing problems, a variety of other quantitative finance problems are tested in quantitative interviews as welL Many of these problems tend to be positionspecific. For example, if you are applying for a risk management job, prepare to answer questions about VaR; for fixed-income jobs, get ready to answer questions about interest rate models. As 1 explained in Chapter I, it always helps if you grasp the basic knowledge before the interview. In this section, we use several examples to show some typical interview problems. Solution: Portfolio optimization has always been a crucial topic for investment management firms. Harry Markowitz's mean-variance portfolio theory is by far the most well-known and well-studied portfolio optjmization model. The essence of the meanvariance portfolio theory assumes that investors prefer (l) higher expected rct11ms for a given level of standard deviation/variance and (2) lower standard deviations/variances for a given level of expected return. Portfolios that provide the minimum standard deviation for a given expected return arc termed efficient portfolios. The expected return and the variance of a portfolio with N assets can be expressed as J.lp::: Wlfll + W2J.i2 + ... + WNflN N 2 1 var(r,) =""a~w ~ I I +""a ~ I) w w1 = w I . te l Interest rate r = 0 and volatilit)' I ' C.,. =Ss2- N(dI ) - N(d~ ) , where I of the exchange option ::: WT fJ Lw ; ... / where wi' 'Vi= I, ... , N, is the weight of the i-th asset in the portfolio; P,, 't::li = I,· ... N, is the expected return of the i-th asset; cr,2 is the variance of i·th usset's return; a'J = Ptj cr.a is the covariance of the returns of the i-th and the j-th assets and P" is their correlation; w is an N x 1 column vector of w, 's; J.1 is an N xI column vector of Jt, 's; L is the covariance matrix of the returns of N assets, an N x N matrix. · of . . . SJnce the optimal portfolio mimm1zes the vanancc of tf lC 1·eturn. for a. given. level . . . can be fiormu 1ated as the followmuo optllllll.aUon expected return, the efficient portfolio I problem: j Finance A Practical Guide To Quantitalive Finance Interviews min wrLw ,. ". 1 1. ., 1 w p=f.i" , w e= i , where e is an N x 1 vector w)th all elements equal to 1 13 · For this specific problem, the expected returns are 12% for both stocks. So J.l, ·1s a1wavs 12% no matter what w,.. and wH ( w..~ + W 11 =l) are. The variance of the portfolio is • var(rl' ) =a~w~ + a~w! + 2pA.naAO'HwAwH --alw2 A A + aH2(1 -wA )2 + 2P.. . a,,a wA( I-wA) 18 11 Taking the derivative of var(r,) with respect to wA and setting it to zero, we have ovar(r ) ':l..., " =2a:,wA- 2a~(l -w,.~)+2pA ' Ha..,aH(I-wA )-2pA.8 a,..... w =0 Av H A U\1 A l ... a , - p :1.11 O'a .I H =:> w _ _ 0.09-0.5x0.2x0.3 6 a ~- 2P,,./Ia,.: a/l+a;- 0.04-2x0.5 x 0.2x0.3+0.09 =7. So we should invest 617 of the money in stock A and J/7 in stock B. Value at risk Briefly expJain what VaR is. What is I . . the risk of derivatives? t le potenttal drawback of usmg VaR to measure Solwion: Value at Risk (VaR) d 1 two important aspects of risk an s ress test--or more general scenario analysis--a~ V R. management In the F: . l R' k AA d'b k II a IS defined as the followin . y AR . · . mancra 1s !"''anuger Han oo . 1 that there is a low, pre-specifieJ· b b. ~ the maximum loss over a target horizon such G. pro a dlty that the actual loss will be larger. tven a confidence level a e (0 J) h f ' · t e VaR can be implicitly defined as a = 1,.,,(xf(x)dx, where x is the dollar fi . . .. . A . pro It Ooss) and f(x) IS tts probabilrty dcilStty . unctton. In practice, a is often set to 95o/,0 l o . • • 1n financial ri sk managcml:nt . , • . or 9.9Yo. VaR Is an extremely popular ch01Cc.: 5tnce It summ 'trtZ" tJ • k to a stngle . < es te ns dollar number. u The optimal weights have closed 11 r.o I . rm so Ut1on I w• "' . u: . e + yr 1p , where ..< (·. - Jl,. 8 == _ _....._ D 8- . . ,--! . l-1 • D . - ,. .. J.l. (_ :::. p 'l IJ.J > 0, D == AC- 8 1 Fmancial Risk Manu"er Handb k b . f ·· " (I(; Y Philr J .· · aspects o n,~ m:ut;•gcm~:nt. A classic book f, v'PPe. Ollon IS a comprehensive book covering diiTcrent or aRtS Value at Ntsk, ' also by Philippe Jorion. r= 164 u. f - 8 Mathematically, it is simply the (negative) first or fifth percentile of the profit distribution. As a percentile-based measure on the profit distribution, VaR does not depend on the shape of the tails before (and after) probability J-a, so it does not describe the loss on the left tail. When the profit/loss distribution is far from a normal distribution, as in the cases of many derivatives, the tail portion has a large impact on the risk, and VaR often does not reflect the real risk. 15 For example, let's consider a short position in a credit default swap. The underlying asset is bond A with a $1M notional value. Further assume that A has a 3% default probability and the loss given default js 100% (no recovery). Clearly we are facing the credit risk of bond A. Yet if we use 95% confidence level, VaR(A) =0 since the probability of default is less than 5%. Furtheonore, VaR is not sub-additive and is not a coherent measure of risk , which means that when we combine two positions A and B to fonn a portfolio C. we do not always have VaR(C) ~ VaR(A) + VaR(B). For example, if we add a short position in a credit default swap on bond B with a $1M notional value. B also has a 3% default probability independent of A and the loss given default is I00%. Again we ha~e VaR(B) = 0. When A and B fonn a portfolio C, the probability that at least one bond wtll default becomes 1-(l-3%)(l-3%)z5.9%. So VaR(C)= $1M >VaR(A)+VaR(B). 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 ) <h. the drift rate is positive. So the VJ~Jcck !no<.ld has the desirable properly of mean-reverting towards lono-tcrm averag~ b. ~~~~~nth Wt~stant volatility. tl1<.· intcrl!st rate has positive probabilitv ofbcing negative. whtch JS undc~mable. " J Cox-! n~~rsoii-Ross model: c/R(t ) :: a (h - R(t)) ctt +a R(u) dW (I) 169 Chapter 7 Algorithms and Numerical Methods Although the percentage of time that a quant spends on programming varies with the job functi on (e.g., quant analyst/researcher versus quant developer) and firm culture, a typical quant generally devotes part of his or her time to implementing models through programming. l11erefore, programming skill test is often an inherent part of the quantitative interview. To a great extent, the programming problems asked in quantitative interviews are similar to those asked in technology interviews. Not surprisingly, many of these problems arc platform- or language-specific. Although C++ and Java still dominate the market. we've seen a growing diversification to otherprogramining languages such as Matlab. SAS. S~L~~..and R. Since there are many existing books and wehsites dedicated to technology interviews, thi s chapter will not give a comprehensive review of programming problems. Instead, it discusses some algorithm problems and numerical methods that are favorit~: topics of quantitative interviews. 7. 1. Algorithms In programming, the analysis of algorithm complexity often uses asymptotic analysis that ignores machine~dependent constants and studies the running time T(n) -the number s> f primitive operations such as addition, multiplication, and comparison-as the number o{lnputs n -... oo. 1 Three of the most important notations in algorithm complexity arc big- 0 notation, !2 notation and e notation: 0 ( g(n)) = {f (n) : there exist positive constants c and 11<1 such that 0 5 /( n) 5 c~ ( n) f(lr nu such that 0 5 c:g(n) ~ all n ;;:: n0 }. It is the asymptotic upper bound of f(n) . .O(g(n)) = { /(n): there exist positive constants c and /"(n) tiu· all n ~ n0 }. It is the asymptotic lower bound of f(n ). 0(g(n) ) = { f(n) : there exist positive constants ' •· "2· and n . sw.:h llmt c,g(n) s f(n ) s c g(n) for all n ~ 170 } . It is the asymptotic tight hound of f(n). 2 · pts in ahwrithm comph:xi tv: Bcs .tdes notations, it is also important to exp1am two concc ~ · 1 • d .. ltu:tiull IIJ Alxorithm" hy Thuma~ I I. If You want to review basic algorithms, I h1ghly rccom~~n 111 ~101 • _ all the thcorics di:)CU)o.'\cd in Connen Charles E Leiserson Ronald L. Rivest and Chflord Stem. 1 1 C~\ers ' and includes · . frequently appeanng · 10 · rn · terv1cws · 1h·IS section many' algorithms p - .. A Practical Guide To Quantitative Finance Interviews Algorithms and Numerical Methods Worst-case running tim e W(n): an upper bound on the running time for any n inputs. Average-case running time A(n): the expected running time if the n inputs are randomly selected. · ch · store the sum of i and 1· first, then extract i's value and assign mat hemat1c approa 15 10 . • · h [! 11 · it to j and fina lly assign j's value to i. The implementatiOn IS shown m t e o owmg code? ~, .. : l! For maoy algorithms, W(n) and A(n) have the same O(g(n)) . But as we will discuss i in some problems, they may well be different and their relative importance often depends on the specific problem at hand. j A problem with n inputs can often be split into a subproblems with n I b inputs in each subproblem. This paradigm is commonly called divide-and-conquer. If it takes .f(n) primitive operations to divide the pro~lem into s_uhpr<?ble~.s and to merge the soluti~ns of the subproblem$, the -running time can be expressed as a recurrence equatiOn T( 11 ) :-: t•T (nIb) ~ n ). where t J ~ l . h > I' _a~'.d I (~~)'Z. ~ :.. r( i i + j ; i - j i i - j ; { &j ) -- ;, ... n.s .. --;·~ ! I : 'I n -:<: .1 t:J - ·~ l ) ' ::> ~ lid j (~ lu vol ~ l ~ & j) s wap(int &i , Lnt v ~ ic . e( 1 l . . . ") ·tion b taking advantage of the fact An altemative so \utton uses bitWise XOR ( unc y that X 1\ X = Q and 0 " X = X: The master theorem is a valuable tool in fincliru.l, the tight bound for recurrence €) for some constant&> 0· ' ..:quatron T(n) : := aT(n l b)+f(n): If f (n)=O (flog. ~1 1~ 1 T(n ) =nlog,a). since f(n) grows slower than n 11 ~··' . If f(n ) = 0 (nlog,o log" for . . . . 11 1 some k ~ 0, T(n) ....: nhl log ' ' n) , since f (n) and nlog.., a grow at similar rates~ If - - ·. 10 f(n)=O(n t- "-: )for some constant £>0, and aj(n l b)~ cf(n) for some constant = ... &i '-..- ' : SW 'j- i i " j ; j j A i i A i; { (j i j/ ; j ; I .I ' ..... . ;· ' j n) e( - c < 1, T(n) .., 8(/(n)), since f(n) grows faster than n 10g ho . Let's use binary search to show the application of the master theorem. To find an element in an array. if the numbers in the array are sor1ed (a, ~ 0 1 ~ ... ~a,), we can usc binary search: The algorithm starts with a If a = x the search stops. If -''' ·!!' l•lllj , a., .• 1 > x, we only need to search a 1, ... >CtL 2 j· If a <x we only need to search II/ -1 ' 11I 1j S al•• ~ IJ •· · · •a,· Each time we can reduce tho numb~r of elements to search by half after making one comparison. So we have a = l, b = 2, and f(n) ( log, 1 o ) . !( n) =I:\ o n · log n and tht· bmary s~arch flas complexity 0(1ogn). =1. Unique eleme~t§.._~ , . the unique elements write some code to extract . . If you are given ~orted arr,ay. can yo~ . ll 1, J , ). J, 5, 5, 5, 9, 9, 9, 9}. the uruque from the array? For exampte, tf the array 15 • elements should be (1, 3, 5, 9J. .~ , 1 \ ~ < Whenever rra ' with elements Go~ a, ... - a,,-1· . . Solution: Let a be an n~element sorted a ) .. ·s different from sts . the sorted array' Its va 1uc I . we encounter a new element a, 10 ·ily extruct the umqut! U . this property we can eas previous element ( a, -:t a,_J ). smg . he fol lowing function: 3 . . C•+ 1s shown as t elements. One implementation tn ( T .. r . ir.t. nJ I ... ~;mr I , Hence. t·,.... <c 1 .1 ;:-; !'J T > V·ect a.r<T > m.qu~ ... t~L ..,.,ed t I vee; ' ' vec .reserve l n) ; I rescrv•-t t vec~ c r<T> "" ch J ' i J 1 l.l vec . pus h_ba c l< (a [OJ ); f or( -.l Number swap .-.= 1 ; ' • ~<n, -1 ~i 1 I l Com~aris~n and swap are tht: basic operations for many algorithms. The most arl! 10 . F thcr problem::;.. the alaorillunlt some iotplementatsons. or o This chapter uses C++ to demonstrate . mmefld. though. as · described using pseudo codes. . . . . n for swapping two .mtegers· It rs not reco Th~ following is a one~line equrvalent tunctJo m th1s problem smcc thc t~mporary variable requires additional storage space. c\ simple it lacks clarity. . . { i - =-j = ( i .. -j l - j ; I : . . n· unique and uniquc_copy. •::~rJ swap l i r t &i l 11 &Jl lgorithms forthisbasrcopcrauo · :; I should point out that C ,_ STL has genera1a 173 2 How do you swap two integers. i and j , without using additional storage space? Solwivn: ~omr:non tcd111q~tc fur swap uses a temporary variable. which unfort unately is forbidden Algorithms and Numerical Melhods A Practical Guide To Quantitative Finance lntcrvic\\:. purposes. Here let's discuss three such algoritluns: insertion sort. merge son rtnd 4uick sort. ~ vec. p~ ~ n_ t, L k(J/i' l ; c; Insertion sort: Insertion sort uses an incremental approach. Assume that we have sorted subarray A[ l, ... , i-1 ). We insert element A, into the appropriate place in A[ I, ... , i-1 ]. which yields sorted subarray A[I, ... , i]. Starting with i =I and increases i step by step to n, we will have a fully sorted array. For each ste~ the expected number of c~mparisons is .i L'f and the worst-case number of compansonsls i. So we have Horn er's algo rithm Write an algorithm to compute y= Ll '"0 +A x+ A 1 2x 2 +A ' 3X , + · · · + A,,x . Solwion: A nai"ve approach 1 1 h . ca cu ates eac component of the polynomial and adds them 1 1 1 up. w liC, takes O(n ) number of multipJjcations. We can use Horner's a!oorithm to 0 reduce the number of multi li · . P cat1ons to O(n). The algonthm expresses the original polynomial as y =((((Ax+ A )x A ) ) ) . " , _, + 11-1 x + ·· ·+ A2 x + A1 x + Ao and sequentmll: calculate B, = A," B,,_, =B,x +A • • • B _ x +A mu ltiplications. ,,_'1 ' o - 81 o· We have y = B0 with at most n A(n) = e[fi /2J =0(n 2 ) e[i> J and W(n) = i•l 2 = 0(n ). r=l } Me rge sort: Merge sort uses the divide-and-conquer paradigm. It divides the arr<~y into two subarrays each with n I 2 items and sorts each subarray. Unless the subarray is small enough (with no more than a few elements), the subarray is again divided for sorting. Finally, the sorted subarrays are merged to fonn a single sorted array. The algorithm can be expressed as the foiJowing pseudocode: mergesort(A, beginindex, endinde.x) ifbeginindex < endindex Moving average Given a large array A of len th an!>rh~r ;:un!:Y- contain in thg ~n,l can you de~elop an efficient algorithm to build ( 81. .... B, ~ NA~ 8 = ( g e n e ement movmg average of the original array 1 ~- ._ , A,_,.I+A,~o-:,+···+A,)!n,'tli=n,···,m)? Solwion: When we calculate th . • ~n reuse the previously com :t:v•ng ~verage of the next n c~nsecutive numbers. w~ subtract the first number i11 tl p _movmg average. Just multtply that average by n. have the new sum o1·v,·d· taht movmg average and then add the new numbcr.~1nd you · mg t e new su b 11 · 1 · the pseudo-code for calcul 1. 0 , _m Y Yle ds the new moving average. Here JS a Ill.-:- t1lc movJng average: S== A[IJ + ... + A[n]; B[n) =S/n; for (i=·n l- 1 tom) { s- S - . - A(J~n] + Afi]; B[i) == S/n; } Sorting algorithm . 1· cxp alll three sort ing al . I anal) tc: th~ complexit , f h . gont uns to sort n distinct values A" .. -~ A, and · ) o eac algonthm? Solution: Soning is a fu d 174 pmgrams. s~ a merge 1 <- mergesort(A, begin index, centerindex) merge2 <- mergesort(A, centerindex + I, endindex) merge( merge I, merge2) The merge of two sorted arrays with n/2 elements each into one array ~ak\,;.·. (·)(nl primitive operations. The running time T(n) follows the following recursive lunctwn: T(n)={2T(n/2)+0(n), 1, ~ n>I _ if n =1 . . a = 2· h -- 2· and ·/"(IJ) =0Uz). we have A.pplymg the master theorem to T(n) wtth /(n)==E>(n 10gba log0 So T(n)=0(nlogn). For merge sort. A(n) and If('1) .m: the n). ~me its T(n). C'ould you 111Cllly then centerindex - (beginindex + endindex)/2 • a~ental pr?cess tba.t is direct)v or indirectly implemented ill vanet\ of sortrng al . h "' t · gont ms have hcen developed for differcn 11 . . - hod It choo~es ont· df the . h . Tho "JC'r rt.mts Qurcksort: Quicksort is another recurs1ve sorting met · I thcr values I 0 I e ements, A, , from the sequence and compares a Wit 1t. s - .. . . . _ e clements larger !ban .I an: smaller than A are put in a subarrav to the left of A,· t1105 . , . • . . h •n repeated on both subarray:. Put m a subarray to the right of A, . The algonthm IS t e (and any subarrays from them) until all values are sorted. 17S A Practical Guide To Quantitative Finance Interviews Algorithms and Numerical Methods ln the worst case, quicksort requires the same number of comparisons as the insertion sort. For example, if we always choose the first element in the array (subarray} and compare all other elements with it, the worst case happens when A" .. ·, A, are already sorted. In such cases, one of the subarray is empty and the other has n- 1 element. Each step on Iy reduces the subarra y size by one. Hence, W (n) = 0 ( ti) =0( n 2 ). To estimate the average-case running time, let's assume that the initial ordering js random so that each comparison is likely to be any pair of elements chosen from A1 , ···,A,.. If we suspect that the original sequence of elements has a certain pattern, we can always randomly p\..'rmute the Sl!quence first with complexity 0 (n) a~_explained illl t~e nl!x't P!ohlcm. J...,et AP and A,, be the pth and qth element ( 1~ p < q ~ n ) in the final Aq. The probability that A A,, js compared is the probability that A, is compared with AP before A,,..,..... or is compared with either Ap or A (otherwise /i and A are separated i.nto sorted array. There ar~ q- p + 1 numbers between and A P and , 1 .-1•( 1 </ ' f' " different subarrays and wilt not be compared), which happens with probability 2 P(p, q) - - -- (you can again use the symmetry argument to derive this probablity}. q - p+ I The total expected number of comparison is A(n} = LL P(p, q) = LL _2 + 1~ 11 q-1 1(= 2 , .... = 0(nlgn). II 11-l ( lj-1 , .... q p ) Although theor~t~cally, quick~rt can be slower than merge s<_?.rt if! the worst ca~ i~ is often as fast as, tt· not taster than. merge so11. Random permutation A. If you have a random number generator that can generate random numbers from eithl!r di~crctc or continuous uniform distributions. how do you shuffle a deck of 52 caro~ ~o that C\'~ry pennmation is equally likely? Sol~ilivn: A simple algorithm to pl!rmute n elements is random permutation by sorting. II assJgns a random ~umber to each card and then sorts the cards in order of their assigned randlllll nut~\bers. Ry. symmetry, cwry possible order (out of n! possible ordered sc::quc n~.:\.·s) 1 'i equally hkely. The complexity is detennincd by the sorting step, so the If "~. u~ _the. conu~ uous unit(1rm Ji:.tribution, tht:oretica llv any two random numbers havt: zero rrohilhlllt) of bcmg C:lfU=ll. • J running time is 0(n log n). For a sma II n, such as n =52 in a deck of C<Jrtls..ththe . . t ble For large n we may want to use a faster algon m complextty E>(n logn) tS accep a . 1 A[,J] ... Afn) the Knuth shuffie uses the known as the Knuth shuffie. For n e ement.s ' , t ' following loop to generate a random pennutation: for (i=l ton) swap(A[i], A[Random~._n~ . . . . . . - - .. be from the discrete uniform distnbutlOn betv.·een where Random(L n) 1s a random ~~ -ri and n. -· I th . first l . f E>(n) and an intuitive interpretatiOn. n l: . The Knuth shuffle has a camp exity o . . fb . h sen as the first card sinl;c the d h al probability o emg c 0 . step, each of the n car s as equ . niform distribution between l and n; m ~1le card number is chosen from the dtscrete u d nts has equal probability of ht:mg 1 second step each of the remaining n - 1 car s e e~e h ordered sequence has I In! chosen as second card; and so on. So natura y eac probability. the The characters in the file can be read B. You have a file consisting of characters. H do you pick a character so that f h file ow 1 unknown. 1 ·s sequentially, but the length o t e b bTt of being chosen? 11 every character in the file has equal pro a y .. . md character. we . h racter If there I S a sec( d Solution: Let's start with pickmg the ~.rst c a and ·replace the pick with the_ secon keep the first characte r with probabJl~ty 1 ~ d haracter we keep the pick (trom the character with probability 112. If there IS a t tr cl the 'pick with the third character .l 1.ty 2/3 and rep ace 1 other b first two characters) with proba l . . 0 until the final character. n with probability 1/3. The same process _Is coftnunu~. llave scanned n characters and tht: h . pJck a er we words let C be the character t at '"e n h bah1'1"1tV ' " . .. _ and t c pro • T of keeping the ptck IS I (n+ l)th character exists, the probabl It)' n+ . , . . . I ·tion. \VI: ~an ~•tstly . S -I= . U<-ifl" stmple muuc h tcr I "' 1:> I c arac of switching to the (n + 1)11 n+ r 'f rc are 111 characters. 1 bTt of being chosen t tlc prove that each character has 1I m proba 1 1 y I f'i Search algorithm . . d the maximum of n numtX b 0 th the tmmmum an A. Develop an algorithm to find ., · · ons · idcnllh' usmg no more than 3n/2 compans · . , . .. 1 compuns~n:, to . . :, f numbers. tt takes n . kc~ at most Jn/S~lution: f or ru1 unsorted array .0 of the array Howe~rer, •!_~~c- separate th~ euhcr the minimum or the maxJmU . . um and the ma~tmum . l!er one in group comparisons to identifY bo.!!!.. the truntmt' J·n each pair and put the 5013 ~ . - compare the elemen s e•cments to n/2 pairs, l77 ':n A Practical Guide To Quantitative Finance Interviews Algorithms and Numerical Methods < x < Ak+,,J and then we search left along the row k + 1 A and the larger one in group B. This step takes n / 2 comparisons. Since the minimum of the whole array must be in group A and the maximum must be in group B, we only need to find the minimum in A and the maximum in 8, either of \.Vhich takes n 12 - 1 comparisons. So the total number of comparisons is at most 3n/2. 5 the grid) or a k that makes B. You are given an array of numbers. From the beginning of the array to some position, all elements are zero~ after that position, all elements are nonzero. If you don't know the size of the array, how do you find the position of the first nonzero element? Fibonacci numbers Consider the following C++ program for producing Fibonaccj numbers: A L.J A towards A trom t•l ,J k•'·' ··. Using this algorithm, the search takes at most 2n steps. So its complexity is O(n). r. int fiLi) nacci ' i nt n) So!urion: We can start with the 1st element; if it is zero, we check the 2nd element; if the 2nd element is zero, we check the 4th element. .. The process is repeated until the itb 1 step when the 2 /h element is nonzero. Then we check the ~~th zero, the search range is limited to the elements between the 2 2' +2 1-1 i f (n element. If it is e ...... <= V) .. ••-1 L . 0i r ,__ ~' 1; retu . iibonacci(n - l}tFibonacc J n- 2'. .. 0 th element and 2 the 2' th element; otherwise the search range is limited to the elements between the 2' ..:..2' I 1 1 2 - th element and the rh element. .. Each time, we cut the range by half. This 2 method is basically a binary search. lf the first nonzero element is at position n, the algorithm complexity is 0(1og n). ute Fibonacci(n). how long will it take some lat:ge n, it .takes I00 seconds to comp d? Is this algorithm efficient? How to compute F1bonacct(n+ l ), to the nearest secon · would you calculate Fibonacci numbers? . . . efficient recursive method to calcu 1ate Solution: This C++ functiOn uses a rather ~ d . the following recurrence: Fibonacci numbers. Fibonacci nwnbers are de Jne as l [f for Fo:; 0, F; = 1, Fn = Fn-1+ F,_2, Vn ~ 2 C. You have a square grid of numbers. The numbers in each row increase from left to right. T~e numbers in each column increase from top to bottom. Design an algorithm to find a g1ven number from the grid. What is the complexity of your algorithm? F, Solution: Let A be an n x n matrix representing the grid of numbers and x be the number we want to find in the grid. Begin the search with the last column from top to b<2!.!2.!U: A,_ , ... ·, A..... If the number is found, then stop the search. If A,, .• < x. x is not in the grid using induction. From the function, it is clear that T(O) =1, T(J) =1, T(n) = T(n -I)+ T(n- 2) + 1. and the search stops as well. If A,... < x < A.. s... • then we know that all the numbers in rows 1,·.. · .i are less than x ;nd are eliminated as wcJI.0 Then we search the (i + l)th row from right to left. If the number is found in the (i + t)rh row, the search stops. rr '• , a > x, x is not in the grid since all the number in rows ; + 1 and above are 1arger than . S ~ o the running time is a propertJ ona n T(n +I) ~ large n, (l-J5) ~ 0, so T( ) n x. If A , ~ x > tl,.,_, . we eliminate all the numbers in colunms j + J, .. ·,n. Then we can search along column from A,.,_, towards A,,_, until we find x (or x does not exist in : ~hght adjust~ent needs to be made ifn is add. but the upper bound Jn/2 still applies. 1 can he 0, which means x < .4, . . in which case we can search the first row from right to left. . (l + has closed-formed solutlOn F,, == .JS) - 1- "5 2., J5 II ( {;)" . which can be easily proven . bers as wdl. For a ~ Fibonacci num · · f 1 to a sequence o J5 + 1. c [f it takes I 00 seconds 2 Fibonacci(n), the time to compute Fibonacci(n.... J) · IS w comput JS+! -16., T(n + l):::--T(Il)- 1 - scconds.7 7 rp "" ..[s + 1 is called the golden ratio. 2 178 ( 179 a Algorithms and Numerical Methods The recursive algorithm has exponential complexity A Practical Guide To Quantitative Finance Interviews e((~ JJ + 1 which is surely A more efficient approach uses the divide-and-conquer paradigm. Let's define I T(i) = L,A[x] and T(O) = 0, then V(i,j) = T(j)- T(i- 1), V'l::;; i::;; j::;; n . Clearly for inefficient. The reason is that it fails to eOective)y use the information from Fibonacci numbers with smaller n in the Fibonacci number sequence. If we compute F , F;. ···,F, 0 in sequence using 1he definition, the running time has complexity G(n). xcl . . . • V(.ILl.}. ·IS maXJ . ·mized ·~ So fixed j, when T(i -1) IS _mmi!?Ized! . the maximum 2.- .end.mg a t j . ·s) v·IYI:ll<. -- T(J.)- Tmon where Tffiltl. = min(T(l),- .. , T(J -I)). If• we 0( keep) subarray An algorithm called recursive squaring can further reduce the complexity to 8(1ogn). track of and update Vrna.\ and Tmin as J. increases, we can develop the followtng algorithm: Since [F.·~• F,, F.]=[1 1] , we can show that I]"using induction. Let A= [I 0I], we can agatn· app1y he d..de- F,, ]==[' ']x[ F,, F,,_,] and [F2 F,,_, I 0 F,,_, F;,_2 F; f"o [ F,,. , F,, ] =- [' ~ ~~ I 0 I 0 t l =JA'' 11 l xA 1112 T = A[.IJ·' Vma.\: = A[l]·' Tmu\. = min(O,T) { T =T + A[j]; If T - Tmin > Vmax then Vmas = T - Tmin ; ' If T < Tmin, then Tmin = T; } Return V . ; Maximum contiguous subarray Suppose you have a one-dimensional array A with length n that contains both positive and negative numbers. Design an algorithm to find the maximum sum of any contiguous "'ax . C++ function The following is a correspon dmg given an array and its length: j !1 1 maxS uba r r~yC~ ;~ uclc AI] , en , that returns v max . ; 1 •~ &_ , .; .. -· . · d · and indtces 1 an J 5j) subarray A[i,j] of A: V(i,j)-:: IA[xJ, 15.i$j5.n. C1oubll? T - A t 0 L .'Cwt Solution: Almost all trading systems need such an algorithm to calculate maximum run- dout:..leo Tm.1.. n up or maxi mum drawdown of either rea l trading books or simulated strategies. Therefore this is a favorite algorithm question of interviewers, especially interviewers at hedge fu!lds and trading desks. -- t· r ( l :. k= l; --~ wh~n Vmax=A. I 0 ] ; = rn-;~'0 •·' ' · 0 ' k< Jen ; 'f ); -tl:) T+ =A [ k ] ; The most apparent algorithm is an 0(17 !) algorithm that sequentially calculates the V (i, j) ·s lrom scratch usiog the following equations: V(i, i ) = A[i] u ~ it 1 T - Tr~ n I > Vma>o { IJr:i• .)( ':'" - "' ~:m- ( T<Tmi n; {-:·min = 1' ; .: . ]'"' k• ; · I (k " .. JJ? '' ~k·ll ;,J ;: I j ==i and V(i,J)= LA[x] ==V{i,j-J)+A[j] when j> i. ?'•.!L u rn t.; As the V(i,j) 's are calculated, we also keep track of the maximum of V(i,j) as well as the corresponding subarray indices i andj. n For j == 2 ton tvl if n js even . The Acn-l>/2 x A(n - l) /2 x A, if n is odd multiplkation of two 2 x 2 matrices has complexity 0(1). So T(n) =T(n I 2) + 8(1). Applying the master theorem, we have T(n) = 0(1og n). and-conquer paradigm to calculate A" : A11 an Vrnax; Applying it to the following array A, J .JtJ tn i r A[ )=· l. 0 , 2 .0,- ..... . 0 I 4 • c I - 3 . CI :2 . 0 , ~' · ..- 0 , 0; - 5 . cI ( I -1. 0~ ; A Practical Guide To Quantitative finance Algorithms and Numerical Methods A[ll. , i, will give j) ; l nlcrvi~\'S Solution: The key to this problem is to realize that p e (0, \) can also be expressed as a binary number and each digit of the binary number can be simulated using a fair coin. First, we can express the probability pas binary number: v;,a,. =9, i =3 and j =6. So the subarray is [4.0,- 3.0, 2.0, 6.0]. p =O.p p 1 2 7.2. The Power of Two There are only 10 ki nd s of people in the world-those who know binary, and those who don't. If you happen to get this joke, you probably know that computers operate using the binary (base-2) number system. Instead of decimal digits 0-9, each bit (binary digit) has only two possible values: 0 and l. Binary representation of numbers gives some interesting properties that are widely explored in practice and makes it an interesting topic to test in interviews. ... p" = p 12-' + p2 2-2 +···+ p, 2-", p, e{0,1}, 'rli =I, 2, ··· , n . Then, we can start tossing the fair coin, and count heads as I and tails as 0. Let s, e {0, \} be the result of the i-th toss starting from i =I. After each toss, we compare P. with s, · If s, < p ,, we win and the coin tossing stops. If s, > p, ) we lose and the coin ~o~..;i~g stops. If s = p we continue to toss more coins. Some P values (e.g., 1/3) are mflmtc '' . the ·probabilitY• to series when' expressed as a bmary num ber ( n -4 <X> ) · I n t)1ese ca"CS ~ , reach s ~ p is 1 as i increases. If the sequence ·IS t~Jnl'te, (e.g., l/4=-0·Ol) and we reach the fin~l s~ge with s, = p,. , we lose (e.g., for 114, only the s~~uence 00 wil~ he classified as a win; all other three sequences 01, 10 and 11 arc classl!!cd as a loss}. Such a simulation will give us probability p of winning. Power of 2 How do you determine whether an integer is a power of2? Solution: Any integer x ~ 2" ( n ~ 0) has a single bit (th_~__('! + l)th bit from the right) set ~~ . I.. For example, 8 ( = 2' ) is expressed as 0· . . 01 000 . 1t is ·;is~-eas~ to-;e; .that 2" - I has all then bits from the right set to l. For example, 7 is expressed as 0·. -00111. So 2" and 2" -I do not share any common bjts. As a result, x & (x -l) = 0, where & is a bitwise AND operata(, is a simple way to ide ntify whethert he integer x is a power of2. Multiplication by 7 Give a fast way to multiply an integer by 7 without using the multip1 ication (*)operator? So/wion: (x <_,< 3)- x, where << is the bit-shift left operator. x << 3 is equivalent to x*8. Hence (x << ..>) - x is x ~~<7. 8 - . . _ Probability simulation You are. .given, a. fair. coin · a Simple · . the fa1r . com . so that your . · Can yo u des1gn game ustng probabd 1ty ot wmnmg IS p, 0 < p < 1? 9 Poisonous wine . . hd rt , Twenty hours before the party, You' ve got 1000 bottles of wmes for a blrt ay pa ). . · . ed You h b0 ttle of wme was po1son · the winery sent you an urgent message t at one bottle of \\-ine is poisonous. happen to have 10 lab mice that can be u~d to. test wh::~~~ :xactly !8 ho~rs. But before The poison is so strong that any amount will kill a mo there a sure wav that you can the death on the 18th hour, there are no other symptoms. 1s • find the poisoned bottle using the I 0 mice before the party? . . r1 .nate half of the bottles each ume, Solution: If the mice can be tested s~quenttally toe ~: Ten mice can jdentify the the problem becomes a simple bmary s.earch p~o em~cly since the symptom won't poisonous bottle in up to 1024 bottles of wmes. ?~nhortun~e c~nnot sequentially test rhc show up unti I l8 hours later and we 0 ?1Y ha~e - ?~All integers between 1 and 1000 mice. Nevertheless, the binary search tdea still app 1tes.l bottle 1000 caA be labeled a. can be expressed in 1O-bit binary format. For examp e, 3 9 8 ?' 2(i+2j+ 2 1111101000 since 1000 = 2 + 2 + - + · . fi . b.. (th . lowest bit . . le that has a 1 tn the lrst ll c. . th ., 1 in the second b1t~ ... ; and, Now let mouse 1 take a stp from every bott b . f: very ott 1e WI .. . b' • on the right); let mouse 2 take a stp rom e .th 1 10 · the lOth bit (the h1ghest Jl,. a · fimall y, let mouse I 0 take a Sl· p firom e' 'en/ ·: bottle WI the highest to the lowest btl and t at a r: - -----~--- : 1 1.1~: 1"\:, uh could be wrong if'-< causc..·s an overnow H1n1: Computer stores bm·uy numbe simulal~:d using a fair coin. ' · 182 · d f· . b rs mslea 0 dec1mal ones; each digit in a binary number can e Eighteen hours later, if we Jinc up the mtce from ·· lv back track the label of the live mouse as 0 and a dead mouse as 1. we c~n9 ~%icc arc dead and all others are poisonous bottle. For example, if the 6th, ?th, an ~ the label for the poisonous bottle alive, the line-up gives the sequence 0101100000 an 8 is 2 + 2 6 + 2 5 = 352. 183 A Practical Guide To Quantitative Finance lnlervicwl> Algorithms and Numerical Methods The esti mated price of the European call is the present value of the expected payoff, M L:max(Sr.k- K,O) 7.3 Numerical Methods - r ( T-1) ..!, k-!!,-1_ _ _ _ __ The prices of many financial instruments do not have closed-form analytjcal solutions. The valuation of these financial instruments relies on a variety of numerical methods. In this section, we di scuss the application of Monte Carlo simulation and finite difference methods. Monte Carlo simulation is a method for iteratively ~aluat~~g ~detenninistic model using ra~dorn numbe~with appropriate probabilities as inputs. For derivative pricing, it simulates a~e nUI!lber of price _paths of ~!!.f!9~_r:.ly3_a_:5sets_ with probability corresponding to the underlying stochastic process (usuall y under risk-neutral measure), calculates the discounted payoff of the derivative for each patl1, and averagcs the discounted payoffs to yield the derivative price. The validity of Monte Carlo simulation relies on the law of large nwnbers. Monte-Carlo simulation can be used to estimate derivative prices if the payoffs only depend on the final values of the underlying assets, and it can be adapted to estimate prices if the payoffs are path-dependent as well. Nevertheless, it cannoL be di r~tly applied or any other derivatives with . to American options-- early exercise options. - - A. Explain how you can use Monte Carlo simulation to price a European ca11 option? So!w;on: lf we assume that stock price follows a geometric Brownian motion, we can simulate possible stock price paths. We can split the time between 1 and T into :V · 10 T- t n1 ~ equa lly-spaced ttme steps. So 61 = - - and 1 = t + 61 xi !lor i =0 I 2 .. · N. n ~.;; N I ' ,,, ' then simulat~ the stock price paths under risk-neutral probability using equation ) _ S 11 - rr · 1 2'A_ !:J }+uEc; h , _ 1 ' , - . . ,_,e • w ere t::, s are liD random variables from standard norma di~trihution. L~t 's say that we simulate M paths and each one yields a stock price S, F where k =I, 2, .....H, at maturity date T. 11 " ·• .. · , ,_ . . 1" on. · \\e ~~~n sunpl} set ,\ .. J. But for more general options espec•allv the path d' For European O"'i e,x·mkm ones. wr wam to have small ti•nc sk ps and therefore N should be large. ' • 184 M . h £ N(" 0"2 ) (normal distribution 8 How do you generate random vanables I at o11ow r• . ·. d . 2) if your computer can only generate random vanablcs with mean J1 an vanance C7 that follow continuous uniform distribution between and 1? , . . . . t the basic knowledge of random number So/ut1on: Th1s IS a gr_eat questiOn to tes . f The solution 10 this question can generation, the foundation of Monte Carlo Simu1a 10 0 . ° Monte Carlo simulation _,.___ which can be calculated as C = e be dissected to two steps: . N(O l) from uniform random number generator 1. Generate random vanable of x' h d . . r th d and reiection met o · usmg mverse trans1orm me o :1 , d variables that follow N(p.CT·) • 2. Scale x to ).J + o-x to generate the final ran om . . ular deserves some explanations. A pop The second step is straightforward; the ftist steph . rse transform method: For any approach to generating random variables is. t edmv~ function. E..+ll.=...f(X) ), the . . bl X ·th cumulattve enstty . contmuous random van a e WI . f u·j\'- F I (U) 0 5 u 51. d the inverse functton o ·.c_::.I random variable X can be de fime as ' . . 0 < u < 1 So aov 1 . . -I ) i a one-to-one function wit 1 - - . • It ts obviOus that X= F (U s . h f0 Bowing process: continuous random variable can be generated usmg t c . . . he standard uniform dtstnbutJon. • Generate a random number ll from t b from the the random num er ) ( • Compute the value x such that u = F x as d d rm·tl distribution, om utable. For stan ar no , For tltis model to work, F - (U) must be c p · ,, solution. . has no ana1yttc,11 U -:= F(X)=[:Y_l_e_ ~,; ,ldx. The inverse functJOil .· . il'l ' of X lO U as the numcnc 'th th one·to-one mapp g Theoretically, we can come u~t e i ,t •! usin" ournerical ) j(r) -~e o solution of ordinary differential equation F'(x :::: - • - ..J2!( . flicil.!nt than h d I I Yet this approach IS less e integration method such as the Euler met 0 · the rejection method: distribution described by F. I .J2i '( ) tJte Euicr - - - - - -- - -·- · 'tial valut! r ;;; r X . " . . . . "' ' =[(:c) and a known lnt . . • ·imat~ v vaiuo : To mtegrate y = F(x) w1th first denvallvt: Y . e) to sequenuaJiy approx · be positive or negatiV method chooses a small step size h ( h can 185 Algorithms and Numerical Methods A Practical Guide To Quantitative Finance Interviews Some random variables have pdf f( x ) ' but no analyllcal . solution for F ' ' (U). In these cases, we can use a random variable with pdf g(y) and y-- C ' '(U) t o I1eJp generate random variables with pdf/( ) A . /( ) x · ~ume that Nf IS a constant such that ___!_ ~ M, "i/y. We can implement the following acceptance-rejection method: • - g(y ) - - - Sampling step: Generate random variable fro1n from standard uniform d' 'b . [ Y g(y) and a random variable v IS1f1 UtiOn 0, l). • Acceptance/rejection step: ff v < f(y) - Mg(y) , accept x = y; otherwise, repeat the sampling step. 12 An exponential random variable (g(x)- A -.<~ . l So the inverse function has analytical -,e. ) Wit l A.= I has cdf u = G(x) =1-e-... . so ut10n x =--log(! ) d d W1th exponential distribution ca b . - u an a ran om variable n e convemently simulated For standard normal distribution, f(x) = ~ e-• '2 · v21T. ' 2 f(x) ~ g(x) N - -= lj), I (I . I ~ - - vr J..{J c - ex-.1 ! < ~e-i.r-ll, '~• l '1<,g ll2 . ff - -e ff ( ~ ~1.32, , - ··- • "iiO<x<co ccan you explain a few variance redu ( . c Ion techmques to improve the efficiency of Monte Carlo simulation? Solution: Monte Carlo sirnulat' . . . Jon, m lis basJc foml .15 h ~, > ;,... ,~ : f ===_I_ M ,. • t e mean of liD random variables M ~~ ~. Smce th~ expected value of each 1': is unbiased, the 11 estimator f _ is unbiased as welL If Var(Y) Var(Y) = a 1JM h . -a and we generate liD Y, then ( ~ , w ere .\fis the number of si I . , 1~ · · mu atJons. Not surprisingly, Monte Carlo F(.r th) - F(x.. Hf(x) x h F( . ·• • x + 2h} = f(x + h) a standa1'd nonnal can be F(O) =O.S . ·· + f< x.. + h) x h, · · · . The initial value of the cdf of P(X $ x)a: [g(v)~ , A~~{ 1') dy . 186 .\1 f /(y)c{l· . .:::> F (x):::: P(.\ $ x) - Antithetic variab le: For each series of &, Is, calculate its corresponding payoff Y(c11 .. ·, E,..,) . Then reverse the sign of all c, Is and calculate the corresponding payoff Y(-&1 ,. .. , - EN). When Y(E"· .. , E.v) and Y(-c" .. ·,-C.v ) are negatively correlated, the variance is reduced. Moment matching: Specific samples of the random variable may not match the population distribution well. We can draw a large set of samples first and then rescale the samples to make the samples' moments (mean and variance are the most commonly used) match the desired population moments. Jon trol variate: If we want to price a derivative X and tbere is a c1oscly related derivative Y that has an analytical solution, we can generate a series of random numbers and use the same random sequences to price both X and Y to yield X and Y. Then X can be estimated as X+ (Y- Y). Essentially we use (Y- f) to correct the estimation error of .. ( r , n (o.ll 'iJ Yl ~ X. "" So "ve can choose M = 1.32 and u x - N(O, l) random variables and I se the acceptance-rejection method to generate sea e them to N(/-l, a ~) random variables. 11 - simulation is computationally intensive if cr is large. Thousands or even millions of simulations are often required to get the desired accuracy. Depending on the specif1c problems, a variety of methods have been applied to reduce variance. r· Importance sampling: To estimate the expected value of h(x) from distribution f(x), instead of drawing x from distribution f(x), we can draw ~istribution ~(x) and h(x)f(x) \ use Monte Carl o simulation to estimate expected value of\ g(x) . J E, ,.T)[h(x)] = h(x)f(x)dx = ~ _ [ htx)f(x)ll.l Jh(x)f(x) (x) g(x)dx- Egt.c> g(x) · g . . r. d e.. v' ... t1·- ~ ~ ~- v·· { f \f h 4 11 i • t Jp . 10 3 If (xy(x) has a smaller variance than h(x), then importance sampling can result g x) . more efficient estimator. This method is better explained using n_dec~ o~tt-o~-the-mone~. option as an example. If we directly use risk~ neutral f(S, ) as the d1stnbutl0n. most of h · t · n ariance will be the simulated paths wiU yield h(S ) = 0 and as a result l e esuma 10 v r ~·d spa•-vrl'lnter tai I tor ~''' )_ Iarge. If we introduce a distribution g(Sr) that has muc11 "" 1 er 'r ·-- .. \ . .- - ~ ~ .. · f tt~ f( .t) ,J,ill keep the more Simulated paths will have pos1ttve h~). The scah ng ac x(x) T M I. . ? I - - . . estimator unbiased, but the approach will have lower vanance. / d P(X< ~)- - ? f(y)y 11 hod using a change of measure. . . 1mponancc sampling is essentially a vanance reduct•on met 187 I A Practical Guide To Quantitative rinance Interviews Algorithms and Numerical Methods Low-discrepancy sequence: Instead of using random samples, we can generate a deterministic sequence of "random variable" that represents the distribution. Such lowdiscrepancy sequences may make the convergence rate 11M. computing power, we can easily generate millions of (x, ~) pairs to ~stimate Jr with good precision. 1,000 simulations with 1,000,000 (x, y) pomts each usmg Mat\ab to~k less than 1 minute on a laptop and gave an average estimation of 1r as 3.14\6 w11h standard deviat ion 0.001 S. D. If there is no closed-form pricing formula for an optjon, how would you estimate its delta and gamma? 0.9 Solution: As we have discussed in problem A, the prices of options with or without closed~form pricing fonn ulas can be derived using Monte Carlo simulation. The same methods can also be used to estimate delta and gamma by slightly changing the current underlying price from S to S ±oS, where oS is a small positive value. Run Monte Carlo simulation for all three starting prices S- oS, S and S + oS, we will get their corresponding option prices /(S - oS), /(S) and f(S + oS) . I ... t- ~ 0.8l .- 01 0.61 0.4 Estimated delta:!:::.= of = f(S+oS)-.f(S-oS) os 03 2os 0.2 ' Estimated gamma: r= (/(S+oS)- f(S)) -( f(S)- f(S-oS)) oS 2 + To reduce variance, it's often better to use the same random number sequences to estimate f(S- oS). f(S) and /(S + oS). 14 0 0 <"· 0.6 Q:?' 0.8 ..;. 1 X Figure 7. 1 A Monte Carlo simulation method to estimate TT E. How do you use Monte CarJo simulation to estimate n ? Solulion: Estimation of 1r is a classic example of Monte Carlo simulation. One standard ~ethod to esti~ate 1r is to randomly select points in the unit square (x and y are tndependent um form random variables between 0 and t) and detenn.ine the ratio of 2 points that are within the circle x + / ::; 1. For simplicity, we focus on the first quadrant. As shown in Figure 7. I, any points with.in the circle satisfy the equation x} + y,2 ::; 1. The percentage of the points within the circl e is proportional to its area: =Number of (x;,Y,) within x,2 + / ::; 1 114Jr 1 p Number of (x,. Y,) within the square = =4ff ::::::> ll' == 4 P · w A A A So. we g~n~rate a .large number of independent (x. y) points, estimate the ratio of the po1.nts -:vutun the crr~Je to the points in the square. and multiply the ratio by 4 to yield an estJmat1on of tt. F1gure 7.1 uses only 1000 points for illustration. With today" s 14 T h~.· method may not work well if the payoiT function is no! continuous. Finite difference method . . . t; derivative . h ular numencal techmquc or . . The finite difference method ts anot cr pop . ·matc the ,rice of a dcnvauvc: 11 1 ·~ . fal 1 1 equatiOn to cs • · 1,, We can convert t 1c Pricing. It numeri cally solves a d tueren - 0 f the underlymg secun - · · by discretizing the time and the pnce . r partial differential equation. to. · cond order non 1mea •.• , . , Black-Scholes-Mertoo equatton, a ~e . , This new equation. ~!.xprcss~::u ~:; a 6 a heat diffusion equation (as we did 111 Chap.tcr ). · t. the undcrlving secunty), . d ( f nctwn of the pncc o . . . function of r (time to matunty) an x a u . . The difference between vanous . . . I t'on for denvattvcs. d d 'tn<• th~ IS a general d1fferentta equal .. building a grid of x an ran us ': . t u ,11 cverv x and r using flmtc derivatives lies in the boundary conditions. Byl 1 · boundary conditions, we can recurs!··velv- cacuae ' difference methods. . . d"f[i ence methods? A. Can you briefly explam fimte 1 cr . L •. d in racucc. ct s . f fi ite ditTerence methods use p d , nd the Solution: There are seveml v~r:s10n ° tn h d the implicit ditlcrence metho a briefly go over the explicit difference met 0 ' 18<> 188 A Practical Guide To Quantitative !=inane~ \ntcrvi~:"~ AI gont · hms and Numerical Methods Cran.k-Nicolson method. As sho v.n ' tn . F'tgure 7.2, if we d'v'd h . . dtscrete mtervals WI.th . mcrement lH =T 1 N a . . t ' e t e range of r ' [0' T) , .Jnlo N . J dtscrcte intervals WJ.th.tncrement & - (x nd dtvtde the range of x' [x· o• X 1 ] , mto . expn::-.:,L'd as a grid ofT n- I - J - x~ )/ J , the time rand the space of " · - , · · ·. N and x J =:: , ... , .1 x can be I' conditions and equation u~+' = au~_1 + ( l-2a) u~ +au~~" we can estimate a\\ 11':'-' on the grid. The implicit difference method uses the backward difference at time au d d ' c n -or er central dtfference at x I : -Of SC 0 X ~ n+l ~ n 1J 1 I - - U1. tl} f:l f ,+1 "' ' = ' 211 1 1 ( flx ) + ,,,\ U ·-1 ' II+ 1 1 -~ anti lh\! ~---"\. Ox' V U The Cronk-Nicolson method uses the central difference at time (1. +1.. ,)12 and the XJ - second-order central difference at xJ ·• au ~ u"•' - ~t" ~ .\'.1-1 I ' or X I - I' JH X ,., 2 r ·' n (~·<l J n+l uj+l - 2u"+l (nx)~ J + u"·' ,-IJ\I - "2 o u ::::- fJxl . R If you are solving a parabolic partial diflOrcntial equation using the explicit tinitc dJITer~nce method, is it worse to have too many steps in the time dimension or too man) L/ .-> / ) X u" .J - 1 II'I XI 6:r (u" -2u" + u;-1 + u" .. , u'·' I ~ - l -- J - un:.. , steps m the space dimension? S<Jiulion: The equation for u••' in the explicit finite difiCrence method is J-1 ~ ~· =au'~_, + ( 1- 2a) u'~ +au" J J J where a::: 6J J(Ax) 2 • For the explicit finite difference j + l' method to be stable, we need to have 1- 2a > 0 => At I( /!.x )' <1 / 2· So a · mall At (i.e .. many time steps) is desirable, but a small /!.x (too many space steps) Jm\) make /(l!.x)' > 1/2 and the resu!IS unstable. In thai sense. it is worse to lw,·c too many s«r' 61 in the space dimension. In contrast, the iJnplicit difference method is stable and alwa~s convergent. r, 0 ... r~ r . Figure 7.2 Grid of 'and l'h~ ord ... r n 11 Rcomngin~ terms. • . , ·11 ' xl. o ~ r ;::; d.~ "•crcncc at time • 11· -• _ 11 " J I - u ,., - Jl 2u"J +-u"1- 1 ciu r,. and the secoml- "-(.\-.~ r (Ax)' . we can ex.pre..'is u ~I as . l' (I - ]a ) u '" au . where' a uA•jmear combination of u n,.l• u;' II • I WI I x for finite different methods explicit difference method uses the fonnrd . . <r cenlral d11 tcn:nccat ...... 1, I conJition~ u • 1 u.,• · anJ u; fur ' = 1 . . . '.u all 11 . :::: an<.lu~ I: (&f . · Besl'des. we often have boundary , .\ :, ~ o· ... · ·; · Combining the bow1dary