aboutsummaryrefslogtreecommitdiffstats
path: root/python/notebooks
diff options
context:
space:
mode:
Diffstat (limited to 'python/notebooks')
-rw-r--r--python/notebooks/Tranche calculator.ipynb125
1 files changed, 125 insertions, 0 deletions
diff --git a/python/notebooks/Tranche calculator.ipynb b/python/notebooks/Tranche calculator.ipynb
new file mode 100644
index 00000000..3b55e4a7
--- /dev/null
+++ b/python/notebooks/Tranche calculator.ipynb
@@ -0,0 +1,125 @@
+{
+ "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\n",
+ "from utils.db import dbconn\n",
+ "from datetime import date\n",
+ "\n",
+ "value_date = (date.today() - pd.offsets.BDay(1)).date()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "index_type = 'HY'\n",
+ "series = 35\n",
+ "tenor = '5yr'\n",
+ "value_date = date.today()\n",
+ "price = 103.875\n",
+ "at_det = [0, 15, 25, 35, 100] if index_type == 'HY' else ['0', '3', '7', '15', '100']\n",
+ "tranche_prices= [41.4, 90.6, 109.6, 119.7]\n",
+ "\n",
+ "#Build another skew to price this new series\n",
+ "base_index = TrancheBasket(\"HY\", 33, \"5yr\")\n",
+ "base_index.tweak()\n",
+ "base_index.build_skew()\n",
+ "skew=base_index.skew"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "results = []\n",
+ "for i in range(3):\n",
+ " #set up\n",
+ " rho_floor = tranche.rho[1] if i > 0 else 0.2\n",
+ " rho_min = rho_floor\n",
+ " rho_max = rho_floor + 0.4\n",
+ " tranche = DualCorrTranche(index_type, series, tenor, attach=at_det[i], detach=at_det[i+1], corr_attach = rho_floor, corr_detach = rho_min + (rho_max -rho_min)/2, tranche_running = 500, value_date=value_date)\n",
+ " tranche._index.tweak([price])\n",
+ " #now loop to find it\n",
+ " for j in range(20):\n",
+ " if tranche.price <= tranche_prices[i]:\n",
+ " rho_min = tranche.rho[1]\n",
+ " else:\n",
+ " rho_max = tranche.rho[1]\n",
+ " tranche.rho[1] = rho_min + (rho_max - rho_min)/2\n",
+ " results.append([tranche.rho[1], tranche.price, tranche.delta, tranche.gamma, tranche.theta(skew=skew), tranche.delta * float(tranche._index.theta())])\n",
+ "ss_corr = tranche.rho[1]\n",
+ "tranche = DualCorrTranche(index_type, series, tenor, attach=at_det[i+1], detach=100, corr_attach = ss_corr, corr_detach = .999, tranche_running = 500, value_date=value_date)\n",
+ "tranche._index.tweak([price])\n",
+ "results.append([tranche.rho[1], tranche.price, tranche.delta, tranche.gamma, tranche.theta(skew=skew), tranche.delta * float(tranche._index.theta())])\n",
+ "results = pd.DataFrame(results, columns = ['corr', 'price', 'delta', 'gamma', 'theta', 'delta * index_theta'])\n",
+ "results['theta_per_delta'] = results['theta'] / results['delta']\n",
+ "results"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#Using another skew\n",
+ "mapped_results = []\n",
+ "for i in range(3):\n",
+ " tranche = DualCorrTranche(index_type, series, tenor, attach=at_det[i], detach=at_det[i+1], corr_attach = np.nan, corr_detach = 0.1, tranche_running = 500, value_date=value_date)\n",
+ " tranche._index.tweak([price])\n",
+ " tranche.mark(skew=skew)\n",
+ " mapped_results.append([tranche.rho[1], tranche.price, tranche.delta, tranche.gamma, tranche.theta(skew=skew), tranche.corr01/tranche.notional])\n",
+ "ss_corr = tranche.rho[1]\n",
+ "tranche = DualCorrTranche(index_type, series, tenor, attach=at_det[i+1], detach=100, corr_attach = ss_corr, corr_detach = .999, tranche_running = 500, value_date=value_date)\n",
+ "tranche._index.tweak([price])\n",
+ "mapped_results.append([tranche.rho[1], tranche.price, tranche.delta, tranche.gamma, tranche.theta(skew=skew), np.nan])\n",
+ "mapped_results = pd.DataFrame(mapped_results, columns = ['corr', 'price', 'delta', 'gamma', 'theta', 'corr01'])\n",
+ "mapped_results['theta_per_delta'] = mapped_results['theta'] / mapped_results['delta']\n",
+ "mapped_results"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3.8.1 64-bit",
+ "language": "python",
+ "name": "python38164bitc40c8740e5d542d7959acb14be96f4f3"
+ },
+ "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
+}