Ejemplo n.º 1
0
#D_jk = sum( delta_i * d_i * MF_i )
df_hedging_set = df_hedging_factor.groupby(['hedging_set_cd'])[['netting_set','asset_cd','asset_class_cd','hedging_set']].first()
df_hedging_set['addon_systematic_k_0Y+'] = ([sum(df_hedging_factor[df_hedging_factor['hedging_set_cd']==hedging_set]
                                           .apply(lambda x: sa_calcs.addon_systematic(x['rho_jk'],x['addon_jk_0Y+']), axis=1))**2
                                           for hedging_set in df_hedging_set.index])  
df_hedging_set['addon_idiosyncratic_k_0Y+'] = ([sum(df_hedging_factor[df_hedging_factor['hedging_set_cd']==hedging_set]
                                           .apply(lambda x: sa_calcs.addon_idiosyncratic(x['rho_jk'],x['addon_jk_0Y+']), axis=1))
                                           for hedging_set in df_hedging_set.index])
df_hedging_set['addon_k_0Y+'] = df_hedging_set.apply(lambda x: math.sqrt(x['addon_systematic_k_0Y+'] + x['addon_idiosyncratic_k_0Y+']), axis=1)
df_hedging_set = (df_hedging_set.join(
                    df_hedging_factor[df_hedging_factor['hedging_factor'].isin(['0Y_1Y','1Y+_5Y','5Y+'])].pivot(index='hedging_set_cd',columns='hedging_factor',values='D_jk')
                    ,how='outer'))
for col in ['0Y_1Y','1Y+_5Y','5Y+']:
    if col not in df_hedging_set.columns: df_hedging_set[col]=0
df_hedging_set.fillna(value=0,axis=1,inplace=True)
df_hedging_set['D_k_ir'] = df_hedging_set.apply(lambda x: sa_calcs.aggregate_effective_notional(x['0Y_1Y'],x['1Y+_5Y'],x['5Y+']), axis=1)
df_hedging_set['SF_k'] = df_hedging_set.apply(lambda x: df_sa_table2_supervisory_parameters.at[x['asset_class_cd'],'Supervisory factor'], axis=1)
df_hedging_set['addon_k_ir'] = df_hedging_set.apply(lambda x: x['D_k_ir'] * x['SF_k'], axis=1)
df_hedging_set['addon_k'] = df_hedging_set['addon_k_ir'] + df_hedging_set['addon_k_0Y+']

print df_hedging_set


#aggregate by asset (asset_cd)
df_asset = df_hedging_set.groupby(['asset_cd'])[['netting_set']].first()
df_asset['addon'] = [sum(df_hedging_set[df_hedging_set['asset_cd']==asset]['addon_k']) for asset in df_asset.index]  
print df_asset

#aggregate by netting_set
#RC: replacement cost
#RC = max{V-C.0}
Ejemplo n.º 2
0
                              axis=1)) for hedging_set in df_hedging_set.index
])
df_hedging_set['addon_k_0Y+'] = df_hedging_set.apply(lambda x: math.sqrt(x[
    'addon_systematic_k_0Y+'] + x['addon_idiosyncratic_k_0Y+']),
                                                     axis=1)
df_hedging_set = (df_hedging_set.join(
    df_hedging_factor[df_hedging_factor['hedging_factor'].isin(
        ['0Y_1Y', '1Y+_5Y', '5Y+'])].pivot(index='hedging_set_cd',
                                           columns='hedging_factor',
                                           values='D_jk'),
    how='outer'))
for col in ['0Y_1Y', '1Y+_5Y', '5Y+']:
    if col not in df_hedging_set.columns: df_hedging_set[col] = 0
df_hedging_set.fillna(value=0, axis=1, inplace=True)
df_hedging_set['D_k_ir'] = df_hedging_set.apply(
    lambda x: sa_calcs.aggregate_effective_notional(x['0Y_1Y'], x['1Y+_5Y'], x[
        '5Y+']),
    axis=1)
df_hedging_set['SF_k'] = df_hedging_set.apply(
    lambda x: df_sa_table2_supervisory_parameters.at[x['asset_class_cd'],
                                                     'Supervisory factor'],
    axis=1)
df_hedging_set['addon_k_ir'] = df_hedging_set.apply(
    lambda x: x['D_k_ir'] * x['SF_k'], axis=1)
df_hedging_set[
    'addon_k'] = df_hedging_set['addon_k_ir'] + df_hedging_set['addon_k_0Y+']

print df_hedging_set

#aggregate by asset (asset_cd)
df_asset = df_hedging_set.groupby(['asset_cd'])[['netting_set']].first()
df_asset['addon'] = [