# Python代写 | Assignment 2 – Create the returns for the three stocks

Python使用三种股票进行投资组合分析

Assignment 2
1. This part of the exercise is on optimization. Use the provided daily price data on three stocks. You must have a command in your codes to download it directly from the web address (https://sites.google.com/site/chnyyang/price_data.csv).
(a) Create the returns for the three stocks
rt = pt+1 −pt.
pt
(b) Compute the sample means of the returns of the three stocks and the covariance matrix.
(c) Maximize the average returns by choosing the allocation of 1 unit of wealth into the three stocks, subject to the condition of (1) fractions need be nonnegative; (2) (budget constraint) the sum need be no larger than 1; (3) the standard deviation of the portfolio needs to be no large than the lowest standard deviation of the returns of the three stocks.
2. This part of the exercise is on regression. Use the provided data set diamonds.csv. You must have a command in your codes to download it directly from the web address (https://sites.google.com/site/chnyyang/diamonds.csv). Consider the regression model
Y =β0 +β1carat+β2color+U
(a) Regress price on the weight of the diamonds (carat) and color. Report robust standard errors.
(b) Calculate the 25%, 50% and 75% quantiles of carats.
(c) Calculate the variances of prices where the weights of the colored diamonds (color=1) are less than 25% quantile, between 25% and 50%, between 50% and 75%, and between 75% and 100%. Use the quantiles calculated in (b). In the end you should have 4 conditional variances.
(d) Based on your calculations in (c), how does the variance of U change with carat for colored diamonds?
(e) Predict the mean price of colored diamonds at 50% quantile of the weight.
(f) Calculate the confidence interval for (e).
(g) Based on your answer in (d), is it reasonable to assume homoskedasticity?
(h) Based on your answer in (g), is it reasonable to calculate Var(U) and use it to calculate the confidence interval of
β0 + β1carat + β2color + U for some values of the explanatory variables?
3. This part is on CAPM model. The model says two things. First, the CAPM equation E(ri)−rRF =βi(E(rmkt)−rRF),
which says the expected return of stock i, E (ri), over the risk-free (constant) return rRF , is linearly related to the expected returns of the market minus the risk free rate. Secondly,
βi = Cov(ri,rmtk). (1) Var(rmkt)
We estimate βi in this exercise.
1

(a) Read in the data of the market returns and the adjusted closing price of three stocks (HD, AAPL and VZ). You must have a command in your codes to download it directly from the web address (https://sites.google.com/site/chnyyang/capm.csv). Calculate the returns of the stocks.
(b) Calculate βi according to the definition in (1).
(c) Interpret the meaning of the estimates.
(d) To answer the question whether the relationship predicted by CAPM is precisely estimated, we use the bootstrap method to estimate the standard error. Bootstrap the data for 2000 times. In other words, bootstrap the tuples of the observation (rmkt,ri) and create 2000 “reshuffled” data sets for each stock.
(e) Calculate βi on each bootstrapped data set. You should have 2000 estimates of the bootstrapped estimates of βi on each data set.
(f) Compute the 0.025 and 0.975 quantiles for the βi estimates, which are your bootstrapped 95% confidence intervals.
(g) Can you reject the null hypothesis βi = 0 in each case? Use 2-sided tests based on the 95% confidence interval in (f) and state your conclusion properly.
(h) Next we run the regression on the model
rHD =α+βHDrmkt +U (2)
(i) Why should the estimates be (un)equal to the number calculated in (b)?
(j) Do you think (2) can be consistently estimated with OLS? No calculation is needed, but you need to provide a convincing argument. (Hint: what is the necessary condition for the conditional mean independence assumption?)
2 E-mail: [email protected]  微信:itcsdx 