{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "\n", "from serenitas.analytics.tranche_basket import TrancheBasket, ManualTrancheBasket, DualCorrTranche\n", "from datetime import date\n", "from copy import deepcopy" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Build previous series skew to price this new series\n", "index_type = 'HY'\n", "new_series = 39\n", "value_date = date.today()\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.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" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#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})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#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" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.9" } }, "nbformat": 4, "nbformat_minor": 4 }