diff options
Diffstat (limited to 'python/exploration')
| -rw-r--r-- | python/exploration/VaR.py | 30 |
1 files changed, 7 insertions, 23 deletions
diff --git a/python/exploration/VaR.py b/python/exploration/VaR.py index 09446591..bb64c314 100644 --- a/python/exploration/VaR.py +++ b/python/exploration/VaR.py @@ -33,35 +33,19 @@ def hist_var(portf, index_type='IG', quantile=.05, years=5): for k, g in returns.groupby(level='date', as_index=False): shocks = g.reset_index('date', drop=True).stack('tenor') shocks.name = 'shocks' - portf.spread = spreads.spread * (1 + spreads.join(shocks).shocks) - r.append((k, portf.pnl)) + 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 rel_spread_diff(report_date=datetime.date.today(), index='HY', rolling=10): - otr = on_the_run(index) - ## look at spreads - df = get_index_quotes(index, list(range(otr - rolling, otr + 1)), - tenor=['3yr', '5yr', '7yr', '10yr'], years=5) - - duration = df.duration.xs((report_date, '5yr', otr), level=['date', 'tenor', 'series'])[-1] - - df = df.xs('5yr', level='tenor')['closespread'].groupby(['date']).last() - df = df.loc['2013-01-15':report_date] - curr_spread = df.iloc[-1] - df = df.pct_change(freq='22B').dropna() - - return df.groupby('date').last(), curr_spread, duration - - def get_pos(report_date, strategy=None): - if strategy is None: - return pd.read_sql_query("SELECT * from list_cds_marks(%s)", + + 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 pd.read_sql_query("SELECT * from list_cds_marks(%s, %s)", - dawndb, params=(report_date, strategy)) + return df[df['strategy'] == strategy] def cleared_cds_margins(report_date=datetime.date.today()): |
