Reference no: EM132390754
Assignment
1 Question 1
Problem 1 Consider the following string str_example = 'Python is an interesting and useful language for numerical computing!'. Using slicing operations, extract the following strings from str_example:
(a). "Python"
(b). "in"
(c). "!gnitupmoc laciremun rof egaugnal lufesu dna gnitseretni na si nohtyP"
(d). "nohtyP"
(e). "Pto sa neetn n sfllnug o ueia optn!"
Problem 2 In calculus, the derivative of x4 is 4x3. The derivative of x5 is 5x4. The derivative of x6 is 6x5. This pattern continues. Write a program that asks the user for input like xˆ3 or xˆ25 (or any other) and prints out the derivative. For example, if the user enters xˆ4, the program should print out 4xˆ3.
Problem 3 Write a program that plots the trajectory of the stock market price as a random walk process. Suppose the price is initially at a level of zero. At each step the price moves up by one unit with probability p and moves down one unit with probability (1 − p). Please simulate the path of the stock price for 1000 periods. Plot a path for this random process. Please use p = 0.6
Problem 4 For this problem you will simulate a GARCH process, which is define as follows
yt = Φyt−1 + σtεt
σ2t = ω + αy2t−1 + βσ2t−1
for t = 1, 2, 3, ..., T.
Please do the following:
1. Write a function “path_garch” that takes parameters (ω,α,β and Φ) and initial values (y0,σ0) and return a vector of simulated values for yt and σt.
2. Use your function “path_garch” to simulate 1000 realizations of yt and σt. Use the values ω = 0.05, α = 0.02, β = 0.9 and Φ = −0.1. Set initial values y0 = ω/(1 − α − β) and σ0 = 0.4, and T = 100.
3. Using the simulations from part (2), plot in a 1x2 subplot figure the median, 5 percentile, and 95 percentile of the simulated values of yt (left subplot) and σt (right subplot) over time.
Problem 5
1. Simulate some data by generating matrices y,X and Z where
y = Xβ + e
X = Zα + µ
where e, and µ are standard normal random vectors.
You can use the following information:
np.random.seed(123)
Z = np.random.randn(500,3)
e = np.random.randn(500,1)
mu = np.random.randn(500,2)
alpha = np.array([[1,0.4],[0.5,-0.1],[0.7,0.5]])
beta = np.array([[0.2],[0.3]])
2. Please write your own 2SLS estimation function which should take arrays X, y and Z as inputs and compute the 2SLS estimates βˆ, the variance of errors s2 , and standard errors ofparameters seβˆ. The formulas for computing outputs are summarized below:
a). The 2SLS estimates βˆ is computed as:
βˆ =(X′PzX)−1(X′Pzy)
Pz = Z(Z′Z)−1Z′
b). The variance of the regression error is:
s2 = eˆ′eˆ/(N − k)
where k is the number of columns in X, N is the number of observations and eˆ = y − Xβˆ.
c). The standard errors for the parameters are:
seβˆ =√diag(V)
where V = s2 (X ′PzX)−1.
3. Test your function by computing the estimates and standard errors of β using the simulated data from part 1)
2 Question 2
1. Load the data oilP_SP.csv. Compute the growth rate for the oil and stock market price. Plot the oil price and stock market price growth rate in a 1-by-2 subplot figure.
2. Generate a table with descriptive statistics which shows the mean, standard deviation, kurtosis and skewness of the oil and stock market price growth using the full sample size. Then compute the correlation between oil and stock market price growth.
3. Generate tables of descriptive statistics (including mean, standard deviation, kurtosis and skewness) for oil and stock market price growth for different subperiods 1950-1973,1974- 2000 and 2001-2019. Please also report the correlation between oil and stock market price growth in each subperiod.
4. Compute the 3-year (36-month) rolling window correlation between the oil price growth and stock price growth. Plot the rolling correlation over time. Please label the x and y axis and show the title.
3 Question 3
1. Load the data CRSP_data.csv as a dataframe. A description of the variables in the dataset is shown below.
Variable Description
Date Date
Return Stock return
D/P Dividend-price ratio
D growth Dividend growth
T-bill ret. Treasury bill return
2. Plot in a 1x2 subplot figure, the dividend price ratio on the left subplot, and the stock return and the treasury bill return in the right subplot. Please show the title for the two subfigures and include the legend for the second subplot.
3. Run a regression of returns at date t + 1 on returns at date t i.e.
Rt+1 = a + bRt + εt+1
Do this for:
(a). The stock return
(b). The treasury bill return
(c). The stock excess return (defined as: stock return - treasury bill return)
Make a table of the coefficients, t statistics, and R2 for these regressions.
4. Run a regression of excess returns at date t + 1 on the dividend price ratio at date t, i.e.
R stock t+1 − R trea.bill t+1 = a + b(D/P)t + εt+1
for t = 1, 2, ..., T − 1. Please print out the estimates for a,b, its standard errors and the R2.
Question 4
1. Load the data bank_data.csv and call it df . Set the column date as Datetime. Remove the banks with the entity number larger or equal to 9990000.
2. Compute the pre-provision net revenue ppnr as follows:
ppnr = nim x intearn_ass + nintrat x assets + tradrat x trading_ass +nie_comp x assets + nie_fass x assets + nie_allother x assets
Also, compute the provision for loan and lease losses (call it cost ) as follows: cost =
rre_loan x rre_rate + cre_loan x cre_rate +con_loan x con rate + other loan x other rate
3. Compute the net_gain as the difference between ppnr and cost . Then plot the net gain overtime for the bank with entity numbers 1951350, 1073757, and 1039502 in one figure. When doing the figure, please rescale the net gain for each bank by dividing the net gain series by its value in 2000-01-01. Please show the legend and title, and mark the x and y-axis in the graph.
4. Plot the ten banks with the highest net gain in 2012-01-01 in a bar chart. Please label the x-axis with the banks' entity number. Please also show the title of the figure.
5. Categorize banks using equal-sized buckets based on assets quartiles in 2007-01-01 (hint: use the assets variable). Plot a 1-by-2 subplot figure. The first subplot shows the number of banks in each quartile category over time. The second subplot shows the average net gain of each quartile category over time.
6. Run a regression for net interest margin (nim) as follows:
nimi,t = +β0 + β1nim i,t-1 + β2spreadt + β3assetshare i,t + εt
where spread, is the interest rate spread at time t, and assetshare is the share of asset of bank i in period 1.
7. Compute the predicted value of nim for three banks (1951350, 1073757, and 1039502) for 12 quarters starting in 2013-07-01. Use the estimated parameters obtained in part (6). Assume assetshare and spread remain constant at the level observed in 2013-07-01. Plot the forecasted values of nim for the three banks.
Attachment:- bank_data.rar
Attachment:- CRSP Data.rar