In [144]:
import numpy as np
import pandas as pd
import csv
import matplotlib as mpl
mpl.rcParams.update({'font.size': 11, 'font.family':'serif'})
from matplotlib.patches import Rectangle
import matplotlib.pyplot as plt
#import seaborn as sns
#sns.set(style="whitegrid", color_codes=True)
In [410]:
import numpy as np
import pandas as pd
import csv
import matplotlib as mpl
mpl.rcParams.update({'font.size': 15, 'font.family':'serif'})
from matplotlib.patches import Rectangle
import matplotlib.pyplot as plt
from scipy.interpolate import UnivariateSpline
sns.set_style("white")
df = pd.read_csv('TAS_bond_shock_10_20.csv')
keys = np.unique(df['shock'])
print keys
for key in keys:
if key == -0.1:
I1 = np.argwhere(df['shock']==key).squeeze()
if key == -0.2:
I2 = np.argwhere(df['shock']==key).squeeze()
x1 = np.array(df['current_step'][I1])
x1new = np.linspace(0, len(x1), num=100)
x2 = np.array(df['current_step'][I2])
x2new = np.linspace(0, len(x1), num=100)
#For -10%
y1 = df['system_TAS'][I1]
y2 = df['system_TAS'][I2]
f1 = UnivariateSpline(x1, y1)
f2 = UnivariateSpline(x2, y2)
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(15,6))
ax[0].plot(x1,y1,'o', x1new,f1(x1new),'--', lw=1, ms=3.5, color='r', label="-10%")
ax[0].plot(x2,y2,'bo', x2new,f2(x2new),'--', lw=1, ms=3.5, label="-20%")
ax[1].plot()
# plt.plot(x1,y1,'o', x1new,f1(x1new),'--', lw=1, ms=3.5, color='r')
# plt.plot(x2,y2,'bo', x2new,f2(x2new),'--', lw=1, ms=3.5)
ax[0].set_xlim(0, 7)
ax[0].set_xlabel("period", fontsize=15)
ax[0].set_ylim(-4e11, 0.1e11)
ax[0].set_ylabel("Asset sales", fontsize=15)
# ax[0].set_ylabel(r"Asset $\delta$ sales", fontsize=12)
ax[0].set_title("Asset sales in response to bond price shock", fontsize=15)
handles, labels = ax[0].get_legend_handles_labels()
p1 = Rectangle((0,0), 1, 1, fc="w")
handles.append(p1)
labels.append(r'RSA bond price shock')
ax[0].legend(handles, labels)
plt.show()
plt.close()
In [179]:
plt.close()
In [390]:
plt.close()
df = pd.read_csv('TAS_bond_shock_10_20.csv')
keys = np.unique(df['shock'])
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(15,6))
for key in keys:
I = np.argwhere(df['shock']==key).squeeze()
#print df['current_step'][I]
# nrows=2, ncols=2,
# ax[0,0] top left
# ax[0,1] top right
# ax[row, col]
#plt.figure('fig 1')
ax[0].plot(df['current_step'][I], df['system_TAS'][I], label="system_TAS %s"%key)
ax[1].plot()
ax[0].set_xlim(0, 7)
ax[0].set_xlabel("period", fontsize=12)
ax[0].set_ylim(-4e11, 0.1e11)
ax[0].set_ylabel(r"Asset $\delta$ sales", fontsize=12)
ax[0].set_title("My title is", fontsize=15)
handles, labels = ax[0].get_legend_handles_labels()
p1 = Rectangle((0,0), 1, 1, fc="w")
handles.append(p1)
labels.append(r'x')
ax[0].legend(handles, labels)
plt.show()
In [148]:
plt.close()
In [ ]:
In [149]:
from scipy.interpolate import interp1d
x = np.linspace(0, 10, num=11, endpoint=True)
y = np.cos(-x**2/9.0)
f = interp1d(x, y)
f2 = interp1d(x, y, kind='cubic')
xnew = np.linspace(0, 10, num=41, endpoint=True)
import matplotlib.pyplot as plt
plt.plot(x, y, 'o', xnew, f(xnew), '-', xnew, f2(xnew), '--')
plt.legend(['data', 'linear', 'cubic'], loc='best')
plt.show()
In [1]:
import matplotlib.pyplot as plt
from scipy import interpolate
x = np.arange(0, 10)
y = np.exp(-x/3.0)
print x, y
f = interpolate.interp1d(x, y)
xnew = np.arange(0, 9, 0.1)
ynew = f(xnew) # use interpolation function returned by `interp1d`
plt.plot(x, y, 'o', xnew, ynew, '-')
plt.show()
In [13]:
import numpy as np
import pandas as pd
from scipy import stats, integrate
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(color_codes=True)
df = pd.read_csv('del_shock.csv')
y = df['deleveraging']
x = y*100
x_filt = x[x<2]
# logx = np.log10(x)
nbins = 1000
n, bins = np.histogram(x_filt, nbins, density=1)
pdfx = np.zeros(n.size)
pdfy = np.zeros(n.size)
for k in range(n.size):
pdfx[k] = 0.5*(bins[k]+bins[k+1])
pdfy[k] = n[k]
plt.plot(pdfx, pdfy)
plt.show()
n, bins = np.histogram(x, nbins, density=1)
pdfx = np.zeros(n.size)
pdfy = np.zeros(n.size)
for k in range(n.size):
pdfx[k] = 0.5*(bins[k]+bins[k+1])
pdfy[k] = n[k]
plt.plot(pdfx, pdfy)
plt.show()
# sns.distplot(x);
In [36]:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
df = pd.read_csv('del_shock.csv')
x = df['deleveraging'] *100
#exclude extreme data
x_filt = x[x<1]
# Histogram:
# Bin it
n, bin_edges = np.histogram(x, 100)
# Normalize it, so that every bins value gives the probability of that bin
bin_probability = n/float(n.sum())
# Get the mid points of every bin
bin_middles = (bin_edges[1:]+bin_edges[:-1])/2.
# Compute the bin-width
bin_width = bin_edges[1]-bin_edges[0]
# Plot the histogram as a bar plot
plt.bar(bin_middles, bin_probability, width=bin_width)
plt.show()
# Histogram:
# Bin it
n, bin_edges = np.histogram(x_filt, 100)
# Normalize it, so that every bins value gives the probability of that bin
bin_probability = n/float(n.sum())
# Get the mid points of every bin
bin_middles = (bin_edges[1:]+bin_edges[:-1])/2.
# Compute the bin-width
bin_width = bin_edges[1]-bin_edges[0]
# Plot the histogram as a bar plot
plt.bar(bin_middles, bin_probability, width=bin_width)
plt.show()
In [331]:
#With seaborn
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import matplotlib as mpl
mpl.rcParams.update({'font.size': 12, 'font.family':'serif'})
df = pd.read_csv('del_shock.csv')
#Drag out columns
x_del = np.array(df['del_effect'])
x_total= np.array(df['total_effect'])
x_total_negative = -1 * x_total
y= np.array(df['shock'])
# #exclude extreme data
# x_filt = x[x<1]
# seaborn.distplot(x_filt, bins=100)
bar_width = 1 # default: 0.8
fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(7,7))
axes.barh(y, x_del, bar_width)
axes.barh(y, x_total_negative, bar_width)
axes.set_xlabel("% of total equity", fontsize=12)
axes.set_ylabel(r"RSA bond price decline in % of initial price", fontsize=15)
axes.set_title("Amplification of asset shocks, RSA Gov bonds", fontsize=15)
plt.legend([' Spillover equity expose, %', ' Direct equity exposure, %'], loc='best')
plt.show()
plt.close()
# plt.show()
# plt.close()
In [344]:
import numpy as np
import pandas as pd
from scipy import stats, integrate
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(color_codes=True)
df = pd.read_csv('del_shock.csv')
y = df['del_effect']
y_filt = y[y<2]
n, bins, patches = plt.hist(y, 100, normed=1, facecolor='g', alpha=0.75)
plt.show()
In [350]:
from scipy.interpolate import interpolate
df = pd.read_csv('test_2.csv')
keys = np.unique(df['shock'])
print keys
for key in keys:
if key == -0.1:
I1 = np.argwhere(df['shock']==key).squeeze()
if key == -0.2:
I2 = np.argwhere(df['shock']==key).squeeze()
x1 = np.array(df['current_step'][I1])
x1new = np.linspace(0, len(x1), num=100)
x2 = np.array(df['current_step'][I2])
x2new = np.linspace(0, len(x1), num=100)
plt.figure('fig 1')
#For -10%
y1 = df['system_TAS'][I1]
y2 = df['system_TAS'][I2]
f1 = interpolate.UnivariateSpline(x1, y1)
f2 = interpolate.UnivariateSpline(x2, y2)
plt.plot(x1,y,'o', x1new,f1(x1new),'--', lw=1, ms=3.5, color='0.8')
plt.plot(x2,y2,'bo', x2new,f2(x2new),'--', lw=1, ms=3.5)
plt.show()
# plt.legend(['data', 'linear'], loc='best')
In [ ]: