aboutsummaryrefslogtreecommitdiffstats
path: root/python/pnl_explain.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/pnl_explain.py')
-rw-r--r--python/pnl_explain.py38
1 files changed, 27 insertions, 11 deletions
diff --git a/python/pnl_explain.py b/python/pnl_explain.py
index 45704538..b874c82f 100644
--- a/python/pnl_explain.py
+++ b/python/pnl_explain.py
@@ -14,6 +14,7 @@ from typing import Tuple, Union
def get_index_pv(
start_date: datetime.date,
end_date: datetime.date,
+ fund: str,
conn: connection,
strategies: Union[Tuple[str], None] = None,
):
@@ -32,14 +33,14 @@ def get_index_pv(
accrued -= amount * t.notional * t.factor * t.fixed_rate * 1e-4
else:
accrued = 0.0
- portf = get_index_portfolio(prev_day, conn, strategies)
+ portf = get_index_portfolio(prev_day, conn, fund, strategies)
nav = 0.0
with conn.cursor() as c:
try:
c.execute(
"SELECT upfront, currency FROM cds WHERE trade_date=%s "
- "AND folder in %s",
- (prev_day, strategies),
+ "AND folder in %s AND fund=%s",
+ (prev_day, strategies, fund),
)
except SyntaxError as e:
conn.reset()
@@ -92,7 +93,11 @@ def get_swaption_pv(
def get_tranche_pv(
- start_date: datetime.date, end_date: datetime.date, conn: connection, **kwargs
+ start_date: datetime.date,
+ end_date: datetime.date,
+ fund: str,
+ conn: connection,
+ **kwargs
):
dr = pd.bdate_range(start_date, end_date, freq=bus_day)
pv = []
@@ -102,6 +107,7 @@ def get_tranche_pv(
prev_day = (d - bus_day).date()
if previous_twentieth(d, roll=True) == d.date():
amount = cds_accrued(prev_day, 1.0, True)
+ accrued = 0.0
for t in portf.trades:
accrued -= (
amount
@@ -113,15 +119,15 @@ def get_tranche_pv(
)
else:
accrued = 0.0
- portf = get_tranche_portfolio(prev_day, conn, **kwargs)
+ portf = get_tranche_portfolio(prev_day, conn, fund=fund, **kwargs)
nav = 0.0
# add terminations
with conn.cursor() as c:
c.execute(
"SELECT termination_fee, currency "
"FROM terminations JOIN cds USING (dealid) "
- "WHERE termination_date=%s AND dealid LIKE 'SCCDS%%' ",
- (prev_day,),
+ "WHERE termination_date=%s AND dealid LIKE 'SCCDS%%' AND fund=%s",
+ (prev_day, fund),
)
for (fee, currency) in c:
nav += fee * get_fx(prev_day, currency)
@@ -130,8 +136,8 @@ def get_tranche_pv(
c.execute(
"SELECT upfront, currency "
"FROM cds WHERE trade_date=%s AND swap_type='CD_INDEX_TRANCHE' "
- "AND fund='SERCGMAST'",
- (prev_day,),
+ "AND fund=%s",
+ (prev_day, fund),
)
for (fee, currency) in c:
nav += fee * get_fx(prev_day, currency)
@@ -143,7 +149,7 @@ def get_tranche_pv(
def get_pv(**kwargs):
- if (pnl_type := kwargs.pop("pnl_type")) == "swaption":
+ if kwargs.pop("pnl_type") == "swaption":
return get_swaption_pv(**kwargs)
else:
return get_tranche_pv(**kwargs)
@@ -181,6 +187,14 @@ if __name__ == "__main__":
dest="pnl_type",
help="instrument for which we want the pnl (one of 'tranche' or 'swaption')",
)
+ parser.add_argument(
+ "-f",
+ "--fund",
+ action="store",
+ default="SERCGMAST",
+ dest="fund",
+ help="fund we run the pnl for",
+ )
args = parser.parse_args()
swaption_strats = ("IGOPTDEL", "HYOPTDEL")
tranche_strats = ("IGINX", "HYINX", "XOINX")
@@ -188,7 +202,9 @@ if __name__ == "__main__":
index_strats = tranche_strats
else:
index_strats = swaption_strats
- df_index = get_index_pv(args.start_date, args.end_date, dawndb, index_strats)
+ df_index = get_index_pv(
+ args.start_date, args.end_date, args.fund, dawndb, index_strats
+ )
df_instrument = get_pv(conn=dawndb, **vars(args))