Solution to Practice Final Exam 584-S21
Solution to Practice Final Exam
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
Solution to Practice Final Exam 584-S21
Name A#
After you have completed the examination, sign the pledge below. A test without a signed
pledge may not be graded.
I declare that this assessment item is my own work, except where acknowledged, and has not
been submitted for academic credit elsewhere, and acknowledge that the assessor of this item
may, for the purpose of assessing this item:
• Reproduce this assessment item and provide a copy to another member of the IIT; and/or,
• Communicate a copy of this assessment item to a plagiarism checking service (which may
then retain a copy of the assessment item on its database for the purpose of future plagiarism
checking).
Signature:
Problem grade Point value
1 10
2 10
3.a 2
3.b 2
3.c 2
3.d 4
3.e 2
4.a 5
4.b 1
4.c 1
4.d 1
5 10
Total 50
Good luck
1. (10 pts) Consider a mutual fund F that invests 50% of its capital in the risk-free security and
50% in stock A, which has an annual return with expectation 10% and with standard deviation
12%. The annual risk-free rate is 5%. You short-sell the risk-free asset and invest the proceeds in
F so as to get an expected annual return of 15%. What is the standard deviation of the annual
return of your investment?
Solution.
Assume that we invest a fraction α of our capital into the mutual fund and 1−α in the risk-free
security. This portfolio has expected return
µ(α) = αµF + (1− α)r = αµA/2 + (1− α/2)r
where r = .05 is the risk-free rate and µA = .1 is the expected return of stock A. To get µ(α) = .15
we need
0.15 = α0.05 + (1− α/2)0.05 = 0.05 + α0.025,
which gives us α = 0.1/0.025 = 100/25 = 4. Such portfolio would have standard deviation
σ(α) = |α|σA/2 = 0.24,
where σA = 12% is the standard deviation of stock A.
2. (10 pts) Consider the following Python code. The input of this code consists of the ticker
name ‘ticker_name’, as well as the start date ‘start_date’ and the end date ‘end_date’ for a
sample of daily closing prices of this ticker. The output is ‘alpha_star_bt’.
stock_data = data.get_data_yahoo([ticker_name], start_date, end_date)
price = stock_data['Adj Close'].values
ret = (price[1:]-price[:-1])/price[0:-1]
gamma = -5.0
R = 0.01
R_daily = R/250
N = 250
T = 100
lam = 0.01
gamma = -5.0
n_win = 5
asset = 1
mu, sig = [], []
for k in range(n_win):
bt_start = N + k*T
temp = ret[(bt_start-N):bt_start,asset]
mu.append(np.mean(temp)), sig.append(np.std(temp))
grid_sz = 100
def expn(alpha,a,v_furt,mu_k,sig_k):
y = 0
for r_furt in [mu_k-sig_k,mu_k+sig_k]:
y = y + (1+(1-alpha)*R_daily+alpha*r_furt-lam*np.abs(alpha-a))
**gamma * v_furt(alpha*(1+r_furt)/(1+(1-alpha)*R_daily+alpha*r_furt))
return y/2
alpha_star_bt = []
a_grid = np.linspace(-2,2,grid_sz)
for k in range(n_win):
alpha_star_mat = [] # v_mat=[]
v_furt = lambda a : -1/gamma # terminal condition
for t in range(T-1,0,-1):
alpha_star, v = [], []
for a in a_grid:
mu_k, sig_k = mu[k], sig[k]
obj = lambda alpha: expn(alpha,a,v_furt,mu_k,sig_k)
opt = scipy.optimize.minimize(obj,[0])
alpha_star.append(opt.x), v.append(opt.fun)
alpha_star_mat.append(alpha_star)
v_furt = InterpolatedUnivariateSpline(a_grid, v, k=1)
alpha_star_bt.append(alpha_star_mat[::-1])
Explain in detail what this code does. In particular, explain the meaning of ‘lam’, ‘n_win’,
‘gamma’, ‘alpha_star_mat’, and ‘alpha_star_bt’. Describe the model that corresponds to the
financial problem being solved.
Solution.
This code constructs the optimal investment strategy for the power-utility optimization prob-
lem,
max
α
E (WT (α))γ /γ,
with proportional transaction costs and with a single risky asset. In the above,WT (α) represents
the terminal wealth generated by the strategy α over the time period [0, T ]. The first part of the
code downloads the data and initializes the parameters. Then, the expectation and the standard
deviation of the daily return of the risky asset are computed for each time period. The auxiliary
function ‘expn’ is defined to compute the objective function that needs to be maximized at each
time step in the DPP algorithm. The last part of the code implements the DPP and computes
the optimal strategy in feedback form.
The size of the transaction costs is ‘lam’= 0.01. The exponent of the utility function is
‘gamma’= −5. The parameter ‘n_win’ represents the number of time periods on which the
optimal strategy is constructed, which is also the same as the number of re-estimations of the
model parameters. The matrix ‘alpha_star_bt’ represents the optimal strategy in the feedback
form. The matrix ‘alpha_star_mat’ contains the same information as the latter matrix, but
with a reversed order of the rows.
The state process is given by the collection (R¯, A):
Wt(α) = Wt−1(α)(1 + αt−1(µ+ εt) + (1− αt−1)R− λ|αt−1 −At−1|),
At(α) =
αt−1(1 + µ+ εt)
1 + αt−1(µ+ εt) + (1− αt−1)R, α−1 = 0, t = 0, . . . , T,
where {εt} is zero-mean white noise, µ is the expected daily return of the risky asset, R is the
riskless return, and λ is the size of the proportional transaction costs. The value of At represents
the weight of the risky asset in your portfolio at time t, before you rebalance it.
3. Denote by X = {Xt} and Y = {Yt} the (adjusted daily closing) prices of two stocks.
a. (2 pts) Assume that there exists a constant C, such that
Zt = Xt − CYt, ∀ t, (0.1)
is a stationary time series. How would you find/estimate C? Name the associated Python
function(s) and module(s).
b. (2 pts) Describe a qualitative (visual) method one can use to determine whether a time
series Z is stationary. Name the associated Python function(s) and module(s).
c. (2 pts) Describe a quantitative method one can use to determine whether a time series Z
is stationary? Name the associated Python function(s) and module(s).
d. (4 pts) Assuming that Z, defined in (0.1), is stationary, how would you make profits using
this information? Describe when you would open/close your positions in the two stocks,
and what type of positions they would be. Explain how to estimate the profits and identify
the main sources of risk.
e. (2 pts) Assume that you follow the strategy described in part (d). Assume that, at time
t = 0, a new long position of size $1, 000, 000 is opened in stock X (as prescribed by the
strategy), and that X0 = 100, Y0 = 30, C = 2. If the proportional transaction costs are
given by λ = $0.005 per dollar transacted, what would be the total transaction cost (in $)
of opening the positions in both stocks at time t = 0, as prescribed by the strategy?
Solution.
a. We can use ordinary least-square regression to find X that best fits the relationship
Xt+1 −Xt = C(Yt+1 − Yt) + εt, t = 0, . . . , T,
where {εt} is white noise and T is the terminal time horizon. In Python, this can be implemented,
e.g., via ‘scipy.stats.linregress()’.
b. Plot the data against time and check if it is centered around a horizontal line, with approx-
imately the same magnitude of (frequent) oscillations, and without a trend or a clear periodic
component. In Python, we can use ‘matplotlib.pyplot.plot()’ function to plot the data. In ad-
dition we can use ‘numpy.mean(numpy.diff())’ to estimate the slope of the trend and see if it is
sufficiently strong.
c. We can use the Dickey-Fuller test to check the null hypothesis that the time series is a
random walk, versus the alternative that it is a stationary AR process. In Python, we can
do it via ‘statsmodels.tsa.stattools.adfuller()’. One minus the p-value of this test gives us the
confidence level with which we reject the null hypothesis.
d. Denote µ := EZt. Then, whenever Zt moves below µ− λ1 (with a chosen λ1 > 0), we open
a long position in X and a short position in Y . For every share of X purchased, we sell C shares
of Y . We close both positions whenever Zt moves above µ+ λ2 (with chosen λ1, λ2 > 0).
Similarly, whenever Zt moves above µ+ λ1, we open a short position in X and a long position
in Y . For every share of X sold, we purchase C shares of Y . We close both positions whenever
Zt moves below µ− λ2.
The values of λ1, λ2 should be of the same order of magnitude as σ :=
√
Var(Zt). The expected
profit of a single round-trip trade described above is λ2 − λ1. The main source of risk is the
de-integration of the two stocks: i.e., when the relationship (0.1) fails after some time t. This
risk is measured/controlled by the duration of the holding time and by the deviation of Z from
µ.
e. W.l.o.g., assume that we long X. Then, we purchase $1M of X, paying $5, 000 is T-costs,
and we short $600, 000 of Y , paying $3, 000 in T-costs. The total T-cost is $8, 000.
4. Assume that you need to execute a relatively large sell order of size Q (measured in the
number of shares) on an electronic exchange. Assume also that you need to execute this order
immediately, with a single market order. For simplicity, assume that you choose not to use the
smart order router (SOR), and that your latency is zero. The current limit order book consists
of the (observed) volumes
V a0 > 0, V
a
1 , . . . , V
a
k ,
corresponding to the price levels (in $)
A,A+ 0.01, . . . , A+ k · 0.01,
on the ask side, and of the volumes
V b0 > 0, V
b
1 , . . . , V
b
k ,
corresponding to the price levels (in $)
B,B − 0.01, . . . , B − k · 0.01,
on the bid side. The bid and ask prices B and A, as well as the integer k ≥ 1, are known
(observed).
a. (5 pts) Write down a formula, or describe a Python function, that computes the immediate
impact of this trade on the midprice (i.e., the change in the midprice). You may assume
that Q does not exceed the overall volume available on the bid side of the book. Compute
the value of this impact for
Q = 1, 000, k = 2, B = 10, A = 10.01, V b0 = V
a
0 = 800, V
b
1 = V
a
1 = 500, V
b
2 = V
a
2 = 1, 000.
b. (1 pts) What is the price per share of this transaction?
c. (1 pts) How would the price impact change if you used the SOR?
d. (1 pts) What would change if your latency was higher?
Solution.
a. We write the code.
k1 = k
temp = 0
for i in range (k):
temp = temp+Vb[i]
if ((temp>Q) & (k1==k)):
k1 = i
impact = 0.5*(A+B-0.01*k1) - 0.5*(A+B)
For the data given, the above code produces k1= 1 and the impact −$0.5 ∗ 0.01 = −$0.005.
b. 800 shares are sold at price B = $10, and 200 shares are sold at price $9.99. The total cash
received is $8, 000 + $1, 998 = $9, 998. The price per share is $9, 998/1, 000 = $9.998.
c. If we used SOR, the cash received for this execution could increase. For example, the last
200 shares would have been routed to a different exchange which has enough bid LOs posted at
price B, if such exchange exists at this time.
d. If our latency is higher, by the time our MO reaches the exchange, the bid LOs could change.
This means uncertainty in the execution price: it could be higher or lower.