CWS - Assignment Pratyush MAE28
CWS - Assignment Pratyush MAE28
[b] Simulate 50 different realizations of the same random walk model and plot the first 10
realizations.
[c] Extract the values of the simulated series at time period 30 for all 50 realizations, reshape the data
into long format, and generate a histogram for the combined Y30 values across realizations.
1
Pratyush Sahu 2023/MAE/28
[d] Modify the random walk model by adding a drift term and simulate 50 realizations of this model.
Plot the first 10 realizations and observe how drift influences the process.
Including a drift term in the random walk process causes the series to exhibit a consistent upward or
downward trend, making it non-stationary with a predictable direction over time. The realizations will
show a systematic deviation rather than fluctuating around zero, unlike a random walk without drift.
Q.2 Generate a time series with a deterministic linear trend and random noise for 200 periods.
Detrend the series by regressing it on the time variable. Plot both the original and detrended series.
How does detrending affect the overall behaviour of the time series?
Detrending removes the deterministic trend component, leaving only the stochastic part. This
transforms the series to be stationary, stabilizing the mean and making it easier to analyze underlying
patterns and fluctuations.
2
Pratyush Sahu 2023/MAE/28
Q.3 Using any suitable Stata dataset, estimate a time series model where the trend is unknown. Fit
polynomial trends of varying degrees (e.g., linear, quadratic, cubic) and compare the model fit using
the AIC, BIC criterion. How do you determine the best fitting model, and what insights do the
residuals provide about the trend?
3
Pratyush Sahu 2023/MAE/28
Q4. In Stata, simulate 50 realizations of an AR(2) process for 100 time periods using the following
specification: Yt = −0.7Yt−1 + 0.8Yt−2 + εt where εt is a normally distributed error term. Plot the first
4
Pratyush Sahu 2023/MAE/28
10 realizations. What patterns do you observe across the realizations? Explain the behaviour of the
AR(2) process over time.
In the AR(2) process, the realizations often show cyclical or oscillatory patterns due to the influence of
both lags. The interaction between Yt−1 and Yt−2 causes the series to alternate direction, creating
smoother and more persistent fluctuations over time compared to an AR(1) process. This reflects the
dampening effect of the coefficients on past values.
Q.5 Simulate a similar AR(1) process for 50 realizations with 100 observations using the specification:
Yt = 0.5Yt−1 + εt where εt is a normally distributed error term.
Compare the AR(2) and AR(1) realizations by plotting them together. What are the key differences in
their dynamics, and how does the second lag affect the AR(2) process?
5
Pratyush Sahu 2023/MAE/28
The AR(2) process shows more complex dynamics with oscillatory patterns, while the AR(1) process is
simpler and exhibits gradual adjustments. The second lag in AR(2) introduces cyclical behavior,
creating smoother and longer-lasting cycles compared to the quicker mean-reversion of AR(1).
Q.6 Using Stata, simulate 50 realizations of an MA(1) process for 100 time periods with the following
specification: Yt = 0.5εt-1 + εt
Plot the autocorrelation function (ACF) for one of the realizations (Y1). What is the theoretical
autocorrelation at lag 1, and how does the sample ACF compare?
There is a non zero autocorrelation at lag 1. At other lags, the autocorrelation is close to 0
Q.7 In Stata, simulate 50 realizations of an MA(2) process for 100 time periods using the following
specification: Yt = 1.5εt-1 + 0.3εt−2 +εt
Generate the ACF for one realization (Y1) with 10 lags. How do the sample autocorrelations behave,
and how does this differ from an MA(1) process?
In the MA(2) process, the sample autocorrelations show significant values at lags 1 and 2, after which
they quickly drop to near zero. This differs from the MA(1) process, where only lag 1 shows significant
autocorrelation, while subsequent lags are close to zero. The presence of the second lag in MA(2)
extends the correlation structure.
6
Pratyush Sahu 2023/MAE/28
Q.8 Simulate an MA(1) process for 50 realizations with 10,000 time periods using the specification:
Yt = 0.5εt-1 + εt
Compare the autocorrelations at lag 1 for simulations with 100 observations and 10,000 observations.
How does increasing the sample size affect the accuracy of the estimated autocorrelation, and why?
Increasing the sample size (from 100 to 10,000 observations) improves the accuracy of the estimated
autocorrelation at lag 1. With a larger sample, the estimation becomes more stable and closer to the
theoretical value due to reduced sampling variability. This is because more data provides a better
representation of the underlying process.
7
Pratyush Sahu 2023/MAE/28
Q.9 Simulate a random walk without drift using Stata. Illustrate how the DickeyFuller test results
change when you include or exclude a constant and lags.
Including a constant in the Dickey-Fuller test adjusts for a potential non-zero mean, making it less
likely to reject the null hypothesis of a unit root. Adding lags accounts for autocorrelation in the
series, which can also affect the test results. Without a constant or lags, the test may falsely suggest
stationarity. Adjusting these components helps improve test accuracy based on the series'
characteristics.
8
Pratyush Sahu 2023/MAE/28
Q.10 Select a time series dataset of your choice (e.g., stock prices, exchange rates,commodity prices,
or economic indicators from reliable databases, with a minimum of 50 time periods) and apply ARIMA
modeling to it. Follow the steps below to complete the assignment:
Using the chosen ARIMA model, forecast future values by fitting it to the historical data. The predicted
values should closely follow the actual values if the model fits well. Plotting the actual vs. predicted
values helps visualize the model's accuracy, where a good fit shows minimal deviation between the
two lines, indicating reliable forecasts.
9
Pratyush Sahu 2023/MAE/28
10
Pratyush Sahu 2023/MAE/28
11
Pratyush Sahu 2023/MAE/28
12