diff options
Diffstat (limited to 'python/exploration/VaR.py')
| -rw-r--r-- | python/exploration/VaR.py | 34 |
1 files changed, 1 insertions, 33 deletions
diff --git a/python/exploration/VaR.py b/python/exploration/VaR.py index bb64c314..f578bf84 100644 --- a/python/exploration/VaR.py +++ b/python/exploration/VaR.py @@ -9,7 +9,6 @@ import datetime dawndb = dbengine('dawndb') serenitasdb = dbengine('serenitasdb') - def hist_var(portf, index_type='IG', quantile=.05, years=5): df = index_returns(index=index_type, years=years, tenor=['3yr', '5yr', '7yr', '10yr']) @@ -36,35 +35,4 @@ def hist_var(portf, index_type='IG', quantile=.05, years=5): portf.spread = spreads.spread * (1 + spreads.join(shocks).shocks) r.append((k, portf.pnl)) pnl = pd.DataFrame.from_records(r, columns=['date', 'pnl'], index=['date']) - return pnl.quantile(quantile) * math.sqrt(12) - -def get_pos(report_date, strategy=None): - - df = pd.read_sql_query("SELECT * from list_cds_marks_by_strat(%s)", - dawndb, params=(report_date,)) - if strategy is None: - return df - else: - return df[df['strategy'] == strategy] - -def cleared_cds_margins(report_date=datetime.date.today()): - - df = get_pos(report_date) - - #Cap Allocation for Deltas - percentile = .95 #monthly 90%tile case... - shocks, widen, tighten, onTR_dur, onTR_spread = {}, {}, {}, {}, {} - for ind in ['IG', 'HY', 'EU']: - shocks[ind], onTR_spread[ind], onTR_dur[ind] = rel_spread_diff(report_date, index=ind) - widen[ind] = shocks[ind].quantile(percentile) - tighten[ind] = shocks[ind].quantile(1-percentile) - - df['onTR_notional'] = df.apply(lambda df: - df.notional * df.factor * df.duration / onTR_dur[df.p_index], axis=1) - df['widen'] = df.apply(lambda df: - df.onTR_notional * onTR_spread[df.p_index] * onTR_dur[df.p_index] * widen[df.p_index]/10000, axis=1) - df['tighten'] = df.apply(lambda df: - df.onTR_notional * onTR_spread[df.p_index] * onTR_dur[df.p_index] * tighten[df.p_index]/10000, axis=1) - delta_alloc = df.groupby('strategy').sum() - delta_alloc['total'] = delta_alloc.apply(lambda df: max(abs(df.widen), abs(df.tighten)), axis=1) - return delta_alloc + return pnl.quantile(quantile) * math.sqrt(12)
\ No newline at end of file |
