aboutsummaryrefslogtreecommitdiffstats
path: root/python/notebooks
diff options
context:
space:
mode:
Diffstat (limited to 'python/notebooks')
-rw-r--r--python/notebooks/swaption_risk.ipynb49
1 files changed, 49 insertions, 0 deletions
diff --git a/python/notebooks/swaption_risk.ipynb b/python/notebooks/swaption_risk.ipynb
index 97f9a1c9..146b0969 100644
--- a/python/notebooks/swaption_risk.ipynb
+++ b/python/notebooks/swaption_risk.ipynb
@@ -95,6 +95,55 @@
"execution_count": null,
"metadata": {},
"outputs": [],
+ "source": [
+ "import numpy as np\n",
+ "sr = np.linspace(47, 51, 100)\n",
+ "rec= []\n",
+ "for s in sr:\n",
+ " delta = 0.\n",
+ " gamma = 0.\n",
+ " for t in portf.trades:\n",
+ " if t.index.index_type == \"IG\":\n",
+ " t.index.mark(ref=s)\n",
+ " delta += t.delta * t.notional\n",
+ " gamma += t.gamma\n",
+ " rec.append((s, gamma, delta))\n",
+ "df = pd.DataFrame.from_records(rec, columns=['spread', 'gamma', 'delta'])\n",
+ "df = df.set_index('spread')\n",
+ "df.delta += risk.loc['IG33 5yr', 'current hedge']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from matplotlib import pyplot as plt\n",
+ "def get_newaxes(num):\n",
+ " plt.close(num)\n",
+ " fix, axes = plt.subplots(figsize=(10,5), num=num)\n",
+ " return axes\n",
+ "\n",
+ "axes = get_newaxes(1)\n",
+ "df.delta.plot(ax=axes)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "axes = get_newaxes(2)\n",
+ "df.gamma.plot(ax=axes)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": []
}
],