aboutsummaryrefslogtreecommitdiffstats
path: root/python/notebooks/Tranche calculator.ipynb
blob: 13b0b1947196f156a845ec9f97caf327e6d3a24a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
{
 "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
}