0% found this document useful (0 votes)
19 views

Assignment 6

Uploaded by

niranth sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Assignment 6

Uploaded by

niranth sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

26/07/2024, 08:39 Untitled16.

ipynb - Colab

a.)

1
2
3 import numpy as np
4 import pandas as pd
5 import matplotlib.pyplot as plt
6
7 # Sample data (replace with actual data from the file)
8
9 df = pd.read_excel("Test6.xlsx")
10 print(df.head())
11
12 # Handling 'NA' values (replace with appropriate method)
13 df.fillna(method='bfill', inplace=True)
14
15 # Create time series plots
16 plt.figure(figsize=(12, 8))
17
18 # CPI of Euro area and USA
19 plt.subplot(2, 2, 1)
20 plt.plot(df['YYYY-MM'], df['CPI_EUR'], label='Euro Area')
21 plt.plot(df['YYYY-MM'], df['CPI_USA'], label='USA')
22 plt.title('CPI')
23 plt.legend()
24
25 # Log(CPI) of Euro area and USA
26 plt.subplot(2, 2, 2)
27 plt.plot(df['YYYY-MM'], df['LOGPEUR'], label='Euro Area')
28 plt.plot(df['YYYY-MM'], df['LOGPUSA'], label='USA')
29 plt.title('Log(CPI)')
30 plt.legend()
31
32 # Monthly inflation (DP) of Euro area and USA
33 plt.subplot(2, 2, 3)
34 plt.plot(df['YYYY-MM'], df['DPEUR'], label='Euro Area')
35 plt.plot(df['YYYY-MM'], df['DPUSA'], label='USA')
36 plt.title('Monthly Inflation (DP)')
37 plt.legend()
38
39 plt.tight_layout()
40 plt.show()
41
42 # Conclusions (replace with your own analysis based on the plots)
43 print("Conclusions from the plots:")
44 print("- Both CPI and log(CPI) show similar trends for Euro area and USA.")
45 print("- Monthly inflation (DP) seems to be more volatile.")
46 print("- Further analysis is needed to determine the predictive power of US inflation on Euro ar
47

https://colab.research.google.com/drive/1leKs6__GCNSCY7yCsn-SaZt6j2crI5dr?authuser=0#scrollTo=m0EbDkQf-Vog&printMode=true 1/6
26/07/2024, 08:39 Untitled16.ipynb - Colab

YYYY-MM TREND CPI_EUR CPI_USA LOGPEUR LOGPUSA DPEUR DPUSA


0 2000M01 1 105.1 107.6 4.654912 4.678421 NaN NaN
1 2000M02 2 105.4 108.3 4.657763 4.684905 0.002850 0.006485
2 2000M03 3 105.8 109.1 4.661551 4.692265 0.003788 0.007360
3 2000M04 4 105.9 109.2 4.662495 4.693181 0.000945 0.000916
4 2000M05 5 106.0 109.3 4.663439 4.694096 0.000944 0.000915

Conclusions from the plots:


- Both CPI and log(CPI) show similar trends for Euro area and USA.
- Monthly inflation (DP) seems to be more volatile.
- Further analysis is needed to determine the predictive power of US inflation on Euro area in

b.)

https://colab.research.google.com/drive/1leKs6__GCNSCY7yCsn-SaZt6j2crI5dr?authuser=0#scrollTo=m0EbDkQf-Vog&printMode=true 2/6
26/07/2024, 08:39 Untitled16.ipynb - Colab
1
2
3 from statsmodels.tsa.stattools import adfuller
4
5 # Perform ADF test for Euro area log(CPI)
6 result_eur = adfuller(df['LOGPEUR'], regression='ct', autolag='AIC', maxlag=3)
7 print("ADF Test for Euro Area Log(CPI):")
8 print("t-value of Coefficient of log(CPIt-1):", result_eur[0])
9 print("Critical t-value:", result_eur[4]['5%'])
10 if result_eur[0] < result_eur[4]['5%']:
11 print("Conclusion: Reject null hypothesis, time series is stationary.")
12 else:
13 print("Conclusion: Fail to reject null hypothesis, time series is non-stationary.")
14
15 print("\n")
16
17 # Perform ADF test for USA log(CPI)
18 result_usa = adfuller(df['LOGPUSA'], regression='ct', autolag='AIC', maxlag=3)
19 print("ADF Test for USA Log(CPI):")
20 print("t-value of Coefficient of log(CPIt-1):", result_usa[0])
21 print("Critical t-value:", result_usa[4]['5%'])
22 if result_usa[0] < result_usa[4]['5%']:
23 print("Conclusion: Reject null hypothesis, time series is stationary.")
24 else:
25 print("Conclusion: Fail to reject null hypothesis, time series is non-stationary.")
26

ADF Test for Euro Area Log(CPI):


t-value of Coefficient of log(CPIt-1): -3.7763913501233537
Critical t-value: -3.4418722820477714
Conclusion: Reject null hypothesis, time series is stationary.

ADF Test for USA Log(CPI):


t-value of Coefficient of log(CPIt-1): -2.8249430667019966
Critical t-value: -3.442098279332953
Conclusion: Fail to reject null hypothesis, time series is non-stationary.

c.) Finding correlations first

1
2 import statsmodels.api as sm
3
4 # Perform OLS regression
5 X = sm.add_constant(df['LOGPUSA']) # Add a constant to the independent variable
6 model = sm.OLS(df['LOGPEUR'], X)
7 results = model.fit()
8
9 # Calculate residuals
10 residuals = results.resid
11
12 # Perform ADF test on residuals
13 result_residuals = adfuller(residuals, regression='ct', autolag='AIC', maxlag=3)
14 print("\nADF Test for Residuals:")
15 print("t-value of Coefficient of Residuals(t-1):", result_residuals[0])
16 if result_residuals[0] < -3.8:
17 print("Conclusion: Reject null hypothesis, residuals are stationary. Series are cointegrated.
18 else:
19 print("Conclusion: Fail to reject null hypothesis, residuals are non-stationary. Series are n
20

ADF Test for Residuals:


t-value of Coefficient of Residuals(t-1): -3.4244571111192053
Conclusion: Fail to reject null hypothesis, residuals are non-stationary. Series are not coint

https://colab.research.google.com/drive/1leKs6__GCNSCY7yCsn-SaZt6j2crI5dr?authuser=0#scrollTo=m0EbDkQf-Vog&printMode=true 3/6
26/07/2024, 08:39 Untitled16.ipynb - Colab

1
2 import pandas as pd
3 import matplotlib.pyplot as plt
4 from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
5
6 # Calculate and plot sample autocorrelations
7 plt.figure(figsize=(12, 4))
8 plot_acf(df['DPEUR'].dropna(), lags=20)
9 plt.title('Sample Autocorrelations of DPEUR')
10 plt.show()
11
12 # Calculate and plot sample partial autocorrelations
13 plt.figure(figsize=(12, 4))
14 plot_pacf(df['DPEUR'].dropna(), lags=20)
15 plt.title('Sample Partial Autocorrelations of DPEUR')
16 plt.show()
17
18 # Fit the AR model
19 X = sm.add_constant(pd.concat([df['DPEUR'].shift(6), df['DPEUR'].shift(12)], axis=1).dropna())
20 y = df['DPEUR'].iloc[12:] # Adjust index to match lagged variables
21 ar_model = sm.OLS(y, X)
22 ar_results = ar_model.fit()
23
24 # Print the model summary
25 print(ar_results.summary())
26

https://colab.research.google.com/drive/1leKs6__GCNSCY7yCsn-SaZt6j2crI5dr?authuser=0#scrollTo=m0EbDkQf-Vog&printMode=true 4/6
26/07/2024, 08:39 Untitled16.ipynb - Colab

<Figure size 1200x400 with 0 Axes>

<Figure size 1200x400 with 0 Axes>

OLS Regression Results


==============================================================================
Dep. Variable: DPEUR R-squared: 0.494
Model: OLS Adj. R-squared: 0.486
Method: Least Squares F-statistic: 63.03
Date: Fri, 26 Jul 2024 Prob (F-statistic): 8.03e-20
Time: 03:08:03 Log-Likelihood: 600.92
No. Observations: 132 AIC: -1196.
Df Residuals: 129 BIC: -1187.
Df Model: 2
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [0.025 0.975]
------------------------------------------------------------------------------
const 0.0002 0.000 0.883 0.379 -0.000 0.001
DPEUR 0.2130 0.071 3.020 0.003 0.073 0.353
DPEUR 0.6544 0.076 8.593 0.000 0.504 0.805
==============================================================================
Omnibus: 11.666 Durbin-Watson: 1.600
Prob(Omnibus): 0.003 Jarque-Bera (JB): 22.704
https://colab.research.google.com/drive/1leKs6__GCNSCY7yCsn-SaZt6j2crI5dr?authuser=0#scrollTo=m0EbDkQf-Vog&printMode=true 5/6
26/07/2024, 08:39
qUntitled16.ipynb - Colab
Skew: -0.328 Prob(JB): 1.17e-05
Kurtosis: 4.923 Cond. No. 389.
==============================================================================

Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.

d.)

1 # Fit the AR model


2 X = sm.add_constant(pd.concat([df['DPEUR'].shift(6), df['DPEUR'].shift(12), df["DPUSA"].shift(1
3 y = df['DPEUR'].iloc[12:] # Adjust index to match lagged variables
4 d_model = sm.OLS(y, X)
5 d_results = d_model.fit()
6
7 # Print the model summary
8 print(d_results.summary())

OLS Regression Results


==============================================================================
Dep. Variable: DPEUR R-squared: 0.616
Model: OLS Adj. R-squared: 0.601
Method: Least Squares F-statistic: 40.41
Date: Fri, 26 Jul 2024 Prob (F-statistic): 1.25e-24
Time: 03:08:03 Log-Likelihood: 619.08
No. Observations: 132 AIC: -1226.
Df Residuals: 126 BIC: -1209.
Df Model: 5
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [0.025 0.975]
------------------------------------------------------------------------------
const 0.0003 0.000 1.175 0.242 -0.000 0.001
DPEUR 0.2081 0.071 2.913 0.004 0.067 0.349
DPEUR 0.6957 0.078 8.907 0.000 0.541 0.850
DPUSA 0.2270 0.049 4.606 0.000 0.130 0.325
DPUSA -0.0519 0.054 -0.967 0.335 -0.158 0.054
DPUSA -0.2451 0.053 -4.635 0.000 -0.350 -0.140
==============================================================================
Omnibus: 10.325 Durbin-Watson: 1.980
Prob(Omnibus): 0.006 Jarque-Bera (JB): 14.416
Skew: 0.421 Prob(JB): 0.000741
Kurtosis: 4.382 Cond. No. 488.
==============================================================================

Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.

The p-value of DPUSA with lag 6 is very high, hence we can reject it and fit the model with remaining parameters

1 # Fit the AR model


2 X = sm.add_constant(pd.concat([df['DPEUR'].shift(6), df['DPEUR'].shift(12), df["DPUSA"].shift(1
3 y = df['DPEUR'].iloc[12:] # Adjust index to match lagged variables
4 d_model = sm.OLS(y, X)
5 d_results = d_model.fit()
6
7 # Print the model summary
8 print(d_results.summary())

OLS Regression Results


==============================================================================
Dep. Variable: DPEUR R-squared: 0.613
Model: OLS Adj. R-squared: 0.601
Method: Least Squares F-statistic: 50.31
Date: Fri, 26 Jul 2024 Prob (F-statistic): 2.60e-25

https://colab.research.google.com/drive/1leKs6__GCNSCY7yCsn-SaZt6j2crI5dr?authuser=0#scrollTo=m0EbDkQf-Vog&printMode=true 6/6

You might also like