You are on page 1of 19

Collaborative Review Task M2

In [1]: import numpy as np


from scipy.optimize import fsolve
from scipy.stats import iqr
import pandas as pd

import holoviews as hv
import hvplot.pandas

In [2]: # There is a compatilibility issue with this library \


#and newer versions of Pandas, this is short fix to the problem, \
#if you have issues at this chunk comment it out and you should be fine.
pd.core.common.is_list_like = pd.api.types.is_list_like
import pandas_datareader.wb as wb

In [3]: hv.extension('bokeh')
np.random.seed(42)

In [4]: def P(*args, **kwargs):


P = np.linspace(-10, 10, 100).reshape(-1,1)
P = P[P!=0]
return P

def AS(P=P(), W=0, P_e=1, Z_2=0):


return P-Z_2

def AD(P=P(), M=0, G=0, T=0, Z_1=0):


return -P+Z_1

In [5]: def findIntersection(fun1,fun2,x0):


return fsolve(lambda x : fun1(x) - fun2(x),x0)
In [6]: indicators = wb.get_indicators()

In [7]: countries = wb.get_countries()


countries.head()

Out[7]:
adminregion capitalCity iso3c incomeLevel iso2c latitude lendingType longitude name region

Not Latin America


0 Oranjestad ABW High income AW 12.51670 -70.0167 Aruba
classified & Caribbean

1 South Asia Kabul AFG Low income AF 34.52280 IDA 69.1761 Afghanistan South Asia

2 AFR Aggregates A9 NaN Aggregates NaN Africa Aggregates

Sub-Saharan Africa (excluding high Lower middle Sub-Saharan


3 Luanda AGO AO -8.81155 IBRD 13.2420 Angola
income) income Africa

Europe & Central Asia (excluding high Upper middle Europe &
4 Tirane ALB AL 41.33170 IBRD 19.8172 Albania
income) income Central Asia
In [8]: %%opts Curve [width=800, height=450]
oil = wb.download(indicator='NY.GDP.PETR.RT.ZS', country=['USA','GBR','CAN','ZAF','MEX'], start=pd.to_datetime('1970', yearfirs
t=True), end=pd.to_datetime('2007', yearfirst=True))
oil = oil.reset_index().dropna()

oil_unscaled = oil

oil.loc[oil.country=='United States', 'NY.GDP.PETR.RT.ZS'] = (oil.loc[oil.country=='United States', 'NY.GDP.PETR.RT.ZS'] -


oil.loc[oil.country=='United States', 'NY.GDP.PETR.RT.ZS'].mean
())/\
iqr(oil.loc[oil.country=='United States', 'NY.GDP.PETR.RT.ZS'])

oil.loc[oil.country=='United Kingdom', 'NY.GDP.PETR.RT.ZS'] = (oil.loc[oil.country=='United Kingdom', 'NY.GDP.PETR.RT.ZS'] -


oil.loc[oil.country=='United Kingdom', 'NY.GDP.PETR.RT.ZS'].mean
())/\
iqr(oil.loc[oil.country=='United Kingdom', 'NY.GDP.PETR.RT.Z
S'])

oil.loc[oil.country=='Canada', 'NY.GDP.PETR.RT.ZS'] = (oil.loc[oil.country=='Canada', 'NY.GDP.PETR.RT.ZS'] -


oil.loc[oil.country=='Canada', 'NY.GDP.PETR.RT.ZS'].mean())/\
iqr(oil.loc[oil.country=='Canada', 'NY.GDP.PETR.RT.ZS'])

oil.loc[oil.country=='South Africa', 'NY.GDP.PETR.RT.ZS'] = (oil.loc[oil.country=='South Africa', 'NY.GDP.PETR.RT.ZS'] -


oil.loc[oil.country=='South Africa', 'NY.GDP.PETR.RT.ZS'].mean
())/\
iqr(oil.loc[oil.country=='South Africa', 'NY.GDP.PETR.RT.ZS'])

oil.loc[oil.country=='Mexico', 'NY.GDP.PETR.RT.ZS'] = (oil.loc[oil.country=='Mexico', 'NY.GDP.PETR.RT.ZS'] -


oil.loc[oil.country=='Mexico', 'NY.GDP.PETR.RT.ZS'].mean())/\
iqr(oil.loc[oil.country=='Mexico', 'NY.GDP.PETR.RT.ZS'])

oil_plot = oil.iloc[::-1,:].hvplot.line(x='year', y='NY.GDP.PETR.RT.ZS', by='country', title='Scaled Oil rents (% of GDP)')

oil_plot
Out[8]:

(http
In [9]: %%opts Curve [width=800, height=450]
money = wb.download(indicator='FM.LBL.BMNY.GD.ZS', country=['USA','GBR','CAN','ZAF','MEX'], start=pd.to_datetime('1970', yearfi
rst=True), end=pd.to_datetime('2007', yearfirst=True))
money = money.reset_index().dropna()

money_unscaled = money

money.loc[money.country=='United States', 'FM.LBL.BMNY.GD.ZS'] = (money.loc[money.country=='United States', 'FM.LBL.BMNY.GD.Z


S'] -
money.loc[money.country=='United States', 'FM.LBL.BMNY.GD.Z
S'].mean())/\
iqr(money.loc[money.country=='United States', 'FM.LBL.BMNY.
GD.ZS'])

money.loc[money.country=='United Kingdom', 'FM.LBL.BMNY.GD.ZS'] = (money.loc[money.country=='United Kingdom', 'FM.LBL.BMNY.GD.Z


S'] -
money.loc[money.country=='United Kingdom', 'FM.LBL.BMNY.GD.Z
S'].mean())/\
iqr(money.loc[money.country=='United Kingdom', 'FM.LBL.BMN
Y.GD.ZS'])

money.loc[money.country=='Canada', 'FM.LBL.BMNY.GD.ZS'] = (money.loc[money.country=='Canada', 'FM.LBL.BMNY.GD.ZS'] -


money.loc[money.country=='Canada', 'FM.LBL.BMNY.GD.ZS'].mean
())/\
iqr(money.loc[money.country=='Canada', 'FM.LBL.BMNY.GD.Z
S'])

money.loc[money.country=='South Africa', 'FM.LBL.BMNY.GD.ZS'] = (money.loc[money.country=='South Africa', 'FM.LBL.BMNY.GD.ZS']


-
money.loc[money.country=='South Africa', 'FM.LBL.BMNY.GD.Z
S'].mean())/\
iqr(money.loc[money.country=='South Africa', 'FM.LBL.BMNY.G
D.ZS'])

money.loc[money.country=='Mexico', 'FM.LBL.BMNY.GD.ZS'] = (money.loc[money.country=='Mexico', 'FM.LBL.BMNY.GD.ZS'] -


money.loc[money.country=='Mexico', 'FM.LBL.BMNY.GD.ZS'].mean
())/\
iqr(money.loc[money.country=='Mexico', 'FM.LBL.BMNY.GD.Z
S'])

money_plot = money.iloc[::-1,:].hvplot.line(x='year', y='FM.LBL.BMNY.GD.ZS', by='country', title='Broad money (% of GDP)')


Out[9]: money_plot

(http
In [10]: %%opts Curve [width=800, height=450]
gdp = wb.download(indicator='NY.GDP.PCAP.KD', country=['USA','GBR','CAN','ZAF','MEX'], start=pd.to_datetime('1970', yearfirst=T
rue), end=pd.to_datetime('2013', yearfirst=True))
gdp = gdp.reset_index()

gdp.loc[:,'NY.GDP.PCAP.KD'] = gdp.loc[:,'NY.GDP.PCAP.KD'].pct_change()

gdp = gdp.loc[pd.to_numeric(gdp.year)<=2012,:].dropna()

gdp_plot = gdp.iloc[::-1,:].hvplot.line(x='year', y='NY.GDP.PCAP.KD', by='country', title='GDP per capita growth (constant 2010
US$)')

gdp_plot

Out[10]:

(http
In [11]: def curves_data_UK(year=1971):

oil_z2 = oil.loc[oil.country=='United Kingdom', 'NY.GDP.PETR.RT.ZS'].iloc[::-1]


oil_z2 = oil_z2 - oil_z2.iloc[0]

money_z2 = money.loc[money.country=='United Kingdom', 'FM.LBL.BMNY.GD.ZS'].iloc[::-1]


money_z2 = money_z2 -money_z2.iloc[0]

z_2 = oil_z2.iloc[year-1971] -10

z_1= money_z2.iloc[year-1971]-10

as_eq = pd.DataFrame([P(), AS(P=P(), Z_2=0)], index=['Price-Level','Real Output']).T


ad_eq = pd.DataFrame([P(), AD(P=P(), Z_1=0)], index=['Price-Level','Real Output']).T

as_shock = pd.DataFrame([P(), AS(P=P(), Z_2=z_2+10)], index=['Price-Level','Real Output']).T


ad_shock = pd.DataFrame([P(), AD(P=P(), Z_1=z_1+10)], index=['Price-Level','Real Output']).T

result = findIntersection(lambda x: AS(P=x, Z_2=z_2+10), lambda x: AD(P=x, Z_1=-z_1-10), 0.0)


r = result + 1e-4 if result==0 else result

plot = hv.Curve(as_eq, vdims='Price-Level',kdims='Real Output').options(alpha=0.2, color='#1BB3F5') *\


hv.Curve(ad_eq, vdims='Price-Level',kdims='Real Output').options(alpha=0.2, color='orange') *\
hv.Curve(as_shock, vdims='Price-Level',kdims='Real Output', label='AS').options(alpha=1, color='#
1BB3F5') *\
hv.Curve(ad_shock, vdims='Price-Level',kdims='Real Output', label='AD').options(alpha=1, color='o
range') *\
hv.VLine(-result[0]).options(color='black', alpha=0.2, line_width=1) *\
hv.HLine(AS(P=-r[0], Z_2=-z_2-10)).options(color='black', alpha=0.2, line_width=1)

gdp_mean = gdp.loc[gdp.country=='United Kingdom', 'NY.GDP.PCAP.KD'].iloc[0]


gdp_iqr = iqr(gdp.loc[gdp.country=='United Kingdom', 'NY.GDP.PCAP.KD'])

gdp_plot_UK = gdp.loc[gdp.country=='United Kingdom',:].iloc[::-1,:].hvplot.line(x='year', y='NY.GDP.PCAP.KD', title='GDP pe


r capita growth (constant 2010 US$)') *\
hv.VLine(year).options(color='black') * pd.DataFrame([[(AD(P=r[0], Z_1=z_1+10)*gdp_iqr*0.35+2.5*gdp_mean), year]], columns=
['Real Output', 'year']).hvplot.scatter(y='Real Output', x='year',color='red')

return plot.options(xticks=[0], yticks=[0], title_format="UK Short-Run AS-AD Model") + gdp_plot_UK


In [12]: %%opts Curve [width=400, height=400]

hv.DynamicMap(curves_data_UK, kdims=['year'], label="UK Short-Run AS-AD Model")\


.redim.range(year=(1971,2007))

Out[12]:
year: 1971
(https://bokeh.pydata.org/)

year:

1971
In [13]: def curves_data_US(year=1971):

oil_z2 = oil.loc[oil.country=='United States', 'NY.GDP.PETR.RT.ZS'].iloc[::-1]


oil_z2 = oil_z2 - oil_z2.iloc[0]

money_z2 = money.loc[money.country=='United States', 'FM.LBL.BMNY.GD.ZS'].iloc[::-1]


money_z2 = money_z2 -money_z2.iloc[0]

z_2 = oil_z2.iloc[year-1971] -10

z_1= -money_z2.iloc[year-1971]-10

as_eq = pd.DataFrame([P(), AS(P=P(), Z_2=0)], index=['Price-Level','Real Output']).T


ad_eq = pd.DataFrame([P(), AD(P=P(), Z_1=0)], index=['Price-Level','Real Output']).T

as_shock = pd.DataFrame([P(), AS(P=P(), Z_2=z_2+10)], index=['Price-Level','Real Output']).T


ad_shock = pd.DataFrame([P(), AD(P=P(), Z_1=z_1+10)], index=['Price-Level','Real Output']).T

result = findIntersection(lambda x: AS(P=x, Z_2=z_2+10), lambda x: AD(P=x, Z_1=-z_1-10), 0.0)


r = result + 1e-4 if result==0 else result

plot = hv.Curve(as_eq, vdims='Price-Level',kdims='Real Output').options(alpha=0.2, color='#1BB3F5') *\


hv.Curve(ad_eq, vdims='Price-Level',kdims='Real Output').options(alpha=0.2, color='orange') *\
hv.Curve(as_shock, vdims='Price-Level',kdims='Real Output', label='AS').options(alpha=1, color='#
1BB3F5') *\
hv.Curve(ad_shock, vdims='Price-Level',kdims='Real Output', label='AD').options(alpha=1, color='o
range') *\
hv.VLine(-result[0]).options(color='black', alpha=0.2, line_width=1) *\
hv.HLine(AD(P=-r[0], Z_1=z_1+10)).options(color='black', alpha=0.2, line_width=1)

gdp_mean = gdp.loc[gdp.country=='United States', 'NY.GDP.PCAP.KD'].iloc[0]


gdp_iqr = iqr(gdp.loc[gdp.country=='United States', 'NY.GDP.PCAP.KD'])

gdp_plot_US = gdp.loc[gdp.country=='United States',:].iloc[::-1,:].hvplot.line(x='year', y='NY.GDP.PCAP.KD', title='GDP per


capita growth (constant 2010 US$)') *\
hv.VLine(year).options(color='black') * pd.DataFrame([[(AD(P=-r[0], Z_1=-z_1-10))*gdp_iqr*0.3+gdp_mean*4, year]], columns=[
'Real Output', 'year']).hvplot.scatter(y='Real Output', x='year',color='red')

return plot.options(xticks=[0], yticks=[0], title_format="US Short-Run AS-AD Model") + gdp_plot_US


In [14]: %%opts Curve [width=400, height=400]

hv.DynamicMap(curves_data_US, kdims=['year'], label="US Short-Run AS-AD Model")\


.redim.range(year=(1971,2007))

Out[14]:
year: 1971
(https://bokeh.pydata.org/)

year:

1971
In [15]: def curves_data_CAN(year=1971):

oil_z2 = oil.loc[oil.country=='Canada', 'NY.GDP.PETR.RT.ZS'].iloc[::-1]


oil_z2 = oil_z2 - oil_z2.iloc[0]

money_z2 = money.loc[money.country=='Canada', 'FM.LBL.BMNY.GD.ZS'].iloc[::-1]


money_z2 = money_z2 -money_z2.iloc[0]

z_2 = oil_z2.iloc[year-1971] -10

z_1= -money_z2.iloc[year-1971]-10

as_eq = pd.DataFrame([P(), AS(P=P(), Z_2=0)], index=['Price-Level','Real Output']).T


ad_eq = pd.DataFrame([P(), AD(P=P(), Z_1=0)], index=['Price-Level','Real Output']).T

as_shock = pd.DataFrame([P(), AS(P=P(), Z_2=z_2+10)], index=['Price-Level','Real Output']).T


ad_shock = pd.DataFrame([P(), AD(P=P(), Z_1=z_1+10)], index=['Price-Level','Real Output']).T

result = findIntersection(lambda x: AS(P=x, Z_2=z_2+10), lambda x: AD(P=x, Z_1=-z_1-10), 0.0)


r = result + 1e-4 if result==0 else result

plot = hv.Curve(as_eq, vdims='Price-Level',kdims='Real Output').options(alpha=0.2, color='#1BB3F5') *\


hv.Curve(ad_eq, vdims='Price-Level',kdims='Real Output').options(alpha=0.2, color='orange') *\
hv.Curve(as_shock, vdims='Price-Level',kdims='Real Output', label='AS').options(alpha=1, color='#
1BB3F5') *\
hv.Curve(ad_shock, vdims='Price-Level',kdims='Real Output', label='AD').options(alpha=1, color='o
range') *\
hv.VLine(-result[0]).options(color='black', alpha=0.2, line_width=1) *\
hv.HLine(AD(P=-r[0], Z_1=z_1+10)).options(color='black', alpha=0.2, line_width=1)

gdp_mean = gdp.loc[gdp.country=='Canada', 'NY.GDP.PCAP.KD'].iloc[0]


gdp_iqr = iqr(gdp.loc[gdp.country=='Canada', 'NY.GDP.PCAP.KD'])

gdp_plot_US = gdp.loc[gdp.country=='Canada',:].iloc[::-1,:].hvplot.line(x='year', y='NY.GDP.PCAP.KD', title='GDP per capita


growth (constant 2010 US$)') *\
hv.VLine(year).options(color='black') * pd.DataFrame([[(AD(P=-r[0], Z_1=-z_1-10))*gdp_iqr*0.3+gdp_mean*4, year]], columns=[
'Real Output', 'year']).hvplot.scatter(y='Real Output', x='year',color='red')

return plot.options(xticks=[0], yticks=[0], title_format="Canada Short-Run AS-AD Model") + gdp_plot_US


In [16]: %%opts Curve [width=400, height=400]

hv.DynamicMap(curves_data_CAN, kdims=['year'], label="Canada Short-Run AS-AD Model")\


.redim.range(year=(1971,2007))

Out[16]:
year: 1971
(https://bokeh.pydata.org/)

year:

1971
In [17]: def curves_data_ZAF(year=1971):

oil_z2 = oil.loc[oil.country=='South Africa', 'NY.GDP.PETR.RT.ZS'].iloc[::-1]


oil_z2 = oil_z2 - oil_z2.iloc[0]

money_z2 = money.loc[money.country=='South Africa', 'FM.LBL.BMNY.GD.ZS'].iloc[::-1]


money_z2 = money_z2 -money_z2.iloc[0]

z_2 = oil_z2.iloc[year-1971] -10

z_1= -money_z2.iloc[year-1971]-10

as_eq = pd.DataFrame([P(), AS(P=P(), Z_2=0)], index=['Price-Level','Real Output']).T


ad_eq = pd.DataFrame([P(), AD(P=P(), Z_1=0)], index=['Price-Level','Real Output']).T

as_shock = pd.DataFrame([P(), AS(P=P(), Z_2=z_2+10)], index=['Price-Level','Real Output']).T


ad_shock = pd.DataFrame([P(), AD(P=P(), Z_1=z_1+10)], index=['Price-Level','Real Output']).T

result = findIntersection(lambda x: AS(P=x, Z_2=z_2+10), lambda x: AD(P=x, Z_1=-z_1-10), 0.0)


r = result + 1e-4 if result==0 else result

plot = hv.Curve(as_eq, vdims='Price-Level',kdims='Real Output').options(alpha=0.2, color='#1BB3F5') *\


hv.Curve(ad_eq, vdims='Price-Level',kdims='Real Output').options(alpha=0.2, color='orange') *\
hv.Curve(as_shock, vdims='Price-Level',kdims='Real Output', label='AS').options(alpha=1, color='#
1BB3F5') *\
hv.Curve(ad_shock, vdims='Price-Level',kdims='Real Output', label='AD').options(alpha=1, color='o
range') *\
hv.VLine(-result[0]).options(color='black', alpha=0.2, line_width=1) *\
hv.HLine(AD(P=-r[0], Z_1=z_1+10)).options(color='black', alpha=0.2, line_width=1)

gdp_mean = gdp.loc[gdp.country=='South Africa', 'NY.GDP.PCAP.KD'].iloc[0]


gdp_iqr = iqr(gdp.loc[gdp.country=='South Africa', 'NY.GDP.PCAP.KD'])

gdp_plot_US = gdp.loc[gdp.country=='South Africa',:].iloc[::-1,:].hvplot.line(x='year', y='NY.GDP.PCAP.KD', title='GDP per


capita growth (constant 2010 US$)') *\
hv.VLine(year).options(color='black') * pd.DataFrame([[(AD(P=-r[0], Z_1=-z_1-10))*gdp_iqr*0.3+gdp_mean*4, year]], columns=[
'Real Output', 'year']).hvplot.scatter(y='Real Output', x='year',color='red')

return plot.options(xticks=[0], yticks=[0], title_format="South Africa Short-Run AS-AD Model") + gdp_plot_US


In [18]: %%opts Curve [width=400, height=400]

hv.DynamicMap(curves_data_ZAF, kdims=['year'], label="South Africa Short-Run AS-AD Model")\


.redim.range(year=(1971,2007))

Out[18]:
year: 1971
(https://bokeh.pydata.org/)

year:

1971
In [19]: def curves_data_MEX(year=1971):

oil_z2 = oil.loc[oil.country=='Mexico', 'NY.GDP.PETR.RT.ZS'].iloc[::-1]


oil_z2 = oil_z2 - oil_z2.iloc[0]

money_z2 = money.loc[money.country=='Mexico', 'FM.LBL.BMNY.GD.ZS'].iloc[::-1]


money_z2 = money_z2 -money_z2.iloc[0]

z_2 = oil_z2.iloc[year-1971] -10

z_1= -money_z2.iloc[year-1971]-10

as_eq = pd.DataFrame([P(), AS(P=P(), Z_2=0)], index=['Price-Level','Real Output']).T


ad_eq = pd.DataFrame([P(), AD(P=P(), Z_1=0)], index=['Price-Level','Real Output']).T

as_shock = pd.DataFrame([P(), AS(P=P(), Z_2=z_2+10)], index=['Price-Level','Real Output']).T


ad_shock = pd.DataFrame([P(), AD(P=P(), Z_1=z_1+10)], index=['Price-Level','Real Output']).T

result = findIntersection(lambda x: AS(P=x, Z_2=z_2+10), lambda x: AD(P=x, Z_1=-z_1-10), 0.0)


r = result + 1e-4 if result==0 else result

plot = hv.Curve(as_eq, vdims='Price-Level',kdims='Real Output').options(alpha=0.2, color='#1BB3F5') *\


hv.Curve(ad_eq, vdims='Price-Level',kdims='Real Output').options(alpha=0.2, color='orange') *\
hv.Curve(as_shock, vdims='Price-Level',kdims='Real Output', label='AS').options(alpha=1, color='#
1BB3F5') *\
hv.Curve(ad_shock, vdims='Price-Level',kdims='Real Output', label='AD').options(alpha=1, color='o
range') *\
hv.VLine(-result[0]).options(color='black', alpha=0.2, line_width=1) *\
hv.HLine(AD(P=-r[0], Z_1=z_1+10)).options(color='black', alpha=0.2, line_width=1)

gdp_mean = gdp.loc[gdp.country=='Mexico', 'NY.GDP.PCAP.KD'].iloc[0]


gdp_iqr = iqr(gdp.loc[gdp.country=='Mexico', 'NY.GDP.PCAP.KD'])

gdp_plot_US = gdp.loc[gdp.country=='Mexico',:].iloc[::-1,:].hvplot.line(x='year', y='NY.GDP.PCAP.KD', title='GDP per capita


growth (constant 2010 US$)') *\
hv.VLine(year).options(color='black') * pd.DataFrame([[(AD(P=-r[0], Z_1=-z_1-10))*gdp_iqr*0.3+gdp_mean*4, year]], columns=[
'Real Output', 'year']).hvplot.scatter(y='Real Output', x='year',color='red')

return plot.options(xticks=[0], yticks=[0], title_format="Mexico Short-Run AS-AD Model") + gdp_plot_US


In [20]: %%opts Curve [width=400, height=400]

hv.DynamicMap(curves_data_MEX, kdims=['year'], label="Mexico Short-Run AS-AD Model")\


.redim.range(year=(1971,2007))

Out[20]:
year: 1971
(https://bokeh.pydata.org/)

year:

1971

Linear Regression of Model


In [21]: df= pd.merge(pd.merge(oil,money),gdp).dropna()

In [22]: df.columns=['country', 'year', 'oil_rent', 'money','gdp']


In [23]: X=df[['oil_rent','money']]
y=df['gdp']

In [24]: from sklearn.model_selection import train_test_split


from sklearn.metrics import r2_score, mean_squared_error
import statsmodels.api as sm

C:\Users\ganes\Anaconda3\lib\site-packages\statsmodels\compat\pandas.py:56: FutureWarning: The pandas.core.datetools module is


deprecated and will be removed in a future version. Please use the pandas.tseries module instead.
from pandas.core import datetools

In [25]: X_train, X_test, y_train, y_test= train_test_split(X,y)

In [26]: X_train_with_const= sm.add_constant(X_train)

model=sm.OLS(y_train,X_train_with_const).fit()

prediction=model.predict(sm.add_constant(X_test))

Model Summary & Application in Risk Management


Model has very low mean squared error for prediction in GDP. It shows that model has covariance in predicted and actual GDP values. Fit that model provided for the given
data has low Adjusted R Sqaure.

Standard Error and Mean squared error shows that there is signification level of covariance in predicated real GDP and actual Real GSP.

While hedging the risk on trade these macroeconomic indicators can give more insight and help in hedging the risk. One of application is for investment banks on commodities
business where trader has positon for client deal for 1o years and he/she wants to hedge the risk for the tenor where these economic factors can help him/her to hedge the
risk on deal.

In [27]: mean_squared_error(y_test,prediction)

Out[27]: 0.0005211661107057653
In [28]: model.summary()

Out[28]:
OLS Regression Results

Dep. Variable: gdp R-squared: 0.002

Model: OLS Adj. R-squared: -0.013

Method: Least Squares F-statistic: 0.1403

Date: Sun, 16 Dec 2018 Prob (F-statistic): 0.869

Time: 22:54:57 Log-Likelihood: 312.67

No. Observations: 139 AIC: -619.3

Df Residuals: 136 BIC: -610.5

Df Model: 2

Covariance Type: nonrobust

coef std err t P>|t| [0.025 0.975]

const -0.0131 0.002 -5.970 0.000 -0.017 -0.009

oil_rent -7.858e-05 0.002 -0.041 0.967 -0.004 0.004

money -0.0009 0.002 -0.529 0.598 -0.004 0.002

Omnibus: 25.074 Durbin-Watson: 2.073

Prob(Omnibus): 0.000 Jarque-Bera (JB): 35.241

Skew: 0.963 Prob(JB): 2.23e-08

Kurtosis: 4.540 Cond. No. 1.33

You might also like