diff options
Diffstat (limited to 'python/notebooks/Tranche calculator.ipynb')
| -rw-r--r-- | python/notebooks/Tranche calculator.ipynb | 67 |
1 files changed, 44 insertions, 23 deletions
diff --git a/python/notebooks/Tranche calculator.ipynb b/python/notebooks/Tranche calculator.ipynb index fb30d134..13b0b194 100644 --- a/python/notebooks/Tranche calculator.ipynb +++ b/python/notebooks/Tranche calculator.ipynb @@ -9,8 +9,9 @@ "import pandas as pd\n", "import numpy as np\n", "\n", - "from analytics import TrancheBasket, ManualTrancheBasket\n", - "from datetime import date" + "from serenitas.analytics.tranche_basket import TrancheBasket, ManualTrancheBasket, DualCorrTranche\n", + "from datetime import date\n", + "from copy import deepcopy" ] }, { @@ -19,13 +20,23 @@ "metadata": {}, "outputs": [], "source": [ + "#Build previous series skew to price this new series\n", "index_type = 'HY'\n", - "series = 35\n", + "new_series = 39\n", "value_date = date.today()\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 = ManualTrancheBasket(index_type, new_series, \"5yr\", \n", + " value_date=value_date, \n", + " ref=102.625, \n", + " quotes=[40, 94.5, 108.5, 117.36])\n", "new_index.tweak()\n", - "new_index.build_skew()\n", - "new_index " + "new_index.build_skew() \n", + "new_index.implied_ss()\n", + "base_index = TrancheBasket(index_type, new_series-2, \"5yr\")\n", + "base_index.tweak()\n", + "base_index.build_skew()\n", + "\n", + "new_index.rho = base_index.map_skew(new_index)\n", + "new_index" ] }, { @@ -34,7 +45,24 @@ "metadata": {}, "outputs": [], "source": [ - "new_index.implied_ss()" + "#Tranchelet pricer\n", + "index = 'EU'\n", + "value_date = date.today()\n", + "orig_tranche = DualCorrTranche(index, 32, '5yr', attach=0, detach=3, corr_attach=.45, \n", + " corr_detach=.55, tranche_running=100, \n", + " value_date=value_date, notional=10000000, use_trunc=True)\n", + "orig_tranche.mark()\n", + "tranchelet = DualCorrTranche(index, 32, '5yr', attach=0, detach=1, corr_attach=0, \n", + " corr_detach=.1, tranche_running=100, \n", + " value_date=value_date, notional=10000000, use_trunc=True)\n", + "tranchelet.mark(**{'ref':34.0})\n", + "tranchelet_flat = deepcopy(tranchelet)\n", + "tranchelet_flat.rho[1] = orig_tranche.rho[1]\n", + "print({'extrapolated price': tranchelet.price, \n", + " 'flat price':tranchelet_flat.price, \n", + " 'extrapolated corr':tranchelet.rho[1],\n", + " 'flat corr': tranchelet_flat.rho[1],\n", + " 'corr 01': tranchelet_flat.corr01[1]/tranchelet.notional})" ] }, { @@ -43,26 +71,19 @@ "metadata": {}, "outputs": [], "source": [ - "#Build previous series skew to price this new series\n", - "base_index = TrancheBasket(index_type, series-4, \"5yr\")\n", - "base_index.tweak()\n", - "base_index.build_skew()\n", - "\n", - "new_index.rho = base_index.map_skew(new_index)\n", - "new_index" + "#Tranchelet pricer: price the missing piece of tranchlet if extrapolated\n", + "tranchelet_stub = DualCorrTranche(index, 32, '5yr', attach=1, detach=3, \n", + " corr_attach=0,\n", + " corr_detach=.1, tranche_running=100, \n", + " value_date=value_date, notional=10000000, use_trunc=True)\n", + "tranchelet_stub.rho=np.array([tranchelet.rho[1], tranchelet_flat.rho[1]])\n", + "tranchelet_stub" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -76,7 +97,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.5" + "version": "3.10.9" } }, "nbformat": 4, |
