\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": "

",
"image/svg+xml": "\n\n\n\n",
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZEAAAEaCAYAAADQVmpMAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAqJ0lEQVR4nO3de5wcVZ338c+XxAkgJASi4hJCwkWzcVkFQ5RHQJCLQV9LlA0bQHdhFxcvRHARFFdFRHRFFlAfcDESbroKES9PXIMxgoKsiEFAMCRIghAmyCUQiBjIEPJ7/qjq0HR6enr6VlXd3/fr1a/pPnWq6nQR5jvnnLooIjAzM2vEFlk3wMzMisshYmZmDXOImJlZwxwiZmbWMIeImZk1zCFiZmYNyzxEJE2RdL2kdZIel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C/7SIqAyz6cCNEfFEC9pnlgk/Y916mqSICA1dEyR9Bdg9It7Zgv2OAB4EzoiIbzW7PbOseDjLepKkSyX1p+/7JV1ax2rnAQdJek0LmnAUydXuV7dgW2aZcU/EbBgkHQ38KSIq5zeGu51jgFURcVNrWmaWDYeImZk1zMNZZmbWMIeImZk1zCFiZmYNc4iYmVnDHCJmZtYwh4iZmTXMIWJmZg1ziJiZWcP+P8r6cdVlsfe+AAAAAElFTkSuQmCC\n"
},
"metadata": {
"needs_background": "light"
}
}
],
"source": [
"# plot contour of probability density function\n",
"x = np.linspace(low[0], high[0], 2**num_qubits[0])\n",
"y = np.linspace(low[1], high[1], 2**num_qubits[1])\n",
"z = u.probabilities.reshape(2**num_qubits[0], 2**num_qubits[1])\n",
"plt.contourf(x, y, z)\n",
"plt.xticks(x, size=15)\n",
"plt.yticks(y, size=15)\n",
"plt.grid()\n",
"plt.xlabel('$r_1$ (%)', size=15)\n",
"plt.ylabel('$r_2$ (%)', size=15)\n",
"plt.colorbar()\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Cash flow, payoff function, and exact expected value\n",
"\n",
"In the following we define the cash flow per period, the resulting payoff function and evaluate the exact expected value.\n",
"\n",
"For the payoff function we first use a first order approximation and then apply the same approximation technique as for the linear part of the payoff function of the [European Call Option](03_european_call_option_pricing.ipynb)."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2020-07-13T23:39:29.440094Z",
"start_time": "2020-07-13T23:39:29.189392Z"
}
},
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "

",
"image/svg+xml": "\n\n\n\n",
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZgAAAEQCAYAAACN2GLgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAjL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iAifi/pJ8B/SNqBdNZzJmlm2t9Img/8GPgd6ezpk8ALpMRo1hBOMGb98zjwNeAbpCnLC4CTcpenPgM8TPoFfgFpJtcS4Hv1flBErJV0OGmK8fcAAZ3AcbkpygATgf8ALgVWAZeTzmyOz9W5J6s3ipSoFgFHZTd3mjWEl0w26yNJM4C/i4j2VsdiNhB5DMbMzErhBGNmZqXwJTIzMyuFz2DMzKwUTjBmZlYKJxgzMyuFE4yZmZXCCcbMzErx/wGZ8kaxgVRmhgAAAABJRU5ErkJggg==\n"
},
"metadata": {
"needs_background": "light"
}
}
],
"source": [
"# specify cash flow\n",
"cf = [1.0, 2.0]\n",
"periods = range(1, len(cf) + 1)\n",
"\n",
"# plot cash flow\n",
"plt.bar(periods, cf)\n",
"plt.xticks(periods, size=15)\n",
"plt.yticks(size=15)\n",
"plt.grid()\n",
"plt.xlabel('periods', size=15)\n",
"plt.ylabel('cashflow ($)', size=15)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"ExecuteTime": {
"end_time": "2020-07-13T23:39:29.698674Z",
"start_time": "2020-07-13T23:39:29.688947Z"
}
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Exact value: \t2.1942\n"
]
}
],
"source": [
"# estimate real value\n",
"cnt = 0\n",
"exact_value = 0.0\n",
"for x1 in np.linspace(low[0], high[0], pow(2, num_qubits[0])):\n",
" for x2 in np.linspace(low[1], high[1], pow(2, num_qubits[1])):\n",
" prob = u.probabilities[cnt]\n",
" for t in range(len(cf)):\n",
" # evaluate linear approximation of real value w.r.t. interest rates\n",
" exact_value += prob * (cf[t]/pow(1 + b[t], t+1) - (t+1)*cf[t]*np.dot(A[:, t], np.asarray([x1, x2]))/pow(1 + b[t], t+2))\n",
" cnt += 1\n",
"print('Exact value: \\t%.4f' % exact_value)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"ExecuteTime": {
"end_time": "2020-07-13T23:39:30.128058Z",
"start_time": "2020-07-13T23:39:30.124504Z"
}
},
"outputs": [],
"source": [
"# specify approximation factor\n",
"c_approx = 0.125\n",
"\n",
"# get fixed income circuit appfactory\n",
"from qiskit_finance.applications.estimation import FixedIncomePricing\n",
"\n",
"fixed_income = FixedIncomePricing(num_qubits=num_qubits, pca_matrix=A, initial_interests=b, \n",
" cash_flow=cf, rescaling_factor=c_approx, bounds=bounds, \n",
" uncertainty_model=u)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" \n",
"q_0: ───────────────────■──────────────────────────────────────────────────\n",
" │ \n",
"q_1: ───────────────────┼─────────────■────────────────────────────────────\n",
" │ │ \n",
"q_2: ───────────────────┼─────────────┼─────────────■──────────────────────\n",
" │ │ │ \n",
"q_3: ───────────────────┼─────────────┼─────────────┼─────────────■────────\n",
" ┌───────────┐┌─────┴──────┐┌─────┴──────┐┌─────┴─────┐┌──────┴───────┐\n",
"q_4: ┤ RY(9π/16) ├┤ RY(-π/216) ├┤ RY(-π/108) ├┤ RY(-π/27) ├┤ RY(-0.23271) ├\n",
" └───────────┘└────────────┘└────────────┘└───────────┘└──────────────┘"
],
"text/html": "",
"text/html": "### Version Information

"
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": "",
"text/html": "### This code is a part of Qiskit

"
},
"metadata": {}
}
],
"source": [
"import qiskit.tools.jupyter\n",
"%qiskit_version_table\n",
"%qiskit_copyright"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"name": "python3",
"display_name": "Python 3.8.6 64-bit ('opt-qiskit')",
"metadata": {
"interpreter": {
"hash": "9c837c7ac14898b4157c3602a52e89b1bd57ef10d6bdaa28fc65fa6f9116fa6b"
}
}
},
"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.8.6-final"
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 1
}

\nq_0: ───────────────────■──────────────────────────────────────────────────\n │ \nq_1: ───────────────────┼─────────────■────────────────────────────────────\n │ │ \nq_2: ───────────────────┼─────────────┼─────────────■──────────────────────\n │ │ │ \nq_3: ───────────────────┼─────────────┼─────────────┼─────────────■────────\n ┌───────────┐┌─────┴──────┐┌─────┴──────┐┌─────┴─────┐┌──────┴───────┐\nq_4: ┤ RY(9π/16) ├┤ RY(-π/216) ├┤ RY(-π/108) ├┤ RY(-π/27) ├┤ RY(-0.23271) ├\n └───────────┘└────────────┘└────────────┘└───────────┘└──────────────┘" }, "metadata": {}, "execution_count": 8 } ], "source": [ "fixed_income._objective.draw()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " ┌───────┐┌────┐\n", "q_0: ┤0 ├┤0 ├\n", " │ ││ │\n", "q_1: ┤1 ├┤1 ├\n", " │ P(X) ││ │\n", "q_2: ┤2 ├┤2 F ├\n", " │ ││ │\n", "q_3: ┤3 ├┤3 ├\n", " └───────┘│ │\n", "q_4: ─────────┤4 ├\n", " └────┘" ], "text/html": "

┌───────┐┌────┐\nq_0: ┤0 ├┤0 ├\n │ ││ │\nq_1: ┤1 ├┤1 ├\n │ P(X) ││ │\nq_2: ┤2 ├┤2 F ├\n │ ││ │\nq_3: ┤3 ├┤3 ├\n └───────┘│ │\nq_4: ─────────┤4 ├\n └────┘" }, "metadata": {}, "execution_count": 9 } ], "source": [ "fixed_income_circ = QuantumCircuit(fixed_income._objective.num_qubits)\n", "\n", "# load probability distribution\n", "fixed_income_circ.append(u, range(u.num_qubits))\n", "\n", "# apply function\n", "fixed_income_circ.append(fixed_income._objective, range(fixed_income._objective.num_qubits))\n", "\n", "fixed_income_circ.draw()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2020-07-13T23:39:30.566677Z", "start_time": "2020-07-13T23:39:30.561554Z" } }, "outputs": [], "source": [ "# set target precision and confidence level\n", "epsilon = 0.01\n", "alpha = 0.05\n", "\n", "# construct amplitude estimation \n", "qi = QuantumInstance(Aer.get_backend('qasm_simulator'), shots=100)\n", "\n", "problem = fixed_income.to_estimation_problem()\n", "\n", "ae = IterativeAmplitudeEstimation(epsilon, alpha=alpha, quantum_instance=qi)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2020-07-13T23:39:53.292025Z", "start_time": "2020-07-13T23:39:30.882045Z" } }, "outputs": [], "source": [ "result = ae.estimate(problem)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2020-07-13T23:39:53.298201Z", "start_time": "2020-07-13T23:39:53.294221Z" } }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Exact value: \t2.1942\nEstimated value: \t2.3419\nConfidence interval:\t[2.3015, 2.3823]\n" ] } ], "source": [ "conf_int = np.array(result.confidence_interval_processed)\n", "print('Exact value: \\t%.4f' % exact_value)\n", "print('Estimated value: \\t%.4f' % (fixed_income.interpret(result)))\n", "print('Confidence interval:\\t[%.4f, %.4f]' % tuple(conf_int))" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "ExecuteTime": { "end_time": "2020-07-13T23:39:53.845834Z", "start_time": "2020-07-13T23:39:53.687281Z" } }, "outputs": [ { "output_type": "display_data", "data": { "text/plain": "

Qiskit Software | Version |
---|---|

Qiskit | None |

Terra | 0.17.0.dev0+8fd3b2c |

Aer | 0.7.4 |

Ignis | 0.5.2 |

Aqua | None |

IBM Q Provider | 0.11.1 |

System information | |

Python | 3.8.6 (default, Mar 10 2021, 14:41:09) \n[Clang 12.0.0 (clang-1200.0.32.29)] |

OS | Darwin |

CPUs | 8 |

Memory (Gb) | 32.0 |

Sat Mar 27 00:19:01 2021 JST |

© Copyright IBM 2017, 2021.

This code is licensed under the Apache License, Version 2.0. You may

obtain a copy of this license in the LICENSE.txt file in the root directory

of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.

Any modifications or derivative works of this code must retain this

copyright notice, and modified files need to carry a notice indicating

that they have been altered from the originals.