aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/exploration/curve_trades.py24
1 files changed, 10 insertions, 14 deletions
diff --git a/python/exploration/curve_trades.py b/python/exploration/curve_trades.py
index 3c0a25ad..d17b35ed 100644
--- a/python/exploration/curve_trades.py
+++ b/python/exploration/curve_trades.py
@@ -245,20 +245,18 @@ def spot_forward(index='IG', series=None, tenors=['3yr', '5yr', '7yr', '10yr']):
def curve_pos(trade_date, index='IG'):
'''
- Input trade_date and index
+ trade_date : :class:`datetime.date`
+ index : string
+ one of 'IG', 'HY' or 'ITRX'
+
Returns a Portfolio of curve trades '''
sql_string = "SELECT * FROM cds where trade_date < %s"
df = pd.read_sql_query(sql_string, dawndb, parse_dates=['trade_date', 'maturity'],
params=[trade_date])
- if index is 'IG':
- df = df[df['folder'] == 'SER_IGCURVE']
- elif index is 'HY':
- df = df[df['folder'] == 'SER_HYCURVE']
- else:
- df = df[df['folder'] == 'SER_ITRXCURVE']
- df.notional = df.apply(lambda x: x.notional * -1 if x.protection == 'Buyer' else x.notional, axis = 1)
- df = df.groupby(['security_id', 'maturity']).sum()['notional']
+ df = df[df['folder'] == f'SER_{index}CURVE']
+ df.notional = df.notional.where(df.protection == 'Seller', -df.notional)
+ df = df.groupby(['security_id', 'maturity'])['notional'].sum()
df = df.iloc[df.nonzero()[0]].reset_index()
sql_string = "SELECT * FROM index_maturity LEFT JOIN index_version USING (index, series)"
@@ -270,18 +268,18 @@ def curve_pos(trade_date, index='IG'):
sql_string = "SELECT closespread FROM index_quotes where index = %s and series = %s and tenor = %s and date = %s"
for i, row in df[['index', 'tenor', 'series', 'notional']].iterrows():
temp = Index.from_name(row['index'], row.series, row.tenor)
- temp.value_date = trade_date.date()
+ temp.value_date = trade_date
if row.notional > 0:
temp.direction = 'Seller'
temp.notional = abs(row.notional)
spread_df = pd.read_sql_query(sql_string, serenitasdb,
- params=[row['index'], row.series, row.tenor, trade_date.date()])
+ params=[row['index'], row.series, row.tenor, trade_date])
temp.spread = spread_df.iloc[0][0]
indices.append(temp)
return Portfolio(indices)
-def curve_shape(trade_date, index = 'IG', percentile=.95):
+def curve_shape(trade_date, index='IG', percentile=.95):
'''
Returns a function to linearly interpolate between the curve based on maturity (in years)'''
@@ -302,5 +300,3 @@ def curve_shape(trade_date, index = 'IG', percentile=.95):
df = df.reset_index().merge(lookup_table, on=['tenor'])
df['year_frac'] = (df.maturity - pd.to_datetime(trade_date)).dt.days/365
return interp1d(np.hstack([0, df.year_frac]), np.hstack([0, df.spread]))
-
-