diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/analytics/curve_trades.py | 21 | ||||
| -rw-r--r-- | python/notebooks/Curve Trades.ipynb | 208 |
2 files changed, 5 insertions, 224 deletions
diff --git a/python/analytics/curve_trades.py b/python/analytics/curve_trades.py index 6c20994d..34fcf72e 100644 --- a/python/analytics/curve_trades.py +++ b/python/analytics/curve_trades.py @@ -265,23 +265,6 @@ def spread_fin_crisis(index="IG"): plt.show() -def forward_spread( - report_date, index="IG", series=None, tenors=["3yr", "5yr", "7yr", "10yr"] -): - - if series is None: - series = on_the_run(index=index) - b_index = MarkitBasketIndex(index, series, tenors, value_date=report_date) - b_index.tweak() - - f_spread = [] - date_range = pd.bdate_range(pd.datetime.today(), max(b_index.maturities), freq="M") - for d in date_range.date: - b_index.value_date = d - f_spread.append(b_index.spread()) - return pd.concat(f_spread, keys=date_range).unstack(-1) - - def spot_forward(index="IG", series=None, tenors=["3yr", "5yr", "7yr", "10yr"]): """ @@ -300,7 +283,7 @@ def spot_forward(index="IG", series=None, tenors=["3yr", "5yr", "7yr", "10yr"]): ) spreads_1yr.name = "1yr" df = pd.concat([spreads_current, spreads_1yr], axis=1) - maturity_1yr = roll_date(b_index.index_desc.issue_date[0], 1) + maturity_1yr = roll_date(b_index.issue_date, 1) df_0 = pd.DataFrame( {"current": [0.0, b_index.spread(maturity_1yr)], "1yr": [0.0, 0.0]}, index=["0yr", "1yr"], @@ -369,7 +352,7 @@ def curve_shape(value_date, index="IG", percentile=0.95, spread=None): ) df = curve_shape[steepness == steepness.quantile(percentile, "nearest")] - df = df * spread / df["5yr"][0] + df = df * spread[0] / df["5yr"][0] df = df.stack().rename("spread") df = df.reset_index().merge(lookup_table, on=["tenor"]) df["year_frac"] = (df.maturity - pd.to_datetime(value_date)).dt.days / 365 diff --git a/python/notebooks/Curve Trades.ipynb b/python/notebooks/Curve Trades.ipynb index d749c74a..159e695d 100644 --- a/python/notebooks/Curve Trades.ipynb +++ b/python/notebooks/Curve Trades.ipynb @@ -54,8 +54,8 @@ "metadata": {}, "outputs": [], "source": [ - "index = w.value\n", - "series = 34 if index == 'IG' else 32\n", + "index = 'IG'\n", + "series = 34 if index == 'IG' else 33\n", "model = ct.curve_model('5yr', '10yr', index=index, max_series=series)\n", "model_results = ct.curve_model_results(model[0], model[1])" ] @@ -85,38 +85,6 @@ "metadata": {}, "outputs": [], "source": [ - "#HY curve trade re-ref calculator - sell protection index_1, buy protection index_2 \n", - "date = datetime.date.today()\n", - "index_type = 'HY'\n", - "series_1 = '29'\n", - "series_2 = '34'\n", - "index_1_trade_price = 104.75\n", - "index_2_trade_price = 104.8\n", - "reref_2 = 104.71\n", - "\n", - "#-----------------------------\n", - "index_1 = CreditIndex(index_type, series_1, '5yr', date)\n", - "index_2 = CreditIndex(index_type, series_2, '5yr', date)\n", - "index_1.price = index_1_trade_price\n", - "index_2.price = index_2_trade_price\n", - "index_2.notional = index_1.notional * index_1.risky_annuity/index_2.risky_annuity\n", - "index_1.direction = 'Seller'\n", - "index_2.direction = 'Buyer'\n", - "past_pv = index_2.pv\n", - "index_2.price = reref_2 \n", - "index_1.pv = -index_1.pv + (index_2.pv - past_pv)\n", - " \n", - "pd.options.display.float_format = '{:,.4f}'.format\n", - "d = {index_type + series_1: [index_1_trade_price, index_1.price , index_1.notional], index_type + series_2: [index_2_trade_price, reref_2, index_2.notional]}\n", - "pd.DataFrame(d, index=['original ref', 're-ref', 'notionals'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ "#On the run spread differences\n", "spreads_diff = curve_spread_diff(index, 6)\n", "spreads_diff.plot()" @@ -286,53 +254,6 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#Do the same regression for Itrxx\n", - "model = ct.curve_model('5yr', '10yr', index='EU')\n", - "model_results = ct.curve_model_results(model[0], model[1])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "model_results['diff'] = model_results['predicted'] - model_results['close_spread']\n", - "model_results" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df = ct.forward_spread(report_date, 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 = df.rename(columns={'1yr': 'Spot Spread - 1 Year Forward', 'current': 'Spot Spread - Today'})\n", @@ -368,19 +289,6 @@ "metadata": {}, "outputs": [], "source": [ - "#plot steepness scenario at current spread\n", - "#df_plot = df.set_index(['spread', 'curve_per'], append=True)\n", - "#df_plot = df_plot.xs(round(spread_df.iloc[0][0], 2), level = 'spread')\n", - "#df_plot.name = 'pnl'\n", - "#g.plot_color_map(df_plot, spread_range)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ "#Plot the shape of the scenario that was run above\n", "ct.plot_curve_shape(report_date)" ] @@ -450,116 +358,6 @@ "scen_table.pnl = scen_table.pnl/navs.iloc[-1].endbooknav *100\n", "scen_table.pivot(index='tighter', columns='wider')" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from exploration.VaR import hist_var\n", - "IG = ct.curve_pos(report_date, 'IG')\n", - "ITRX = ct.curve_pos(report_date, 'EU')\n", - "VaR = hist_var(IG, 'IG') + hist_var(ITRX, 'EU')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -578,7 +376,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.1" + "version": "3.8.5" } }, "nbformat": 4, |
