aboutsummaryrefslogtreecommitdiffstats
path: root/python/notebooks/HY quote reref.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'python/notebooks/HY quote reref.ipynb')
-rw-r--r--python/notebooks/HY quote reref.ipynb58
1 files changed, 29 insertions, 29 deletions
diff --git a/python/notebooks/HY quote reref.ipynb b/python/notebooks/HY quote reref.ipynb
index a4ceb6df..ce3aada0 100644
--- a/python/notebooks/HY quote reref.ipynb
+++ b/python/notebooks/HY quote reref.ipynb
@@ -11,7 +11,8 @@
"outputs": [],
"source": [
"import ipysheet\n",
- "from analytics import CreditIndex"
+ "from analytics import CreditIndex\n",
+ "from functools import partial"
]
},
{
@@ -40,46 +41,45 @@
"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",
+ "def create_indices(indices, i, name):\n",
+ " index_type = name[:2]\n",
+ " series = int(name[2:])\n",
+ " indices[i] = CreditIndex(index_type, series, '5yr', notional=cells[(i, 1)].value)\n",
+ " set_price(indices, i, cells[(i, 2)].value)\n",
+ " change_notional(indices, cells[(2, 1)].value)\n",
+ " set_new_ref(indices, cells[(1, 3)].value)\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",
+ "def change_notional(indices, notional):\n",
+ " index1 = indices[1]\n",
+ " index2 = indices[2]\n",
+ " index2.notional = notional\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",
+ "def set_price(indices, i, price):\n",
+ " indices[i].price = price\n",
+ " change_notional(indices, cells[(2, 1)].value)\n",
+ " set_new_ref(indices, cells[(1, 3)].value)\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",
+ "def set_new_ref(indices, ref):\n",
+ " index1 = indices[1]\n",
+ " index2 = indices[2]\n",
" old_price1, old_price2 = index1.price, index2.price\n",
" old_pv1 = index1.pv\n",
- " index1.price = change['new']\n",
+ " index1.price = ref\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"
+ "\n",
+ "indices = {}\n",
+ "cells[(1, 0)].observe(lambda change: partial(create_indices, indices, 1)(change['new']), 'value')\n",
+ "cells[(2, 0)].observe(lambda change: partial(create_indices, indices, 2)(change['new']), 'value')\n",
+ "cells[(2, 1)].observe(lambda change: partial(change_notional, indices)(change['new']), 'value')\n",
+ "cells[(1, 2)].observe(lambda change: partial(set_price, indices, 1)(change['new']), 'value')\n",
+ "cells[(2, 2)].observe(lambda change: partial(set_price, indices, 2)(change['new']), 'value')\n",
+ "cells[(1, 3)].observe(lambda change: partial(set_new_ref, indices)(change['new']), 'value')\n"
]
},
{