.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/portfolio/growth/plot_03_cppi.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_portfolio_growth_plot_03_cppi.py: Black and Jones's constant proportion portfolio insurance ========================================================= Fischer Black and Robert Jones (1987) proposed a simple rule for protecting a floor: hold :math:`m` times the *cushion* (wealth above the floor) in stocks and the rest in bonds. When stocks fall the cushion shrinks and so does the exposure, so under continuous trading wealth never touches the floor; Black and Perold (1992) showed the cushion is then a power :math:`m` of the stock price. With discrete rebalancing, a fall of more than :math:`1/m` between trades breaks through the floor: gap risk. .. GENERATED FROM PYTHON SOURCE LINES 16-26 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.integrators import gbm_paths from financialkit.portfolio import cppi, cppi_continuous from financialkit.portfolio.visualizers import plot_cppi mu, sigma, r = 0.07, 0.25, 0.02 times, S = gbm_paths(100.0, mu, sigma, 3.0, 3 * 252, 400, rng=1) .. GENERATED FROM PYTHON SOURCE LINES 27-29 Daily rebalancing with multiplier 4 ----------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 29-33 .. code-block:: Python res = cppi(S, times, floor=0.8, multiplier=4.0, r=r) plot_cppi(res, n_paths=40) .. image-sg:: /api/gallery/portfolio/growth/images/sphx_glr_plot_03_cppi_001.png :alt: CPPI, m = 4: 0.0% of paths breach the floor :srcset: /api/gallery/portfolio/growth/images/sphx_glr_plot_03_cppi_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 34-39 The payoff is convex in the stock --------------------------------- Terminal wealth against the stock's return: the discrete strategy hugs Black and Perold's closed form :math:`F_T + C_0 (S_T/S_0)^m e^{(1-m)(r + m\sigma^2/2)T}`. .. GENERATED FROM PYTHON SOURCE LINES 39-52 .. code-block:: Python exact = cppi_continuous(S, times, sigma, floor=0.8, multiplier=4.0, r=r) fig, ax = plt.subplots(figsize=(7, 4)) x = S[:, -1] / S[:, 0] ax.plot(x, res.wealth[:, -1], ".", ms=4, label="daily CPPI") order = np.argsort(x) ax.plot(x[order], exact[order, -1], "C3", lw=1, label="continuous rebalancing") ax.axhline(res.floor[-1], color="k", ls="--", lw=1, label="floor") ax.set_xlabel("stock gross return S_T / S_0") ax.set_ylabel("terminal wealth") ax.legend() fig.tight_layout() .. image-sg:: /api/gallery/portfolio/growth/images/sphx_glr_plot_03_cppi_002.png :alt: plot 03 cppi :srcset: /api/gallery/portfolio/growth/images/sphx_glr_plot_03_cppi_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 53-55 Gap risk grows with the multiplier and the rebalancing interval --------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 55-65 .. code-block:: Python fig, ax = plt.subplots(figsize=(7, 3.5)) for step, label in [(1, "daily"), (5, "weekly"), (21, "monthly")]: breach = [cppi(S[:, ::step], times[::step], 0.8, m, r).breached.mean() for m in [2, 4, 6, 8, 10]] ax.plot([2, 4, 6, 8, 10], breach, "o-", label=label) ax.set_xlabel("multiplier m") ax.set_ylabel("fraction of paths breaching the floor") ax.legend() fig.tight_layout() plt.show() .. image-sg:: /api/gallery/portfolio/growth/images/sphx_glr_plot_03_cppi_003.png :alt: plot 03 cppi :srcset: /api/gallery/portfolio/growth/images/sphx_glr_plot_03_cppi_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.141 seconds) .. _sphx_glr_download_api_gallery_portfolio_growth_plot_03_cppi.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/portfolio/growth/plot_03_cppi.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_cppi.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_cppi.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_cppi.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_