aboutsummaryrefslogtreecommitdiffstats
path: root/python/risk/portfolio.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/risk/portfolio.py')
-rw-r--r--python/risk/portfolio.py57
1 files changed, 31 insertions, 26 deletions
diff --git a/python/risk/portfolio.py b/python/risk/portfolio.py
index afc71852..41b8ea2e 100644
--- a/python/risk/portfolio.py
+++ b/python/risk/portfolio.py
@@ -28,16 +28,43 @@ def hy_equiv_trade(value_date, notional):
)
+def gen_bond_proxies(position_date, fund, conn):
+ rmbs_pos = subprime_risk(position_date, conn, dbengine("rmbs_model"), fund=fund)
+ crt_pos = crt_risk(position_date, conn, fund=fund)
+ with dbconn("etdb") as etconn:
+ clo_pos = clo_risk(position_date, conn, etconn, fund=fund)
+
+ for name, position in zip(
+ (
+ "rmbs_bonds",
+ "crt_bonds",
+ "clo_bonds",
+ ),
+ (
+ rmbs_pos,
+ crt_pos,
+ clo_pos,
+ ),
+ ):
+ if not position.empty:
+ yield name, -position.get("hy_equiv", np.zeros(1)).sum()
+
+
def build_portfolio(position_date, value_date, fund="SERCGMAST"):
"""
Output two portfolios:
1) All synthetic + curve with just delta-proxy + dummy index as cash bonds proxy (portf)
- 2) All synthetic (portf_syn)
+ 2) Tranches + Index without Swaption Delta for JTD
"""
Trade.init_ontr(value_date)
with dawn_pool.connection() as conn:
portf = get_tranche_portfolio(position_date, conn, False, [fund])
+ syn_portf = deepcopy(portf)
+ syn_portf += get_index_portfolio(
+ position_date, conn, fund, exclude_strategies="%OPTDEL"
+ )
+
swaption_portf = get_swaption_portfolio(position_date, conn, fund=fund)
swaption_portf.trade_ids = [tid[:-1] for tid in swaption_portf.trade_ids]
portf += swaption_portf
@@ -56,7 +83,6 @@ def build_portfolio(position_date, value_date, fund="SERCGMAST"):
("CASH_BASIS", "negate_basis_trades"),
)
- syn_portf = deepcopy(portf)
portf += nocurve_portf
curve_portf.value_date = value_date
curve_portf.mark()
@@ -65,30 +91,9 @@ def build_portfolio(position_date, value_date, fund="SERCGMAST"):
("curve_trades", "curve_trades"),
)
- if not curve_portf:
- syn_portf = nocurve_portf
- else:
- syn_portf += curve_portf + nocurve_portf
-
- # get bond risks:
- rmbs_pos = subprime_risk(position_date, conn, dbengine("rmbs_model"), fund=fund)
- crt_pos = crt_risk(position_date, conn, fund=fund)
- portf.add_trade(
- hy_equiv_trade(value_date, -rmbs_pos.get("hy_equiv", np.zeros(1)).sum()),
- ("rmbs_bonds", "rmbs_bonds"),
- )
- portf.add_trade(
- hy_equiv_trade(value_date, -crt_pos.get("hy_equiv", np.zeros(1)).sum()),
- ("crt_bonds", "crt_bonds"),
- )
- with dbconn("etdb") as etconn:
- clo_pos = clo_risk(position_date, conn, etconn, fund=fund)
-
- if clo_pos is not None:
- portf.add_trade(
- hy_equiv_trade(value_date, -clo_pos["hy_equiv"].sum()),
- ("clo_bonds", "clo_bonds"),
- )
+ # Add the bond proxies to the portfolio only
+ for name, notional in gen_bond_proxies(position_date, fund, conn):
+ portf.add_trade(hy_equiv_trade(value_date, notional), (name, name))
for p in [portf, syn_portf]:
p.value_date = value_date