aboutsummaryrefslogtreecommitdiffstats
path: root/python/exploration
diff options
context:
space:
mode:
Diffstat (limited to 'python/exploration')
-rw-r--r--python/exploration/tranches.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/python/exploration/tranches.py b/python/exploration/tranches.py
index 2de7e53c..663daf25 100644
--- a/python/exploration/tranches.py
+++ b/python/exploration/tranches.py
@@ -28,33 +28,35 @@ def rv_calc1():
#Read existing results, find which ones need to run
try:
- results = pd.read_csv("/home/serenitas/edwin/Python/rv_" + index + str(series) + ".csv", parse_dates=['date'], index_col=['date'])
+ results = pd.read_csv(f"/home/serenitas/edwin/Python/rv_{index}{series}.csv",
+ parse_dates=['date'], index_col=['date'])
except IOError:
results = pd.DataFrame()
sql_string = "select distinct date from risk_numbers_new where index = %s and series = %s order by date desc"
- df = pd.read_sql_query(sql_string, engine,params=(index, series), parse_dates=['date'])
- df1 = pd.read_sql_query(sql_string, engine,params=(index, series2), parse_dates=['date'])
+ df = pd.read_sql_query(sql_string, engine, params=(index, series), parse_dates=['date'])
+ df1 = pd.read_sql_query(sql_string, engine, params=(index, series2), parse_dates=['date'])
df = df.merge(df1, on=['date'])
df = df[~df.date.isin(results.index)]
rho_tlp, pv_tlp, rho_prev_index, pv_prev_index = [], [], [], []
+ tranche = bkt.TrancheBasket('IG', series, '5yr')
+ tranche2 = bkt.TrancheBasket('IG', series2, '5yr')
+
for trade_date in df.date:
- tranche = bkt.TrancheBasket('IG', series, '5yr', trade_date=trade_date)
+ tranche.trade_date = trade_date
+ tranche2.trade_date = trade_date
tranche.build_skew()
- tranche1 = bkt.TrancheBasket('IG', series, '5yr', trade_date=trade_date)
- tranche1.cs = tranche1.cs[:-shortened]
- tranche1.rho = tranche.map_skew(tranche1, method)
- _, _, pv = tranche1.tranche_pvs()
- rho_tlp.append(tranche1.rho[~np.isnan(tranche1.rho)])
+ tranche.rho = tranche.map_skew(tranche, method, 4)
+ pv = tranche1.tranche_pvs().bond_price
+ rho_tlp.append(tranche.rho[1:-1])
pv_tlp.append(pv)
- tranche2 = bkt.TrancheBasket('IG', series2, '5yr', trade_date=trade_date)
tranche2.build_skew()
- rho_prev_index.append(tranche2.rho[~np.isnan(tranche2.rho)])
+ rho_prev_index.append(tranche2.rho[1:-1])
tranche1.rho = tranche2.rho
- _, _, pv = tranche1.tranche_pvs()
+ pv = tranche1.tranche_pvs(shortened=4).bond_price
pv_prev_index.append(pv)
temp1 = pd.DataFrame(rho_tlp, index=df.date, columns=['3_rho_tlp','7_rho_tlp','15_rho_tlp'])