This is for the distribution moments. It will write a csv


In [92]:
import numpy as np
import pandas as pd
import matplotlib as mpl
mpl.rcParams.update({'font.size': 15, 'font.family':'serif'})
from matplotlib.patches import Rectangle
import matplotlib.pyplot as plt

df = pd.read_csv('test100.csv')

keys = np.unique(df['current_step'])

for key in keys:
    if key == 0:
        I0 = np.argwhere(df['current_step']==key).squeeze() 
    if key == 1:
        I1 = np.argwhere(df['current_step']==key).squeeze()
    if key == 2:
        I2 = np.argwhere(df['current_step']==key).squeeze()     
    if key == 3:
        I3 = np.argwhere(df['current_step']==key).squeeze()     
    if key == 4:
        I4 = np.argwhere(df['current_step']==key).squeeze()    
    if key == 5: 
        I5 = np.argwhere(df['current_step']==key).squeeze()     
    if key == 6: 
        I6 = np.argwhere(df['current_step']==key).squeeze()
    if key == 7:
        I7 = np.argwhere(df['current_step']==key).squeeze()

period1 = df['system_equity'][I1]
period2 = df['system_equity'][I2]
period3 = df['system_equity'][I3]
period4 = df['system_equity'][I4]
period5 = df['system_equity'][I5]
period6 =  df['system_equity'][I5]
period7 = df['system_equity'][I6]
period8 = df['system_equity'][I7]

list = [period1, period2, period3, period4, period5, period6, period7, period8]


def calc_percentile(array):
    p5 = np.percentile(array, 5) 
    p95 = np.percentile(array, 95)
    pm = np.mean(array)   
    return p5, pm, p95

output = []
for i in list:
    vfunc = np.array(np.array(calc_percentile(i)))
    output.append(vfunc)

print output

df = pd.DataFrame(output)
df.to_csv("1000_moments.csv", index=False, header=False)

# fig = plt.figure()
# ax1 = fig.add_subplot(121)

# for key in keys:    
#     I = np.argwhere(df['current_step']==key).squeeze()

#     ax1.plot(df['current_step'][I], df['system_equity'][I], label="system_Equity")

# plt.show()


# ax1 = fig.add_subplot(121)
# ax1.plot(df['current_step'][I], df['system_Equity'][I], label="system_Equity")
# ax1.set_xlabel('$p$')
# ax1.set_ylabel('$x$')

# nrows=2, ncols=2,
# ax[0,0] top left
# ax[0,1] top right
# ax[row, col]  

    #fig = plt.figure()
#     ax[0].plot(df['current_step'][I], df['system_TAS'][I], label="system_TAS %s"%key)
    
#  ax1 = fig.add_subplot(121)
# ax1.plot(p, data_sorted)
# ax1.set_xlabel('$p$')
# ax1.set_ylabel('$x$')

# ax2 = fig.add_subplot(122)
# ax2.plot(data_sorted, p)
# ax2.set_xlabel('$x$')
# ax2.set_ylabel('$p$')

# plt.show()


[array([  1.62450000e+11,   2.43947695e+11,   3.15150000e+11]), array([  1.18400000e+11,   2.33234735e+11,   3.14150000e+11]), array([  1.08448674e+11,   2.31521482e+11,   3.14150000e+11]), array([  1.06465405e+11,   2.31102857e+11,   3.14150000e+11]), array([  1.06450340e+11,   2.30998812e+11,   3.14150000e+11]), array([  1.06450340e+11,   2.30998812e+11,   3.14150000e+11]), array([  1.05497623e+11,   2.30958177e+11,   3.14150000e+11]), array([  1.05497133e+11,   2.30948071e+11,   3.14150000e+11])]

This is for the actual values per shock simulated:


In [128]:
df = pd.read_csv('test1000.csv')

new_df = df[["system_equity", "shock"]].copy()
numpyMatrix = new_df.as_matrix()

df1 = df.pivot(index='current_step', columns='shock', values='system_equity')
# output = []
# for key in keys2:
#     I = np.argwhere(df['shock']==key).squeeze() 
#     output.append(df['system_equity'][I])  
#     print df['system_equity'][I]

#  shock_array = np.array(df['system_equity'][I])
# df = pd.DataFrame(output)
df1.to_csv("1000_hihishocks.csv")

In [ ]:
df3 = pd.read_csv('1000_plot.csv')

df4 = df3.loc[ : , '5%': ]

col_names=[]
for i in df4.columns:
    col_names.append(str(i))
    
# rows = [df4.loc[  : , :label  ] for label in col_names]
print "hello"
# print rows

# df.plot(x="current_step", y = (df3.loc[ : , '5%': ]))

In [ ]: