Professional Documents
Culture Documents
import holoviews as hv
import hvplot.pandas
In [3]: hv.extension('bokeh')
np.random.seed(42)
Out[7]:
adminregion capitalCity iso3c incomeLevel iso2c latitude lendingType longitude name region
1 South Asia Kabul AFG Low income AF 34.52280 IDA 69.1761 Afghanistan South Asia
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_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
(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):
z_1= money_z2.iloc[year-1971]-10
Out[12]:
year: 1971
(https://bokeh.pydata.org/)
year:
1971
In [13]: def curves_data_US(year=1971):
z_1= -money_z2.iloc[year-1971]-10
Out[14]:
year: 1971
(https://bokeh.pydata.org/)
year:
1971
In [15]: def curves_data_CAN(year=1971):
z_1= -money_z2.iloc[year-1971]-10
Out[16]:
year: 1971
(https://bokeh.pydata.org/)
year:
1971
In [17]: def curves_data_ZAF(year=1971):
z_1= -money_z2.iloc[year-1971]-10
Out[18]:
year: 1971
(https://bokeh.pydata.org/)
year:
1971
In [19]: def curves_data_MEX(year=1971):
z_1= -money_z2.iloc[year-1971]-10
Out[20]:
year: 1971
(https://bokeh.pydata.org/)
year:
1971
model=sm.OLS(y_train,X_train_with_const).fit()
prediction=model.predict(sm.add_constant(X_test))
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
Df Model: 2