{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# _*Pricing Fixed-Income Assets*_ " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction\n", "\n", "We seek to price a fixed-income asset knowing the distributions describing the relevant interest rates. The cash flows $c_t$ of the asset and the dates at which they occur are known. The total value $V$ of the asset is thus the expectation value of:\n", "\n", "$$V = \\sum_{t=1}^T \\frac{c_t}{(1+r_t)^t}$$\n", "\n", "Each cash flow is treated as a zero coupon bond with a corresponding interest rate $r_t$ that depends on its maturity. The user must specify the distribution modeling the uncertainty in each $r_t$ (possibly correlated) as well as the number of qubits he wishes to use to sample each distribution. In this example we expand the value of the asset to first order in the interest rates $r_t$. This corresponds to studying the asset in terms of its duration.\n", "
\n", "
\n", "The approximation of the objective function follows the following paper:
\n", "Quantum Risk Analysis. Woerner, Egger. 2018." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2020-07-13T23:39:25.388331Z", "start_time": "2020-07-13T23:39:23.208125Z" } }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "import numpy as np\n", "from qiskit import Aer, QuantumCircuit\n", "from qiskit.utils import QuantumInstance\n", "from qiskit.algorithms import IterativeAmplitudeEstimation, EstimationProblem\n", "from qiskit_finance.circuit.library import NormalDistribution" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2020-07-13T23:39:26.366384Z", "start_time": "2020-07-13T23:39:26.362453Z" } }, "outputs": [], "source": [ "backend = Aer.get_backend('statevector_simulator')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Uncertainty Model\n", "\n", "We construct a circuit factory to load a multivariate normal random distribution in $d$ dimensions into a quantum state.\n", "The distribution is truncated to a given box $\\otimes_{i=1}^d [low_i, high_i]$ and discretized using $2^{n_i}$ grid points, where $n_i$ denotes the number of qubits used for dimension $i = 1,\\ldots, d$.\n", "The unitary operator corresponding to the circuit factory implements the following: \n", "$$\\big|0\\rangle_{n_1}\\ldots\\big|0\\rangle_{n_d} \\mapsto \\big|\\psi\\rangle = \\sum_{i_1=0}^{2^n_-1}\\ldots\\sum_{i_d=0}^{2^n_-1} \\sqrt{p_{i_1,...,i_d}}\\big|i_1\\rangle_{n_1}\\ldots\\big|i_d\\rangle_{n_d},$$\n", "where $p_{i_1, ..., i_d}$ denote the probabilities corresponding to the truncated and discretized distribution and where $i_j$ is mapped to the right interval $[low_j, high_j]$ using the affine map:\n", "$$\\{0, \\ldots, 2^{n_{j}}-1\\} \\ni i_j \\mapsto \\frac{high_j - low_j}{2^{n_j} - 1} * i_j + low_j \\in [low_j, high_j].$$\n", "\n", "In addition to the uncertainty model, we can also apply an affine map, e.g. resulting from a principal component analysis. The interest rates used are then given by:\n", "$$\\vec{r} = A * \\vec{x} + b,$$\n", "where $\\vec{x} \\in \\otimes_{i=1}^d [low_i, high_i]$ follows the given random distribution." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2020-07-13T23:39:27.609551Z", "start_time": "2020-07-13T23:39:27.600449Z" } }, "outputs": [], "source": [ "# can be used in case a principal component analysis has been done to derive the uncertainty model, ignored in this example.\n", "A = np.eye(2)\n", "b = np.zeros(2) \n", "\n", "# specify the number of qubits that are used to represent the different dimenions of the uncertainty model\n", "num_qubits = [2, 2]\n", "\n", "# specify the lower and upper bounds for the different dimension\n", "low = [0, 0]\n", "high = [0.12, 0.24]\n", "mu = [0.12, 0.24]\n", "sigma = 0.01*np.eye(2)\n", "\n", "# construct corresponding distribution\n", "bounds = list(zip(low, high))\n", "u = NormalDistribution(num_qubits, mu, sigma, bounds)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2020-07-13T23:39:28.547778Z", "start_time": "2020-07-13T23:39:28.126558Z" }, "tags": [ "nbsphinx-thumbnail" ] }, "outputs": [ { "output_type": "display_data", "data": { "text/plain": "