aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/pnl_explain.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/python/pnl_explain.py b/python/pnl_explain.py
index 5c0c31ab..cb10516d 100644
--- a/python/pnl_explain.py
+++ b/python/pnl_explain.py
@@ -207,9 +207,13 @@ def get_tranche_pv2(
):
start_date = prev_business_day(start_date)
df = pd.read_sql_query(
- "SELECT date, tranche_id AS id, clean_nav, accrued, folder "
+ "SELECT date, tranche_id AS id, "
+ "clean_nav * (CASE WHEN currency='USD' THEN 1. ELSE eurusd END) AS clean_nav, "
+ "accrued * (CASE WHEN currency='USD' THEN 1. ELSE eurusd END) AS accrued, "
+ "folder "
"FROM tranche_risk "
"JOIN cds ON tranche_id=id "
+ "LEFT JOIN fx USING (date) "
"WHERE date BETWEEN %s and %s AND fund=%s",
conn,
params=(start_date, end_date, fund),
@@ -265,7 +269,10 @@ def get_tranche_pv2(
parse_dates=["date"],
index_col=["date", "id"],
)
+ # force to float in case of empty dataframe (otherwise it's object)
+ df_cashflows = df_cashflows.astype("float")
df_cashflows = principal.to_frame().add(df_cashflows, fill_value=0.0)
+ df_cashflows = df_cashflows.fillna(0.0)
df_cashflows = df_cashflows.rename(columns={"accrued": "realized_accrued"})
return pd.concat([df, df_cashflows], axis=1).join(strategies).sort_index()