{ "cells": [ { "cell_type": "code", "execution_count": null, "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 datetime import date" ] }, { "cell_type": "code", "execution_count": null, "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)})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "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.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" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Implied SS\n", "implied_ss = ((new_index.index_pv().bond_price - new_index.accrued()) -\n", " ((new_index.K[1]-new_index.K[0]) * result.price[0] +\n", " (new_index.K[2]-new_index.K[1]) * result.price[1] +\n", " (new_index.K[3]-new_index.K[2]) * result.price[2]))/(new_index.K[4] - new_index.K[3])\n", "implied_ss" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Build previous series skew to price this new series\n", "base_index = TrancheBasket(index_type, series-2, \"5yr\")\n", "base_index.tweak()\n", "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" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }