{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import curve_trades as ct\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "from ipywidgets import widgets\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "w = widgets.Dropdown(\n", " options=['IG', 'EU'],\n", " value='IG',\n", " description='Index:',\n", " disabled=False,\n", ")\n", "w" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "index = w.value" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#On the run spread differences\n", "spreads_diff = ct.curve_spread_diff(index, 6)\n", "spreads_diff.plot()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Table of Spread Differences, and Z-score of current spread differences\n", "ct.spreads_diff_table(spreads_diff)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Theta per unit duration\n", "ct.theta_matrix_by_series(index)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#on the run theta\n", "ct.on_the_run_theta(index)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Curve Trade returns\n", "ct.curve_returns()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ct.cross_series_curve(index)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Theta with 3-5-10 Strategy\n", "df = ct.ratio_within_series(param='duration')\n", "ct.curve_3_5_10(df)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Theta with 5-10 Strategy\n", "df = ct.ratio_within_series(param='duration')\n", "ct.curve_5_10(df)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Relative Spread Difference\n", "spread_ratio = ct.ratio_within_series(param = 'closespread')\n", "spread_ratio.groupby(level = ['date']).last()['closespread_ratio_to_5yr'].plot()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model = ct.curve_model('5yr', '10yr')\n", "model_results = ct.curve_model_results(model[0], model[1])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Scenario Anslysis on current position\n", "report_date = (pd.datetime.today() - pd.offsets.BDay(1)).normalize()\n", "curve_pos = ct.curve_pos(report_date)\n", "origpv = curve_pos.pv" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "flat_curve = ct.curve_shape(report_date, percentile = .05)\n", "for ind in curve_pos.indices:\n", " ind.spread = flat_curve((pd.to_datetime(ind.end_date) - trade_date).days/365)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#PNL in flattening to a 5% case\n", "curve_pos.pv - origpv" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = ct.forward_spread(index)\n", "df.plot()\n", "plt.ylabel('spread')\n", "plt.xlabel('forward spread start date')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = ct.spot_forward(index)\n", "df.plot()\n", "plt.ylabel('spread')" ] }, { "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.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }