# Python辅导 | Assignment with written and programming components

Assignment 1
The assignment consists of both written and programming components
1. Use simulations to compute probabilities and expectation. (a) The goal of the first exercise is to compute
E?X2?,
where X is a standard normal distribution. One can directly show that E ?X2? is 1. Set the random seed to 120. Generate 20,40,…,200 draws from a standard normal distribution. For each data set, compute the sample mean of the squares of the data points. Plot the result for each sample size and check whether the average approaches 1 as the size of the data set increases.
(b) X and Y are independent standard normal random variables. We define two new random variables ?X ̃,Y ̃? as
4444
We know these two random variables are normal. What are the marginal distributions of X ̃ and
Y ̃ ? (You need to calculate their means and variances using formulas)
(c) The covariance of the two random variables is 3. We now calculate this covariance using Python: 8
simulate two series of numbers from standard normal distributions
? ̃ ̃??1 33 1? X,Y = X+ Y, X+ Y .
x1,x2,x3,… y1,y2,y3,…
and create the new series
8
(d) Let’s consider simulating the conditional probabilities. Suppose we would like to calculate the
1×1 + 3y1,… 44
3×1 + 1y1,… 44
Calculate the sample covariance for your simulations. Do this for data sets of size 200, 400, . . ., 2000, and plot the sample covariances and see whether they approach 3.
probability of
The conditional probability is given by
Pr ?X ̃ ≤ 1 | Y ̃ ≤ 2? .
Pr ?X ̃ ≤ 1, Y ̃ ≤ 2? some fraction of the simulations
Pr ?Y ̃ ≤ 2? ≈ some other fraction of the simulations .
Use the same data sets as (c), calculate the fractions for data sets of size 200, 400, …, 2000, and plot the ratios. Note that in this case, we do not have a closed solution and have to rely on simulations.
1

(e) We can also calculate conditional expectations. Suppose we would like to use simulation to calculate
E ? X ̃ | X ̃ ≤ 1 ? .
You still will calculate a sample mean, but on a specific subsample. Again, do this for all the data
sets in (c) and see which value the results approach.
(f) Repeat (e) for
E ? X ̃ | X ̃ ≤ 1 , Y ̃ ≤ 2 ? .
2. Bootstrap methods to calculate statistics. Re-set the random seed to 120
(a) Download the 2019 AMD stock prices at daily frequency from Yahoo finance. Read in the data with Python. (The data should start on the first day available in 2019 and end some time in August. The exact end date does not matter.)
(b) Focus on the variable called “adjusted closing price”. Our analysis will be based on this variable and not other prices. Calculate the sample mean μˆ and sample standard deviation σˆ.
(c) If the data are from an i.i.d and normal sample, then about 68% of the data should be within one σˆ away from μˆ, and 95% of the data should be within 1.96σˆ from μˆ. Is this the case? Calculate the percentages of data covered by the two intervals.
(d) If the data are from an i.i.d and normal sample, what should the correlation of the prices on day t and t + 1 be? What is the sample correlation?
(e) Let the price on t be yt. Create new data
rt = yt+1 −yt.
yt
You will have one fewer observation than yt. What is the sample correlation between rt+1 and
rt? Is the i.i.d assumption more or less likely to hold?
(f) Calculate the standard deviation of rt and the bootstrapped standard error. Bootstrap 1000
times.
(g) Calculate the data analog of the following statistic
σ− =?E(V2),
where V = min{0,rt}. Comparing σ−2 with the variance tells you the proportion of variations
where prices move downward.
(h) Use the bootstrap samples from (f) and perform bias reduction on the estimate σˆ− and calculate the bootstrapped standard error.
2 E-mail: vipdue@outlook.com  微信号:vipnxx 