Download Interview questions

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Interview questions
XW
July 5, 2007
1
Brainteaser
1. A and B are having a shooting contest. Each of them have 50 bullets.
For each bullet, both A and B have 50target. After they finish shooting, the total numbers of bullets that hit the target are counted. If A
hit the target more than B, A wins. If they hit the target the same
number of times, it’s a tie. Otherwise, B wins. Apparently if A and
B both get 50 shots, they have the same probability of winning. The
question is: what is the probability of A winning if A gets 51 shots
and B gets 50 shots?
Answer: One way of seeing this is as follows: first look at what
happens after both have done 50 shots. Either A is ahead (with
probability, say p), or B is ahead (which by symmetry, is also equal
to p), or both are tied (with probability, say, q). So obviously, 2p +
q = 1. Now what are the ways A can win after 51 shots? He can win
if he’s already ahead after 50 shots (which happens with probability
p) and then the outcome of the 51st shot is irrelevant, or if he’s tied
after 50 shots and has a success on the 51st shot (which occurs with
probability q * 1/2). (If A is behind B after 50, he either stays behind
or at best ties at the 51st, and if A and B are tied at 50, then they
still stay tied if A misses his 51st shot.) Thus, the probability of A
winning is p + q/2 = 1/2. If you know some advanced probability
theory, then a simpler argument, called coupling, says that without
loss of generality, you can assume that A and B have exactly the same
hits and misses during their first 50 shots. Then A wins if and only if
he succeeds on his 51st shot, which occurs with probability 1/2. Note
that 50 isn’t special here; this works for any n and n+1.
1
2. You are blindfolded and wearing thick gloves. You are taken to a
room, on the floor of which you are told there are 100 coins, 75 of
which show tails and the remainder heads. You are asked to separate
the coins into two piles, both containing an equal number of heads.
How would you proceed?
Answer: Choose random 25 coins and flip all them.
3. Suppose 2 teams play a series of up to 7 games in which the first team
to win 4 games wins the series and then no more games are played.
Suppose that you want to bet on each individual game in such a way
that when the series ends you will be ahead by exactly 100 if your
team wins the series, or behind by exactly 100 if your team loses the
series, no matter how many games it takes. How much would you bet
on the first game?
Answer: 31.25. Constructing binomial tree. There are 8 outcomes,
each with payoff 100 or -100. Suppose the probability to win or lose
is 0.5 and discount back to the first game.
4. What is the expected time to find HTTHTH (pattern τ ) in a random
coin toss sequence.
Answer: First of all, the answer depends on the internal structure
of the pattern. Second, find the longest proper suffix (σ) of the pattern which is also a perfix of the pattern, i.e. ”‘H”’ in ”‘HTTHTH”’.
It can be proved that the expected time to find τ has the following
2
relation with that to find σ:
E[Tτ ] = E[Tσ ] + 2n
where n is the length of patten τ .
ref: [1]ross’s Stochastics Process P125 second edition, [2]a downloaded
note in refs.
5. you throw a fair coin until you get 8 heads in a row. What’s the
probability you will see 8 consecutive tails in the sequence prior to
stopping?
Answer: It is useful to take a look at the analysis in Ross’s book
page 127: Suppose now we want to compute the probability of a
given pattern, say pattern A , occurs before a second pattern, say
patern B. For instance, consider independent flips of coin that lands
on the heads with probability p, and suppose we are interested in
the probability that A=HTHT occurs before B=THTT. To find this
prabability, we will find it useful to first consider the expected additional time after a given one of these pattern occur until the other
one does. Let NB|A denote the respectivly the number of additional
flips needed for B to appear starting with A, and similarly for NA|B .
Also let NA denote the number flips until A occurs. Then
E[NB|A ] = E[additional number to THTT starting with HTHT]
= E[additional number to THTT starting with THT]
But since
ENT HT T = E[NT HT ] + E[NT HT T |T HT ]
we see that
E[NB|A ] = E[NT HT T ] − E[NT HT ]
3
But
E[NT HT T ] = E[NT ] + q −3 p−1 = q −1 + q −3 p−1
E[NT HT ] = E[NT ] + q −2 p−1 = q −1 + q −2 p−1
and so,
E[NB|A ] = q −3 p−1 − q −2 p−1
Also,
E[NA|B ] = E[NA ] = q −2 p−2 + q −1 p−1
To compute PA = P {A before B} let M = M in{NA , NB }. Then
E[NA ] = E[M ] + E[NA − M ]
= E[M ] + E[NA − M |B before A](1 − PA )
= E[M ] + E[NA|B ](1 − PA ).
Similarly
E[NB ] = E[M ] + E[NB|A ]PA
Solving these equations yields
PA =
E[NB ] + E[NA|B ] − E[NA ]
E[NB|A ] + E[NA|B ]
Return to the original question, where E[NB|A ] = E[NA|B ] and E[NA ] =
E[NB ]. PA = 0.5. What a simple result!
6. As you leave your house in the morning, you can feel the portent
of snow in the air. The weather report on the radio confirms your
suspicions. The snow begins to fall before noon-time, and falls at a
constant rate. The city sends out its first snow plow at noon which
begins removing snow at a constant rate (in cubic feet per minute.)
At 1 P.M. it has gone 2 miles. At 2 P.M. it has gone 3 miles, and is
4
still not retracing its path. At what time did it start to snow?
Answer: The snow falls at a constant rate P so that the height of
snow on ground is h = h0 + P · t. The removing capacity of snow plow
is constant Q so that its speed follows Q · dt = h · ds. Integrating this
equation yields
Z L
Z 1
Qdt
ds =
0
0 h0 + P · t
L = Q/P [ln(h0 + P ) − ln(h0 )]
Pluging L = 1, 2 into the above equation gives that the snow began
to fall at about 11:23 am.
7. Slot machine has payout rate 97%. Each time you can only put one
quantar in. What is the probability to win $1000?
Answer: Poisson distribution? play 8 hours and 4800 times?
8. You have a camel, two points AB - distance 1000 miles, 3000 liter of
water in A. Camel can carry out at one 1000 liter and need 1 liter per
mile. What is the MAX amount of water can you with camel carry
on to point B?
Answer: two spots:200 and 200+1000/3
9. There are 99 tigers and one deer stranded on the proverbial island covered in grass. All the animals are quite happy to be eating the grass
that is continually replenished, but each tiger would much rather eat
the deer. Only one tiger is permitted to eat the deer (i.e. no sharing),
but the catch is that the predatory tiger turns into a deer once it has
eaten the original deer. The question is whether the original deer gets
5
eaten or not and whether your answer woul d change for a diffenerent
number of tigers.
Answer: If there is one tiger and one deer, tiger will definitely eats
the deer. If there are two tigers, tiger will not eat the deer. Thus,
there are odd number of tiger, tiger eats; there are even nubmer of
tiger, tiger does not.
10. Cards from an ordinary deck of 52 playing cards are turned face up
one at a time. If the 1st card is an ace, or the second a deuce, or the
third a three, or ...., the thirteenth a king, or the fourteenth an ace,
and so on, we say that a match occurs. Note that we don not require
that the (13n+1)th card be any particular ace for a match to occur
but only that it be an ace. Compute the expected number of matches
that occur.
Answer: Let Ak =card k is a match, k=1,...,52 and T=total number
of matches. Then P (Ak ) = 1/13.
T =
5
X
2Ak
k=1
E[T ] = 52/13 = 4
note: here Ai and Aj are not independent events.
11. Suppose you play a game in which you pick a ball, notice its color,
and drop it back in the urn containing equal amount of red, blue and
white balls. If you pick a red ball, then you are out of the game. If
you pick a blue ball then you win $1 and you play the game again.
If you pick the white ball then you win $4 and play the game again.
What is the expected amount of money you can earn from this game?
Answer: Conditioning on the first pick yields the eq: x = 1/3(1+x)
+1/3(4+x) or equivalently, x = 5.
6
12. Given a stick of unit length. Break this in two pieces at random. Then
break the longest piece in two pieces at random. What is the probability that you can build a triangle from the three resulting pieces?
Answer: suppose the length of the short piece is x. It is obvious
that x ∈ (0.00.5). The length of one piece of the second break is y.
To form a triangle, the sum of any two piece should be larger than
the third piece.
y < 0.5, y > 0.5 − x →
x/2
1/2 − x/2
The probability is
Z
2
0
0.5
x/2
= 0.386....
1/2 − x/2
13. Consider n independent flips of a coin having prob p of landing heads.
Say that a changeover occurs whenever an outcome differs from the
one preceding it. For instance, if n=5 and the outcome is H H T H
T, the there is a total of 3 changeovers. Find the expected number of
changeovers.
Answer: For n=2, the expected number of changeover is 2p(1-p)=2(n1)p(1-p). consider n=k+1, the probability of the end flip of k flips
equal head is p so that p(1-p) is added to the expected number of
changeover. Similarly, tail also contributes to (1-p)p.
14. Suppose you have an array A containing both positive numbers and
negative numbers, design an algorithm to find the subarray from A[i]
to [j] whose sum (the sum of A(i) through A[j]) is the largest among all
7
the subarrays. There is an O(n) algorithm, but I cannot figure it out.
Answer: Kadane’s Algorithm(arr[1..n])
begin
(max, a, b) := (-INFINITY, 0, 0)
curr := 0
aa := 1
for bb := 1 to n do
curr := curr + arr[bb]
if curr > max then
(max, a, b) := (curr, aa, bb)
endif
if curr < 0 then
curr := 0
aa := bb + 1
endif
enddo
return (max, a, b)
end
15. There is a ten digit number. The number contains each of the numbers from 0 to 9 exactly once. The left most digit is divisible by one.
The two leftmost digits are divisible by two. The three leftmost digits are divisible by three, etc. (If the above is not clear, assume the
number can be displayed as d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 Then d1
is divisible by one, 10d1 + d2 is divisible by two, 100d1+10d2+d3 is
divisible by three, etc.) What is the number?
Answer: a) d(2i) is even, d(2i-1) is odd
b) d10 = 0
c) So Sum[d(i),i,1,9] is divisible by 9 =¿ ok coherent but no useful
info
d) d5 = 5
e) 10d3+d4 is div by 4 AND d3 is even =¿ d4 is 2 or 6
f) 100d6+10d7+d8 is div by 8 AND d6 is even AND d7 is odd =¿ d8
is 6 or 2
g) So d2 is 4 or 8 and d6 is 8 or 4
h) If d2 is 4 then d1 is 1 or 7 and d3 is 7 or 1
i) d1+d2+d3 is div by 3 AND d1+d2+d3+d4+d5+d6 is div by 3 =¿
8
d4+d5+d6 is div by 3
j) d4 d5 d6 is either 258 or 654
k) If d4 d5 d6 is 258 =¿ d8 = 6 =¿ d7 is 1 or 9
l) But if d4 d5 d6 is 258 =¿ d2 = 4 =¿ d7 is 9
m) But neither 1472589 or 7412589 is divisible by 7
n) So d4 d5 d6 is 654 =¿ d2 is 8 and d8 is 2 =¿ d7 is either 3 or 7
o) So we have as possibilities for d1, d3, d7 : 1,3,7, 1,9,3, 1,9,7, 3,1,7,
7,9,3, 9,1,3, 9,1,7, 9,7,3
p) But only 3816547 is divisible by 7
q) So the number is 3816547290
2
Equations
1. Heat equation:
∂u
∂ 2u
= c2 2
∂t
∂x
where the boundary condition is u(0, t) = 0, u(L, t) = 0, u(x, 0) =
f (x)
Answer: Solution of the heat equation: separation of variables. assume u(x, y) = X(x)T (t), we get
X 00 T = c2 X Ṫ
,then
X 00
Ṫ
= c2 = k
X
T
,where k is constant (in fact negtive constant). Solving c2 ṪT = k yields
2
T (t) = T0 ec kt . Since k is negtive, let k = −p2 .
X 00 + p2 X = 0
9
,then
X(x) = Acos(px) + Bsin(px)
. Apply boundary condition that X(0) = 0, X(L) = 0, we obtain that
pL = nπ,
∞
X
nπ
2 2 2
2
u(x, t) =
Bn sin( x)e−n π c t/L
l
n=0
2. Solve
dy(x + y) = dx(x − y)
Answer: let u = y(x) + x,
du = dx + (dy/dx)dx =
2x
dx
u
3. A drunken man is on a 100 meter long bridge at the 17 meter position. He has a 50% chance of staggering forward and backward one
meter per step. What is the probability he will make it to the end
of the bridge before the beginning? Can anybody solve this problem
intuitively instead of using Markov Chain and deduction? Thanks
Answer: This is a problem of random walk (Browian motion). X1 , X2 , X3 , ...
is a sequence of random variables. Xτ is where the man make to the
end or the beginning. Let p is the probability to the end. The expectation value of the final positions is equal to the initial position,
p · 100 + (1 − p) · 0 = 17
10
The mean time of the man staggering on the bridge can be obtained
as follows, Xn2 − n is a martingale, and so
E[τ ] = E[Xτ2 ] = p · 832 + (1 − p) · 172
4. A worm can crawl at a velocity c. He is attempting to cross a rubber
sheet of initial length L. One end of the sheet is fixed, the other end
is being pulled at a velocity s such that the sheet is being stretched.
How long does it take the worm to cross the sheet? What happens if
c¡s?
Answer: The worm is moving at the sum of two speeds:
x·s
dx/dt = c +
s·t+L
. Useful formula:
y 0 = 1 + y/x → y = x + x · ln x
3
Misc.
1. A Poisson process has rate λ = 1. Let N be the number of integers
k such that k is one of 0; 1; 2; : : : ; 99 and there is at least one
observation in [k; k + 2]. (So for example if the process has hits at
0.7 and 25.8 and no other hits in [0; 101], then N = 3). Find EN and
E(N2 ).
Answer: The poisson probability is
P [N (t) − N (0) = k] =
11
e−λt (λt)k
k!
. The expectation value of poisson process is λ. In any two periods,
e−2 (2)k
P [N (2) − N (0) = k] =
k!
. if k = 0,
e−2 (2)0
P [N (2) − N (0) = 0] =
= e−2
0!
.
E[N ] = 98(1 − e−2 )
???
2. How to explain the concept of risk neutral to your manager or common clients?
Answer: Risk neutral is used to describe an investor who only cares
about expected return and not the risk. A risk neutral world is one
where investors are assumed to require no extra return on average for
bearing risks. Risk aversion is the reluctance of a person to accept a
bargain with an uncertain payoff rather than another bargain with a
more certain, but possibly lower, expected payoff.
3. Why the early exercise of an American call option with a no-dividend
underlying stock is worthless?
Answer: It can be easily seen from the figure of call price vs stock
price. Call price is always above its intrisic value max(S-K,0). Consider two portfolios:(1)one American call option C plus an amount of
cash equal to Ke−rT −rt ;(2) one share stock S. Portolio (1) is always
worth more than (2) i.e., C > S − Ke−rT −rt > S − K.
4. What is efficient market, complete market? How to test them?
Answer: Here efficient means informationally efficient. There are
three forms:(1)weak-form, (2)semi-strong form and (3)strong-form.
12
(1)No excess returns can be earned by using investment strategies
based on historical share prices or other financial data. Weak-form
efficiency implies that Technical analysis techniques will not be able to
consistently produce excess returns, though some forms of fundamental analysis may still provide excess returns. (2)Share prices adjust
within an arbitrarily small but finite amount of time and in an unbiased fashion to publicly available new information, so that no excess
returns can be earned by trading on that information. (3)Share prices
reflect all information and no one can earn excess returns. To test
these, we can check whether Technical analysis, fundamental analysis
and all fund manager can make excessive return respectively.
5. How to calibrate the black-scholes model?
Answer: Volatility can be calculated by historical data or by implied
method.
6. What are the out of sample problems? How to deal with it/them?
Answer: ???
7. What is low-discrepancy sequence?
Answer: a low-discrepancy sequence is a sequence with the property that for all N, the subsequence x1, ..., xN is almost uniformly
distributed (in a sense to be made precise), and x1, ..., xN+1 is almost uniformly distributed as well.
8. You have two glass balls and a 100-story building. You would like
todetermine the lowest floor from which a glass ball will break when
dropped. What is the strategy that will minimize the worst case scenario for number of drops? What is your strategy if you have 100
glass balls?
Answer:
13
9. A rabbit sits at the bottom of a staircase with n stairs. The rabbit
can hop up only one or two stairs at a time. How many different ways
are there for the rabbit to ascend to the top of the stairs?
Answer:
10. A drunken man is on a 100 meter long bridge at the 17 meter position. He has a 50% chance of staggering forward and backward one
meter per step. What is the probability he will make it to the end of
the bridge before the beginning?
Answer:
11. Assume zero interest rate and a stock with current price $1. When
the price hits level $H for the first time you can exercise the option
and will receive $1. What is this option worth to you today?
Answer:
12. A family has two children. If one of them is a boy, what is the probability the other child is a boy?
Answer:
13. You start with one amoeba. After one minute the amoeba can die,
stay the same, split into two or split into three with equal probability.
What is the probability the amoeba population will ever die out?
Answer:
14. Suppose you have a coin with probability p of tossing heads. What
is the expected number of coin tosses to get two heads in a row?
14
Answer:
15. A banker gets off work at some random time between 6:00 pm and
7:00 pm. He walks to the subway and takes the first of two trains
that arrives. One of these travels downtown to his mother, the other
travels uptown to his girlfriend. His mother complains that she never
sees him since she has only seen him twice in the last 20 working days.
Explain this.
Answer:
16. Two people arrive at the center of town at some random time between
5:00 am and 6:00 am. They stay exactly five minutes and then leave.
What is the probability they will meet on a given day?
Answer:
17. A baker sells on average 20 cakes in one day. What is the probability
he will sell an even number of cakes on any given day?
Answer:
18. Airborne spores produce tiny mold colonies on gelatin plates in a laboratory. The many plates average 3 colonies per plate. What fraction
of plates will have exactly 3 colonies?
Answer:
19. You walk out of an airport, and the first bus you see has number 26
on it. Assume buses with all numbers up to some number N exist.
Estimate N.
Answer:
15
20. Coupons in cereal boxes are numbered 1 to 5, and a set of one each
is required for a prize. With one coupon per box, how many boxes
on average are required to make a complete set?
Answer:
21. Explain linear regression. What is the model? How do you estimate
the parameters? Prove this.
Answer:
22. Solve the following ordinary differential equations. y” + y’ + y = 1
y” + 2y’ + y = 1
Answer:
23. Graph vega for a digital option.
Answer:
24. Prove it is never optimal to exercise an American call on a nondividend paying stock.
Answer:
25. What is the martingale measure of the forward price for a nondividend- paying stock?
Answer:
26. Describe a function for which using antithetic variables in a Monte
Carlo simulation produces no advantage.
Answer:
16
27. Suppose you have two random variables, one uniformly distributed on
inter- val [3; 3] and the other standard normal. Is it possible for them
to have correlation 1 or -1? What if the first variable is T-distributed?
Answer:
28. What is the price of a swap? Choose the swap rate so the initial price
is zero. Let Vt be the price of the swap. You would like to model Vt
using Brownian motion. Would this work? Why or why not?
Answer:
29. Derive Newton’s method for finding the zero of a function.
Answer:
30. Define Brownian Motion. Suppose W N(0; 1) and t measures time.
Is the random variable Sqrt(t)*W Brownian Motion?
Answer:
31. Use a binomial tree to price a call option with strike K. Assume zero
interest rate. Use parameters S0 = 18 Su = 22 Sd = 16 K = 19.
Answer:
32. Design a C++ routine that will efficiently compute exp(x) to n terms.
Answer:
33. Design a class or classes in C++ that will model a deck of cards.
17
Answer:
34. Which pricing measure is most relevant for pricing credit derivatives,
risk- neutral or physical? Why?
Answer:
35. Give an example where Value at Risk is not subadditive.
Answer:
36. Describe a situation where Value at Risk is always subadditive.
Answer:
37. Suppose you have a string that is one unit long, and you cut it in two
places uniformly distributed. What is the probability you can make
a triangle out of the three pieces? If you instead make the second
cut on the longest piece, what is then the probability you can make
a triangle out of the pieces?
Answer:
38. Define standard Brownian motion. Compute P(W1 ¿ 0;W2 ¡ 0), where
W1 and W2 are standard Brownian motion at times 1 and 2.
Answer:
39. Prove that standard Brownian motion hits a level with probability 1.
Is this also true in higher dimensions?
Answer:
18
40. What is the distribution of the minimum of a Brownian motion? How
about a Brownian motion plus a Poisson process?
Answer:
41. How would you price a swaption today when the swap begins today?
Answer:
42. How would you price a swaption today when the swap begins in one
month?
Answer:
43. What is a Eurodollar future?
Answer:
44. What is a swaption?
Answer:
45. What is smile and skew? How do you model them?
Answer:
46. What is the advantage of HJM over regular affine models? Can you
fit the initial term structure for any affine models?
Answer:
47. Draw on one graph the Black Scholes price of a call option as a function of the stock price for two option, one with maturity 1 and the
other with maturity 2.
19
Answer:
4
C++
1. What is mutable
Answer: This keyword can only be applied to non-static and nonconst data members of a class. If a data member is declared mutable,
then it is legal to assign a value to this data member from a const
member function. For example: class X{ public: bool GetFlag() const
{ accessCount++; return flag; } private: bool flag; mutable int accessCount; };
2. What is Polymorphism
Answer: Polymorphism enables one common interface for many implementations, and for objects to act differently under different circumstances. C++ supports several kinds of static (compile-time) and
dynamic (run-time) polymorphism.
20