Skip to main content

View on GitHub

Open this notebook in GitHub to run it yourself

Introduction and Background

In Finance models we are often interested in calculating the average of a function of a given probability distribution (E[f(x)]E[f(x)]). The most popular method to estimate the average is Monte Carlo [1] due to its flexibility and ability to generically handle stochastic parameters. Classical Monte Carlo methods, however, generally require extensive computational resources to provide an accurate estimation. By leveraging the laws of quantum mechanics, a quantum computer may provide novel ways to solve computationally intensive financial problems, such as risk management, portfolio optimization, and option pricing. The core quantum advantage of several of these applications is the Amplitude Estimation algorithm [2] which can estimate a parameter with a convergence rate of Ω(1/M2)\Omega(1/M^{2}), compared to Ω(1/M)\Omega(1/M) in the classical case, where MM is the number of Grover iterations in the quantum case and the number of the Monte Carlo samples in the classical case. This represents a theoretical quadratic speed-up of the quantum method over classical Monte Carlo methods!

Option Pricing

An option is the possibility to buy (call) or sell (put) an item (or share) at a known price - the strike price (K), where the option has a maturity price (S). The payoff function to describe for example a European call option will be: f(S)= {0,when K≥SS−K,when K<Sf(S)=\ \Bigg\{\begin{array}{lr} 0, & \text{when } K\geq S\\ S - K, & \text{when } K < S\end{array} The maturity price is unknown. Therefore, it is expressed by a price distribution function, which may be any type of a distribution function. For example a log-normal distribution: ln(S)∼ N(μ,σ)\mathcal{ln}(S)\sim~\mathcal{N}(\mu,\sigma), where N(μ,σ)\mathcal{N}(\mu,\sigma) is the standard normal distribution with mean equal to μ\mu and standard deviation equal to σ\sigma .

To Estimate the Average Option Price Using a Quantum Computer, We Need To:

  • Load the distribution, that is, discretize the distribution using 2n2^n points (n is the number of qubits) and truncate it.
  • Implement the payoff function that is equal to zero if S≤KS\leq{K} and increases linearly otherwise.
The linear part is approximated in order to be properly loaded using RyR_y rotations [3].
  • Evaluate the expected payoff using amplitude estimation.
The algorithmic framework is called Quantum Monte-Carlo Integration. For a basic example, see QMCI. Here we use the same framework to estimate european call option, where the underlying asset distribution at the maturity data is modeled as log-normal distribution.

Designing the Quantum Algorithm

In this workshop, we will collaboratively design a quantum algorithm to estimate the price of a European option. This algorithm can be applied to real-world stock data, providing practical results and offering a potential speedup over the classical Monte Carlo method. During the algorithm design process, you will explore state preparation and arithmetics, define Qstructs (quantum classes), and function calling using Classiq? The code in the following section is incomplete, with missing parts that you need to fill in, indicated by “#TODO” in the code description. If you’re unsure how to use a specific Classiq function, please refer to the Classiq documentation and search for the required quantum function to find its corresponding documentation page.

The Probability Distribution

We begin by creating the probability distribution. The distribution is describing the option underlying asset price at maturity date. We will load a discrete version of the log-normal probability with 2n2^n points, when μ\mu of the normal distribution is denoted by mu, σ\sigma by sigma and nn is the number of qubits num_qubits. K, the strike price, is also chosen in this section.
Output:
Output:
output

Quantum Function for Distribution Loading

Here we use the general inplace_prepare_state function. The inplace_prepare_state function is applied instead of prepare_state when a state preparation needs to be repeatedly applied to the same previously initialized quantum variable. We use the genreal purpose state preparation for simplicity. There are more efficient and scalable methods for preparing the required distribution, for example, see [4].

The Payoff Function

We now proceed to load the payoff function. Our end objective is to construct UpayoffU_{payoff}, which satisfies: Upayoff∣S⟩∣0⟩=f(S)∣S⟩∣1⟩+1−f(S)∣S⟩∣0⟩U_{payoff}|S\rangle|0\rangle = \sqrt{f(S)}|S\rangle|1\rangle + \sqrt{1-f(S)}|S\rangle|0\rangle Where ∣S⟩\ket{S} is the quantum state of the maturity price SS (disregarding the prepared probability amplitudes for now) represented by a Qnum variable named ‘asset’ (see note), and the qubit state (∣{⟩0} \ket\{0\} on the LHS) is represented by the ‘ind’ variable, serving as the indicator qubit. Due to the structure of the European option price payoff function, it is easily observed that the state remains unchanged if the maturity price SS is less than the strike price KK. For S≥KS \geq K, on the other hand, a linear amplitude loading is applied to reflect the option’s payoff. *Note: in order to save qubits and depth, the register ∣S⟩n|S\rangle_n will hold a value in the range [0,2n−1][0, 2^{n-1}], effectively “labeling” the asset values. The mapping from the label space to the asset value space (and vice-versa) will occur within the comparator and amplitude loading, using the following (classical) scale/descale functions correspondingly*
For the amplitude loading step, we use a general-purpose loading method utilizing the assign_amplitude_table function. While the calculation is accurate, it is not scalable for large variable sizes. There are more scalable methods, like the ones mentioned in [4], [6]. *See Quantum Types in documentation (under Qmod reference) for Qstruct definition Important: To ensure that the sum of all loaded amplitudes does not exceed 1, we normalize the payoff using a scaling_factor, which will later be multiplied during the post-processing stage.

Wrapping to an Amplitude Estimation Model

After defining the probability distribution and the payoff function, we pack it into a grover_operator. Both stages completed so far contribute to the state preparation process that precedes the successive applications of the Grover operator, an operator used to amplify the amplitudes of specific states corresponding to a desired output. A Grover operator consists of two components: a phase oracle, which is used to distinguish between ‘good’ state and ‘bad’ states, and a diffusion operator, which reflects the states about the mean axis (usually achieved by some state preparation successively followed by a reflection about the ∣0⟩\ket{0} state). In our case, the oracle function Of=∣x⟩→(−1)f(x)∣x⟩O_f=\ket{x} \rightarrow (-1)^{f(x)}\ket{x} is quite simple, and only needs to flip the sign when the indicator qubit is in the ∣{⟩1} \ket\{1\} state (meaning f(1)=1,  f(0)=0f(1)=1,\; f(0)=0) After the initial probability and payoff loading, iterations of the Grover operator are applied within the Iterative Quantum Amplitude Estimation algorithm [5], which is a generalization of the Grover search algorithm, utilized for the estimation of the amplitude aa to arbitrary precision, given the state (now taking the prepared probability amplitudes into account): ∣Ψ⟩=∑x∣x⟩[p(x)f(x)∣1⟩ind+p(x)(1−f(x))∣0⟩ind]=a∣Ψ1⟩+1−a∣Ψ0⟩|\Psi\rangle = \sum_x|x\rangle[\sqrt{p(x)f(x)}|1\rangle_{ind} + \sqrt{p(x)(1-f(x))}|0\rangle_{ind}]=\sqrt{a}|\Psi_1\rangle + \sqrt{1-a}|\Psi_0\rangle Which approximates the expectation value of the payoff (after a post-processing step): a=∑xp(x)f(x)≈E[f]pa = \sum_xp(x)f(x) \approx E[f]_p

Quantum Program Synthesis

After we finished the model design, we synthesize the model to a quantum program.
Output:

Quantum Program Execution

Finally, we execute with defined parameters for the accuracy of the amplitude estimation. This will affect the expected number of grover of repetitions within the execution, which is generally O(N)O(\sqrt{N}):

Post Processing

In order to get the expected payoff, we need to descale the measured amplitude by scaling_factor.
Output:

Compare to the Expected Calculated Payoff

Output:

References

[1]: Paul Glasserman, Monte Carlo Methods in Financial Engineering. Springer-Verlag New York, 2003, p. 596.
[2]: Gilles Brassard, Peter Hoyer, Michele Mosca, and Alain Tapp, Quantum Amplitude Amplification and Estimation. Contemporary Mathematics 305 (2002)

[3]: Nikitas Stamatopoulos, Daniel J. Egger, Yue Sun, Christa Zoufal, Raban Iten, Ning Shen, and Stefan Woerner, Option Pricing using Quantum Computers, Quantum 4, 291 (2020).

[4]: Chakrabarti, Shouvanik, et al. “A threshold for quantum advantage in derivative pricing.” Quantum 5 (2021): 463.

[5]: Grinko, D., Gacon, J., Zoufal, C. et al. Iterative quantum amplitude estimation. npj Quantum Inf 7, 52 (2021)

[6]: Francesca Cibrario et al., Quantum Amplitude Loading for Rainbow Options Pricing. Preprint