aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/notebooks/HY quote reref.ipynb127
1 files changed, 127 insertions, 0 deletions
diff --git a/python/notebooks/HY quote reref.ipynb b/python/notebooks/HY quote reref.ipynb
new file mode 100644
index 00000000..a4ceb6df
--- /dev/null
+++ b/python/notebooks/HY quote reref.ipynb
@@ -0,0 +1,127 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "jupyter": {
+ "source_hidden": true
+ }
+ },
+ "outputs": [],
+ "source": [
+ "import ipysheet\n",
+ "from analytics import CreditIndex"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "jupyter": {
+ "source_hidden": true
+ }
+ },
+ "outputs": [],
+ "source": [
+ "sheet = ipysheet.sheet(rows=3, columns=4, column_headers=False, row_headers=False)\n",
+ "ipysheet.cell(0, 0, 'indices', read_only=True)\n",
+ "ipysheet.cell(0, 1, 'notionals', read_only=True)\n",
+ "ipysheet.cell(0, 2, 'price', read_only=True)\n",
+ "ipysheet.cell(0, 3, 'newref', read_only=True)\n",
+ "cells = {}\n",
+ "cells[(1, 0)] = ipysheet.cell(1, 0, '', background_color='yellow')\n",
+ "cells[(2, 0)] = ipysheet.cell(2, 0, '', background_color='yellow')\n",
+ "cells[(1, 1)] = ipysheet.cell(1, 1, -10_000_000, read_only=True)\n",
+ "cells[(2, 1)] = ipysheet.cell(2, 1, 10_000_000, background_color='yellow')\n",
+ "cells[(1, 2)] = ipysheet.cell(1, 2, background_color='yellow')\n",
+ "cells[(2, 2)] = ipysheet.cell(2, 2, background_color='yellow')\n",
+ "cells[(1, 3)] = ipysheet.cell(1, 3, background_color='yellow')\n",
+ "cells[(2, 3)] = ipysheet.cell(2, 3, read_only=True)\n",
+ "\n",
+ "indices = {}\n",
+ "def create_indices(change):\n",
+ " global indices\n",
+ " index_str = change['new']\n",
+ " index_type = index_str[:2]\n",
+ " series = int(index_str[2:])\n",
+ " indices[index_str] = CreditIndex(index_type, series, '5yr')\n",
+ "\n",
+ "def change_notional(change):\n",
+ " global indices\n",
+ " index2 = indices[cells[(2, 0)].value]\n",
+ " index1 = indices[cells[(1, 0)].value]\n",
+ " index2.notional = change['new']\n",
+ " index1.notional = -index2.notional * index2.factor * index2.risky_annuity / index1.risky_annuity / index1.factor\n",
+ " cells[(1, 1)].value = index1.notional\n",
+ " \n",
+ "def set_price(change):\n",
+ " global indices, debug\n",
+ " index_str = cells[(change['owner'].row_start, change['owner'].column_start -2)].value\n",
+ " indices[index_str].price = change['new']\n",
+ "\n",
+ "debug = None\n",
+ "def set_new_ref(change):\n",
+ " global indices, debug\n",
+ " index1 = indices[cells[(1, 0)].value]\n",
+ " index2 = indices[cells[(2, 0)].value]\n",
+ " old_price1, old_price2 = index1.price, index2.price\n",
+ " old_pv1 = index1.pv\n",
+ " index1.price = change['new']\n",
+ " pv_change = index1.pv - old_pv1\n",
+ " index2.pv -= pv_change\n",
+ " cells[(2, 3)].value = index2.price\n",
+ " index1.price = old_price1\n",
+ " index2.price = old_price2\n",
+ " \n",
+ "cells[(1, 0)].observe(create_indices, 'value')\n",
+ "cells[(2, 0)].observe(create_indices, 'value')\n",
+ "cells[(2, 1)].observe(change_notional, 'value')\n",
+ "cells[(1, 2)].observe(set_price, 'value')\n",
+ "cells[(2, 2)].observe(set_price, 'value')\n",
+ "cells[(1, 3)].observe(set_new_ref, 'value')\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "jupyter": {
+ "source_hidden": true
+ }
+ },
+ "outputs": [],
+ "source": [
+ "sheet"
+ ]
+ },
+ {
+ "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
+}