{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Pricing Bull Spreads" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Introduction\n", "
\n", "Suppose a [bull spread](http://www.theoptionsguide.com/bull-call-spread.aspx) with strike prices $K_1 < K_2$ and an underlying asset whose spot price at maturity $S_T$ follows a given random distribution.\n", "The corresponding payoff function is defined as:\n", "\n", "\n", "$$\\min\\{\\max\\{S_T - K_1, 0\\}, K_2 - K_1\\}$$\n", "\n", "\n", "\n", "In the following, a quantum algorithm based on amplitude estimation is used to estimate the expected payoff, i.e., the fair price before discounting, for the option:\n", "\n", "\n", "$$\\mathbb{E}\\left[ \\min\\{\\max\\{S_T - K_1, 0\\}, K_2 - K_1\\} \\right]$$\n", "\n", "\n", "as well as the corresponding $\\Delta$, i.e., the derivative of the option price with respect to the spot price, defined as:\n", "\n", "\n", "$$\n", "\\Delta = \\mathbb{P}\\left[K_1 \\leq S \\leq K_2\\right]\n", "$$\n", "\n", "\n", "The approximation of the objective function and a general introduction to option pricing and risk analysis on quantum computers are given in the following papers:\n", "\n", "- [Quantum Risk Analysis. Woerner, Egger. 2018.](https://arxiv.org/abs/1806.06893)\n", "- [Option Pricing using Quantum Computers. Stamatopoulos et al. 2019.](https://arxiv.org/abs/1905.02666)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "import numpy as np\n", "\n", "from qiskit import Aer\n", "from qiskit.utils import QuantumInstance\n", "from qiskit.algorithms import IterativeAmplitudeEstimation, EstimationProblem\n", "from qiskit.circuit.library import LinearAmplitudeFunction\n", "from qiskit_finance.circuit.library import LogNormalDistribution" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Uncertainty Model\n", "\n", "We construct a circuit factory to load a log-normal random distribution into a quantum state.\n", "The distribution is truncated to a given interval $[\\text{low}, \\text{high}]$ and discretized using $2^n$ grid points, where $n$ denotes the number of qubits used.\n", "The unitary operator corresponding to the circuit factory implements the following: \n", "\n", "$$\\big|0\\rangle_{n} \\mapsto \\big|\\psi\\rangle_{n} = \\sum_{i=0}^{2^n-1} \\sqrt{p_i}\\big|i\\rangle_{n},$$\n", "\n", "where $p_i$ denote the probabilities corresponding to the truncated and discretized distribution and where $i$ is mapped to the right interval using the affine map:\n", "\n", "$$\\{0, \\ldots, 2^n-1\\} \\ni i \\mapsto \\frac{\\text{high} - \\text{low}}{2^n - 1} * i + \\text{low} \\in [\\text{low}, \\text{high}].$$" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# number of qubits to represent the uncertainty\n", "num_uncertainty_qubits = 3\n", "\n", "# parameters for considered random distribution\n", "S = 2.0 # initial spot price\n", "vol = 0.4 # volatility of 40%\n", "r = 0.05 # annual interest rate of 4%\n", "T = 40 / 365 # 40 days to maturity\n", "\n", "# resulting parameters for log-normal distribution\n", "mu = ((r - 0.5 * vol**2) * T + np.log(S))\n", "sigma = vol * np.sqrt(T)\n", "mean = np.exp(mu + sigma**2/2)\n", "variance = (np.exp(sigma**2) - 1) * np.exp(2*mu + sigma**2)\n", "stddev = np.sqrt(variance)\n", "\n", "# lowest and highest value considered for the spot price; in between, an equidistant discretization is considered.\n", "low = np.maximum(0, mean - 3*stddev)\n", "high = mean + 3*stddev\n", "\n", "# construct circuit factory for uncertainty model\n", "uncertainty_model = LogNormalDistribution(num_uncertainty_qubits, mu=mu, sigma=sigma**2, bounds=(low, high))" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "output_type": "display_data", "data": { "text/plain": "