Skip to content

Demo: Estimating Option Price Using Amplitude Estimation

View on GitHub Experiment in the IDE

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)]\)). 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 \(\Omega(1/M^{1/2})\), compared to \(\Omega(1/M)\) in the classical case, where \(M\) 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)=\ \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: \(\mathcal{ln}(S)\sim~\mathcal{N}(\mu,\sigma)\), where \(\mathcal{N}(\mu,\sigma)\) is the standard normal distribution with mean equal to \(\mu\) and sdt equal to \(\sigma\) .

To estimate the average option price using a quantum computer, one needs to:

  • Load the distribution, that is, discretize the distribution using \(2^n\) points (n is the number of qubits) and truncate it.

  • Implement the payoff function that is equal to zero if \(S\leq{K}\) and increases linearly otherwise. The linear part is approximated in order to be loaded properly using \(R_y\) rotations [3].

  • Evaluate the expected payoff using amplitude estimation

The probability distribution

We begin by creating the probability distribution. We use FinanceModelInput, to build discrete version of the log normal probability with \(2^n\) points, when \(\mu\) is equal to mu, \(\sigma\) is equal to sigma and \(n\) is equal to num_qubits.

from classiq.applications.finance import log_normal_model_input

num_qubits = 5
mu = 0.7
sigma = 0.13

log_normal_model = log_normal_model_input.LogNormalModelInput(
    num_qubits=num_qubits, mu=mu, sigma=sigma
)

The option pricing function

We continue with creating the option pricing function . We use FinanceFunctionInput, to build the European call option function, when \(K\) equal to threshold.

from classiq.applications.finance import function_input

threshold = 1.9

condition = function_input.FunctionCondition(threshold=threshold, larger=True)
finance_function = function_input.FinanceFunctionInput(
    f="european call option",
    condition=condition,
)

Loading the model

After defining the probability distribution and the finance function input, we proceed by creating a Model. The Model define the logic flow of the quantum algorithm. In this case, the logic flow includes one Finance operator that loads the distribution and then implements the payoff function, which is plugged into the amplitude estimation algorithm (using phase estimation). We need to define the number of qubits used by the phase estimation algorithm which will set the accuracy of the calculation.

from classiq import construct_finance_model

qmod = construct_finance_model(
    finance_model_input=log_normal_model,
    finance_function_input=finance_function,
    phase_port_size=2,
)

Setting Constraints to the circuit

We set constraints for the number of qubits in order to get an optimized quantum circuit.

from classiq import Constraints
from classiq.synthesis import set_constraints

qmod = set_constraints(qmod, constraints=Constraints(max_width=20))
from classiq import write_qmod

write_qmod(qmod, "option_pricing")

Synthesizing the circuit

Now we are ready to synthesize the circuit using Classiq's synthesis engine. The synthesis should take approximately several seconds:

from classiq import synthesize

qprog = synthesize(qmod)

Showing the Resulting Circuit

After Classiq's synthesis engine has finished the job, we can show the resulting circuit in the interactive GUI:

from classiq import QuantumProgram, show

show(qprog)
Opening: https://platform.classiq.io/circuit/61aad498-f6fd-43f8-8462-fd48b9753de4?version=0.41.0.dev39%2B79c8fd0855
circuit = QuantumProgram.from_qprog(qprog)
print(circuit.transpiled_circuit.depth)
2593

Executing the circuit

Lastly, we can execute the resulting circuit with Classiq's execute interface, using the execute function.

from classiq import execute

results = execute(qprog).result()

Printing out the result estimation of the options price :

print(results[1].name, ":", results[1].value)
estimation : 0.37948482165243613

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).