Financial Computing Assignment Chapter 3 Time Series
Notes: •Provide commented programming code (Python language preferred) that can be executed. Your submitted solution will be tested on computer. Pictures or screen-shots of programming code are not accepted . •If you use standard Python, submit (1) a document (.pdf preferred, .docx accepted) with your answer and (2) the Python file (.py) with the commented code. (Your answers can copy the output of your programming code, when applicable). •If you use Jupyter Notebook, you can include both the answer and programming code in the notebook. Create separate sections for answers as text notes (markdown sessions). Run your code and display all results. Download the whole notebook in (1) either .pdf (preferred) or .html (accepted) and submit it. •Import packages you use and include package installation instructions as comment in you programming code • Report numbers up to the 4th decimal or higher in your answer 1 Exercise: Autocorrelation (15 points) The file "000001SZ.csv" contains time series of adjusted prices and return of PingAn Bank.
- Write a function that calculates the autocorrelation with arguments x(time series) and lag 2.Assign two series: X1with data from January 2001 to December 2010 and X1with data from January 2011 and December 2020.
- Compute the autocorrelation for the two series at lag= 1;:::; 22
- Plot results of the autocorrelations in autocorrelograms (use barplot) Do not use the already implemented functions for autocorrelation in statmodels.tsa or in pandas 2 Exercise: Autoregressive Process (30 points) The file ret5.csv contains 5 (adjusted) return series of randomly selectes stocks listed in the Shenzhen Stock Exchange for the last 20 years. Note that there are missing values that you can either replace Chapter 3 - Lab 1|3 with 0 or disregard (as if in those days the trading is closed). Fit a AR(1)model to each of those time series by implementing the following points: [NOTE: You are not allowed to use external packages or modules with the implementation] 1.Define a function fit_ar(params, x) that returns the residual from an AR(p) with arguments "params" and time series "x"
- Define a function ar_loglike(params, x) that return the log likelihood of the AR model 3.Define a function optim_par(x, init_par) that returns the estimated parameters by maximum likelihood of a AR(2) model 4.Plot the estimate for 0(intercept) and 1(first order partial autocorrelation) for each of the time series in a line or dot plot 5.Plot the residuals of each 5 time series as a line plot on the (xaxis = date, yaxis = residual) space. 3 Exercise: Time Varying (Conditional) Volatility Process (35 points) [Second stage estimation] With the data and estimated parameters of the previous exercise, fit an AR(1)-GARCH(1,1) model for each of the 5 time series, implementing the following points: [NOTE: You are not allowed to use external packages or modules with the implementation] 1.Define a function fit_GARCH11(params, epsilon) that return the time-varying conditional variance (ht) and standardized residuals ( epsilon t=p (ht)) of the GARCH(1,1) model, where the argument epsilon is the series (ndArray) of residuals from the AR(1) 2.Define a function garch11_loglike(params, epsilon) that return the log likelihood of the GARCH(1,1) model, where the argument "epsilon" is the series (ndArray) of residuals from the AR(1) 3.Define a function optim_par_garch11(epsilon, init_par) that returns the estimated parameters by maximum likelihood of the GARCH(1,1) model. Use the SciPy package. You may want to try different optimization algorithms (e.g. "SLSQP", "Nelder-Mead", "trust-constr") to check their power. 4.Plot the estimate for the 3 parameters of the GARCH(1,1): (!;; ), in a line or dot plot for each of the 5 time series. 5.Plot the standardized residuals of each 5 time series as a line plot on the (xaxis = date, yaxis = residual) space. Chapter 3 - Lab 2|3 4 Exercise: Simulation (20 points) Using the data and estimated parameter of the AR(1)-GARCH(1,1) of the previous exercises run a (historical) simulation by implementing the following points. 1.Choose 1 stock return from any of the 5 returns in the dataset. Consider p0= 100 is the starting price of the stock. Compute ptthe price for t= 1;:::; 2490 2.Simulate 10 possible price trajectories with AR(1) and constant volatility [NOTE: The chinese stock market imposes a 10% limit return. Hard code this limit in the simulated price by correcting the return whenever they exceed this limit.]
- Plot the actual price with the simulated trajectories for (AR(1)) in two separate plots. 4.Simulate 10 possible price trajectories with AR(1)- GARCH(1,1) conditional volatility [NOTE: The chinese stock market imposes a 10% limit return. Hard code this limit in the simulated price by correcting the return whenever they exceed this limit.] 5.Plot the actual price with the simulated trajectories for (AR(1)-GARCH(1,1)) in two separate plots. Chapter 3 - Lab 3|3