aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/analytics/tranche_basket.py27
-rw-r--r--python/notebooks/Tranche calculator.ipynb57
2 files changed, 39 insertions, 45 deletions
diff --git a/python/analytics/tranche_basket.py b/python/analytics/tranche_basket.py
index abc91bd7..b16c7217 100644
--- a/python/analytics/tranche_basket.py
+++ b/python/analytics/tranche_basket.py
@@ -1425,5 +1425,28 @@ class MarkitTrancheBasket(TrancheBasket):
class ManualTrancheBasket(TrancheBasket):
"""TrancheBasket with quotes manually provided"""
- def _set_tranche_quotes(self, value_date, tranche_quotes):
- self.tranche_quotes = tranche_quotes
+ def _set_tranche_quotes(self, value_date, ref, quotes):
+ if self.index_type == "HY":
+ detach = [15, 25, 35, 100]
+ elif self.index_type == "IG":
+ detach = [3, 7, 15, 100]
+ elif self.index_type == "EU":
+ detach = [3, 6, 12, 100]
+ else:
+ detach = [10, 20, 35, 100]
+ coupon = 500 if (self.index_type == "HY" or self.index_type == "XO") else 100
+ if self.index_type == "HY":
+ ref_type1 = "indexrefprice"
+ ref_type2 = "indexrefspread"
+ else:
+ ref_type1 = "indexrefspread"
+ ref_type2 = "indexrefprice"
+ self.tranche_quotes = pd.DataFrame(
+ {
+ "detach": np.array(detach),
+ "trancheupfrontmid": np.array(quotes),
+ "trancherunningmid": np.full(4, coupon),
+ ref_type1: np.full(4, ref),
+ ref_type2: np.full(4, None),
+ }
+ )
diff --git a/python/notebooks/Tranche calculator.ipynb b/python/notebooks/Tranche calculator.ipynb
index 8649d43e..394618a3 100644
--- a/python/notebooks/Tranche calculator.ipynb
+++ b/python/notebooks/Tranche calculator.ipynb
@@ -6,14 +6,10 @@
"metadata": {},
"outputs": [],
"source": [
- "import analytics.tranche_basket as bkt\n",
"import pandas as pd\n",
"import numpy as np\n",
- "import matplotlib.pyplot as plt\n",
"\n",
- "from analytics.scenarios import run_tranche_scenarios, run_portfolio_scenarios, run_tranche_scenarios_rolldown\n",
- "from analytics import DualCorrTranche, TrancheBasket, ManualTrancheBasket\n",
- "from utils.db import dbconn\n",
+ "from analytics import TrancheBasket, ManualTrancheBasket\n",
"from datetime import date"
]
},
@@ -23,29 +19,15 @@
"metadata": {},
"outputs": [],
"source": [
- "def build_tranche_quotes(index_type, ref, quotes):\n",
- " if index_type == 'HY':\n",
- " detach = [15, 25, 35, 100] \n",
- " elif index_type == 'IG':\n",
- " detach = [3, 7, 15, 100] \n",
- " elif index_type == 'EU':\n",
- " detach = [3, 6, 12, 100] \n",
- " else:\n",
- " detach = [10, 20, 35, 100]\n",
- " coupon = 500 if (index_type == 'HY' or index_type == 'XO') else 100\n",
- " if index_type == 'HY':\n",
- " ref_type1 = 'indexrefprice'\n",
- " ref_type2 = 'indexrefspread'\n",
- " ref_2 = None\n",
- " else:\n",
- " ref_type1 = 'indexrefspread'\n",
- " ref_type2 = 'indexrefprice'\n",
- " ref_2 = None\n",
- " return pd.DataFrame({\"detach\": np.array(detach), \n",
- " \"trancheupfrontmid\": np.array(quotes), \n",
- " \"trancherunningmid\": np.full(4, coupon),\n",
- " ref_type1: np.full(4, ref),\n",
- " ref_type2: np.full(4, ref_2)})"
+ "def display_result(basket_index):\n",
+ " thetas = basket_index.tranche_thetas()\n",
+ " result = pd.concat([pd.DataFrame(basket_index.rho[0:4], index=thetas.index, columns=['att_corr']),\n",
+ " pd.DataFrame(basket_index.tranche_pvs().bond_price, index=thetas.index, columns=['price']),\n",
+ " basket_index.tranche_deltas(),\n",
+ " thetas],\n",
+ " axis=1)\n",
+ " result['net_theta'] = result.theta - new_index.theta()[0] * result.delta\n",
+ " return result"
]
},
{
@@ -57,17 +39,11 @@
"index_type = 'HY'\n",
"series = 35\n",
"value_date = date.today()\n",
- "df = build_tranche_quotes(index_type, 104.625, [43, 92.5, 110, 120.27])\n",
- "new_index = ManualTrancheBasket(index_type, series, \"5yr\", value_date=value_date, tranche_quotes=df)\n",
+ "new_index = ManualTrancheBasket(index_type, series, \"5yr\", value_date=value_date, ref=104.625, quotes=[43, 92.5, 110, 120.27])\n",
"new_index.tweak()\n",
"new_index.build_skew()\n",
- "result = pd.concat([pd.DataFrame(new_index.rho[0:4], index=new_index.tranche_thetas().index, columns=['att_corr']),\n",
- " pd.DataFrame(new_index.tranche_pvs().bond_price, index=new_index.tranche_thetas().index, columns=['price']),\n",
- " new_index.tranche_deltas(),\n",
- " new_index.tranche_thetas()],\n",
- " axis=1)\n",
- "result['net_theta'] = result.theta - new_index.theta()[0] * result.delta\n",
- "result"
+ "result = display_result(new_index)\n",
+ "result "
]
},
{
@@ -96,12 +72,7 @@
"base_index.build_skew()\n",
"\n",
"new_index.rho = base_index.map_skew(new_index)\n",
- "result = pd.concat([pd.DataFrame(new_index.rho[0:4], index=new_index.tranche_thetas().index, columns=['att_corr']),\n",
- " pd.DataFrame(new_index.tranche_pvs().bond_price, index=new_index.tranche_thetas().index, columns=['price']),\n",
- " new_index.tranche_deltas(),\n",
- " new_index.tranche_thetas()],\n",
- " axis=1)\n",
- "result['net_theta'] = result.theta - new_index.theta()[0] * result.delta\n",
+ "result = display_result(new_index)\n",
"result"
]
},