{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# better formatting for large floats\n", "import pandas as pd\n", "pd.options.display.float_format = \"{:,.2f}\".format" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from risk.swaptions import get_swaption_portfolio\n", "import datetime\n", "from utils.db import dbconn\n", "from analytics import init_ontr\n", "import analytics\n", "conn = dbconn('dawndb')\n", "conn.autocommit = True\n", "value_date = datetime.date.today()\n", "init_ontr(value_date)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "portf = get_swaption_portfolio(value_date, conn, source_list=[\"GS\"])\n", "portf" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = portf._todf()\n", "positions = df.set_index(\"Index\")[[\"Delta\", \"Notional\"]].prod(axis=1).groupby(level=\"Index\").sum()\n", "positions.name = 'current_delta'\n", "gamma = df.set_index(\"Index\")[[\"Gamma\", \"Notional\"]].prod(axis=1).groupby(level=\"Index\").sum()\n", "gamma.name = 'gamma'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hedges = pd.read_sql_query(\"SELECT security_desc, notional FROM list_cds_positions_by_strat(%s) \"\n", " \"WHERE folder in ('IGOPTDEL', 'HYOPTDEL')\",\n", " conn, params=(value_date,))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def f(s):\n", " l = s.split(\" \")\n", " return f\"{l[1]}{l[3][1:]} {l[4].lower()}r\"\n", "\n", "hedges[\"Index\"] = hedges[\"security_desc\"].apply(f)\n", "hedges = hedges.rename(columns={\"notional\": \"current hedge\"})\n", "hedges = hedges.set_index(\"Index\")[\"current hedge\"]\n", "hedges = hedges.reindex(positions.index, fill_value=0.)\n", "risk = pd.concat([hedges, positions, gamma], axis=1)\n", "risk['net_delta'] = risk[\"current hedge\"] + risk.current_delta\n", "risk" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "portf.theta" ] }, { "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.1" } }, "nbformat": 4, "nbformat_minor": 4 }