Junior Quantitative Trader interview questions:
Recently, I came across these questions for a Junior Trader position. Here I provide what should be my answers for any of those. I hope can be useful for anyone in the recruiting process for a similar position.
Question 1:
What has been your biggest achievement so far? please provide any details about it.
Question 2:
Compute the sum of numbers between 1 and 100 excluding all the numbers that include the digit 8.
To solve this problem we need to compute first the sum of all the numbers from one until 100, this is: $$\sum_{i=1}^{n=100}i=\frac{n(n+1)}{2}=5050$$
Now, we need to subtract to 5050 the numbers: 8, 18, 28, ..., 78, 80, 81, 82, ..., 89, 98. Notice the following pattern for numbers up to 78:
$$\sum_{i=1}^{8}\left[ 10(i-1)+8 \right]=(0*10+8)+(1*10+8)+(2*10+8)+...+(7*10+8)$$
This is equal to:
$$\sum_{i=1}^{8}\left[ 10(i-1)+8 \right]=\sum_{i=1}^{8} \left[ 10i-10+8 \right] = 10 \sum_{i=1}^{8}i - \sum_{i=1}^{8}2$$
To get the result we can use the same formula above to get the total but in this case, with $n=8$, the second part is a constant sum of $2$ eight times:
$$10 \sum_{i=1}^{8}i - \sum_{i=1}^{8}2 = 10\frac{8(8+1)}{2}-2(8)=360-16=344$$
The final section is to get the sum of 80, 81, 82, ..., 89, this is equal to:
$$\sum_{i=1}^{10}\left[ 79 + i \right]=\sum_{i=1}^{10} 79 + \sum_{i=1}^{10} i = 79(10)+\frac{10(10+1)}{2}=790+55=845$$
Finally, the over result is the follow:
$$5050-344-845-98=3763$$
Please notice we need to include the 98 not subtracted before.
Python code:
The python code to get the sum of numbers between 1 and 100 excluding any number that contains 8 is presented below. In the first line, we created a vector of numbers between 1 and 100 (in Python, the range operation uses the interval between the first number and the last one - 1).
In the second line, we get the sum of elements in the vector and subtract any number with 8. To do it, we converted all the elements in the vector as a string and select those that include '8'. Those elements are added up and subtracted from the total sum.
n = list(range(1, 101))
print(sum(n) - sum(([i for i in n if '8' in str(i)])))
Sum of numbers between 1 and 100 excluding any number that contains 8: 3763
Question 3:
$X$ is a random variable such that $E[e^{tX}]=\frac{1}{(1-t)^2}$ for all $t<1$. What is $Var[X]$?
It is important to notice the difference between $E[X]$ and $E[e^{tX}]$, the first one is the expected value of the random variable $X$ and the second is the moment generation function of $X$ given by:
$$M_X(t) = E[e^{tX}] = \int e^{tX} f(X)dX $$
Where a "moment" is just the expected value of powers $$E[X^1], E[X^2], E[X^3]\cdots E[X^k]$$
To get the $k-$moment for the random variable $X$ we need to compute the $k-$derivative of $M_X(t)$ and eval the result on $t=0$, this is:
$$E[X^k]= \left. \frac{d^t}{dt^k}M_X(t)\right|_{t=0}$$
Now, $Var[X]=E(X^2) - \left[ E(X) \right]^2$ or the variance is the second moment of $X$ minus the first moment $X$ squared. Hence, we need to compute $E(X)$ and $E(X^2)$ based on the above equation.
$$\left. \frac{d}{dt}M_X(t)\right|_{t=0}= \left. \frac{d}{dt} \frac{1}{(1-t)^2} \right|_{t=0} = \left. 2(1-t)^{-3} \right|_{t=0} = 2 $$
$$\left. \frac{d^2}{dt^2}M_X(t)\right|_{t=0}= \left. 6(1-t)^{-4} \right|_{t=0} = 6 $$
Finally, the variance of $X$ is given by:
$$Var[X]=E(X^2) - \left[ E(X) \right]^2= 6-(2)^2=2$$
Reference:
Miller, Scott, and Donald Childers. Probability and random processes: With applications to signal processing and communications. Academic Press, 2012. Page: 139
Question 4:
Compute $p(y \le x)$ for $f(X,Y)=\frac{3}{2}X^2+2XY: (x,y) \in [0,1]^2$
The first step to solve this problem isto define the integration region. We know any value of $X$ and $Y$ belongs to the interval $[0, 1]$, however $X \ge Y$. It means, if $X=0.7$, the value of $Y$ should be between 0 and 0.7. It suggest the following region:
 |
| Integration region for $f(x, y)$ |
Notice from the figure that if you choose any value for $Y$, let say $Y=0.1$ (blue line) all the possible values for $X$ are greater or equal to 0.1. Hence, integration region is defined by: $0 \le Y \le X \le 1$. To compute $p(Y \le X)$ we need to compute:
$$ p(Y \le X) = \int \int \left(\frac{3}{2}x^2+2xy \right) dy dx$$
We can't integrate between 0 and 1 only because it breaks $0 \le Y \le X \le 1$. Hence, we need to adjust the integration limits. Consider the red rectangle of size $dy dx$, $dy$ goes from $0$ to $X$ (diagonal line) and then $X$ between 0 and 1, this is:
$$ p(Y \le X) = \int_{0}^{1} \int_{0}^{x} \left(\frac{3}{2}x^2+2xy \right) dy dx$$
Finally, we can compute the required probability:
$$p(Y \le X) = \int_{0}^{1} \int_{0}^{x} \left(\frac{3}{2}x^2+2xy \right) dy dx$$
$$= \int_{0}^{1} \left(\frac{3}{2}x^3+x^3 \right) dx= \int_{0}^{1} \frac{5}{2}x^3 dx=\frac{5}{8}$$
The Python code to solve the integral is the following:
from scipy import integrate
f = lambda y, x: 3/2*x**2 + 2*x*y
integrate.dblquad(f, 0, 1, lambda x: 0, lambda x: x)[0]
0.6250000000000001
The first parameter of integrate.dblquad is the function $f(y, x)$ and not $f(x, y)$ despite the second and third parameters are 0 and 1 (limit values for $X$). The last two values in the function are functions of $X$ corresponding to the domain of $Y$ (between 0 and $X$). Python function reference
scipy.integrate.dblquad
Question 5:
Compute $\int_{e^{-6}}^{e^{-5}} \frac{1}{x \ln x} dx$
To solve this integral, notice we have $\ln x$ and its first derivative $\frac{1}{x}$ together. So we can apply the following substitution:
$$u = \ln x$$
Hence $du=\frac{1}{x}dx$. In this case we can transform the problem to:
$$ \int_{e^{-6}}^{e^{-5}} \frac{1}{\ln x} \frac{1}{x } dx = \int_{-6}^{-5} \frac{1}{u} du = \left. \ln u \right|_{-6}^{-5} = \ln \frac{5}{6} $$
Thank you for the information. Please keep posting.
ReplyDeleteData Analytics Solutions