Quantum Monte Carlo simulations for financial risk analytics: scenario generation for equity, rate, and credit risk factors

Monte Carlo (MC) simulations are widely used in financial risk management, from estimating value-at-risk (VaR) to pricing over-the-counter derivatives. However, they come at a significant computational cost due to the number of scenarios required for convergence. If a probability distribution is available, Quantum Amplitude Estimation (QAE) algorithms can provide a quadratic speed-up in measuring its properties as compared to their classical counterparts. Recent studies have explored the calculation of common risk measures and the optimisation of QAE algorithms by initialising the input quantum states with pre-computed probability distributions. If such distributions are not available in closed form, however, they need to be generated numerically, and the associated computational cost may limit the quantum advantage. In this paper, we bypass this challenge by incorporating scenario generation -- i.e. simulation of the risk factor evolution over time to generate probability distributions -- into the quantum computation; we refer to this process as Quantum MC (QMC) simulations. Specifically, we assemble quantum circuits that implement stochastic models for equity (geometric Brownian motion), interest rate (mean-reversion models), and credit (structural, reduced-form, and rating migration credit models) risk factors. We then integrate these models with QAE to provide end-to-end examples for both market and credit risk use cases.


Introduction
Several papers have been published recently that demonstrate how quantum algorithms can significantly speed up the solution of typical numerical problems in quantitative finance (for reviews, see [1][2][3][4][5][6][7]).In the area of financial risk management, applications include calculating value-atrisk and expected shortfall [8][9][10], pricing of options [11][12][13][14][15] and collateralised debt obligations [16], credit valuation adjustments [17,18], and calculating Greeks [19].While the current state of quantum computing hardware is years away from being used in production systems, theoretical advances on the development and implementation of quantum algorithms are necessary to prepare financial institutions for the transition.The so-called Noisy Intermediate-Scale Quantum (NISQ) technology is considered to outperform current classical computers in the limit of 50-100 qubits ("Intermediate-Scale") and shallow circuit depths ("Noisy", i.e. due to gate errors stacking up) [20].In this paper we consider fault-tolerant quantum devices; namely, we focus on the representation of stochastic models by quantum gates ignoring the effect of quantum errors.

Monte Carlo simulations
Financial risk management applications estimate the likelihood and size of potential losses due to hypothetical future events, such as the adverse move of equity prices, interest rates, credit spreads, or foreign exchange rates (market risk), the default of a debt instrument (credit risk), and the default of a counterparty (counterparty credit risk).The risk is generally represented by a statistical measure that depends on the properties of the underlying risk factors.A typical calculation consists of the following three stages: i) gen-erating a probability distribution P (X t ) of the risk factor vector X t at a future time t, ii) defining a risk measure F (X t ) as a function of X t , and iii) employing a statistical method to estimate its value. 1 For example, consider the value V t of a portfolio consisting of q shares of a given stock, with S 0 its price at t = 0. Here, X t is onedimensional with its only element being S t .The price and volatility of the stock can be used as inputs to model the evolution of S t and generate a distribution P (S t ).Suppose we define our risk measure as the expected value of the portfolio at time t, E(V t ) = qE(S t ); then, we can estimate E(V t ) with either analytical or numerical methods.Apart from special cases where closed-form expressions are available, the probabilistic nature of the risk factor evolution often requires repeated random sampling followed by statistical estimation -this type of numerical approach is called Monte Carlo (MC) simulation.
Financial risk management calculations that rely on MC simulations often require 10,000 to 1,000,000 experiments to achieve the desired precision.This relatively-slow convergence can be understood by considering the following example: suppose we want to estimate the probability p of a random variable X that takes the value X = 1 with p and the value X = 0 with 1 − p.In an MC simulation the experiment is repeated N times, obtaining N 1 observations of the outcome X = 1 and N 0 of the outcome X = 0, with N 1 +N 0 = N .This is a binomial distribution with the expected value of the number of occurrences of X = 1 being N1 = pN and the standard deviation being δN 1 = [p(1 − p)N ] 1/2 .Since N 1 is known but not p, we can invert the expressions to approximate p based on the observed outcomes: From the second equation we can infer that the precision of the estimate is inversely proportional to the square root of N .

Quantum Amplitude Estimation algorithms
Equation (2) implies that, in order to improve the precision by a decimal digit, classical algorithms require 100 times more experiments; therefore, typical values of N are between 10, 000-1, 000, 000.In quantum computing (see App.A for an introduction and definitions), it has been shown that Quantum Amplitude Estimation (QAE) algorithms can achieve a quadratic speed-up as compared to classical algorithms [21].
For the example of Sect.1.1, we can estimate the probability p with a quantum computer by encoding the probability distribution of the random variable in the quantum state of a qubit: such that the state |1⟩ is measured with probability p.However, repeating this quantum experiment multiple times (each one called a shot) and measuring the outcomes does not bypass the classical constraint: the precision would again be proportional to the square root of the number of shots as in Eq. (2).Instead, the quadratic gain of QAE algorithms is achieved by leveraging quantum interference.Specifically, consider an input qubit initialised in the superposition of Eq. (3) and a quantum register of n output qubits.The QAE algorithm is based on phase kickback and quantum amplitude estimation [21].Essentially, the probability p -i.e. the angle θ (Eq. 3) -is imprinted as a phase ϕ = ±kθ onto the output qubits, where k takes the values 2 0 , 2 2 , ..., 2 n−1 for the output qubits labelled 0, 1, ..., n − 1, respectively.This operation is then followed by an inverse quantum Fourier transform which, through interference, converts these phases to a binary number; this enables to directly read off the angle θ and hence the value of p.With this approach, the estimated value of p and its error are (see Sect. 1.4.4): where N = 2 n is the number of possible outcomes, and, notably, δp scales as the inverse of N .

Paper motivation and structure
The majority of QAE papers on financial risk have studied quantum circuits with pre-computed probability distributions of the random variables, P (X t ).However, unless we can exactly encode them in a quantum state, algorithms that involve Monte Carlo integration for state preparation [22] may not be sufficiently efficient to preserve the quadratic speed-up [23].When such distributions are readily available, there are approaches to efficiently load them on a quantum register [e.g.[24][25][26], as well as to simplify state preparation and optimise circuits which can help reduce circuit complexity [13,27].However, if P (X t ) is not given in closed form, an MC simulation is needed to generate the distribution numerically with a classical computer.In these cases, even though QAE algorithms can measure its properties with a quadratic speed-up, the computational cost to generate P (X t ) -associated with the slow convergence of classical algorithms -is paid upfront.This challenge can be bypassed by incorporating scenario generation into the quantum circuit.In a single shot, the exact distribution of a random variable can be represented as a superposition of quantum states.By avoiding loading pre-computed distributions, this approach also reduces the dependence on classical computers, including the data transfer between classical and quantum systems.In this context, this paper focuses on the quantum implementation of stochastic risk models to generate risk factor scenarios -we refer to this process as QMC simulations. 2The resulting distributions are then combined with QAE gates to provide end-to-end example circuits.We study the main risk factor groups -equities, rates, and credit -but not exchange rates as they rely on similar models and/or can be derived from interest rates.Depending on the complexity of the stochastic differential equations that describe the evolution of risk factors, theoretical studies have shown that MC simulations can be further optimised by leveraging quantum-accelerated multilevel MC methods [28][29][30].Here, we limit our scope to assembling QMC circuits for the foundational stochastic models -i.e.geometric Brownian motion, mean-reversion models, Poisson processes, and multinomial trees -as most risk models are based on these or a variation thereof. 3he paper is structured as follows.Section 1.4 presents the main steps of QAE algorithms and their implementation in quantum circuits.In Sect.2, we assemble quantum circuits to perform QMC simulations, namely to model the evolution of equity (Sect.2.1), interest rate (Sect.2.2), and credit (Sect.2.3) risk factors.Section 3 estimates the number of qubits and the resulting circuit depth needed in typical financial risk use cases.We conclude in Sect. 4.

Overview of QAE circuits
where D is the gate that generates the input distribution using m "risk factor" qubits (the focus of this paper), M the controlled gate that encodes the risk measure into the angle θ of the risk measure qubit, Q the repeated application of the controlled gate Q to imprint θ onto the phases of the n output qubits, and QFT/QFT † the quantum Fourier transformation and its inverse to measure the phase of the output qubits with interference.These circuit components are described below in more detail, see Table 1 for state notation.
The m qubits, |0⟩ ⊗m rf , can model a discrete probability distribution of 2 m possible outcomes, each one with a probability |a j | 2 , with j ∈ {0, 1, ..., 2 m − 1}.We use the gate D to load the distribution of X t onto the "risk factor" qubits, which can be depicted as: and expressed mathematically as: where j is an integer in the decimal number system representing the binary number b jm−1 ...b j1 b j0 , and b jl ∈ {0, 1} is the l-th digit of the j-th state.If the distribution is precomputed, it can be loaded by leveraging Quantum Generative Adversarial Networks [24] or Fourier expansion [25], among other approaches [26,27].Here, the distributions will be generated with quantum gates that implement stochastic models for the risk factor evolution.
With the distribution P (X t ) encoded in the state of the "risk factor" qubits, |ψ⟩ rf , the next step is to encode a risk measure f (X t ) -for example a probability such as p = P (X t < K) where K ∈ [X min , X max ] -in the state of the "risk measure" qubit, |0⟩ rm .The value of p can be captured in the angle θ of a qubit with the help of a controlled gate M that reads the distribution |ψ⟩ rf and encodes p ∈ This can be represented as: and described by the expression: where Fig. 1 shows the multipliers (1 − 4p) 2 and (3 − 4p) 2 which increase/decrease the probabilities of measuring |0⟩ rm and |1⟩ rm , respectively. 6A key property of Q is that it leaves the states: unchanged when applied k times, but introduces a global phase (see App. B.2): Phase kickback We can exploit this property by implementing a controlled gate Q acting on |ψ⟩ in , which we express as (see App. B.3): The target of this control gate is the output qubits, after first rotating their initial state, |0...00⟩ out , with the H operator such that it becomes |+... + +⟩ out .This is equivalent to a quantum Fourier transformation, which we can represent as: and mathematically express as: Then, we can leverage phase kickback to imprint the multiples of the angle θ onto their phases.Based on Eq. (11), the phase of an output qubit where we set k = 2 l .Namely, k = 2 0 for the first output qubit, k = 2 1 for the second, ..., and k = 2 n−1 for the last (n-th).The repeated application of the controlled gate Q can be represented as: and the state of the output qubits can be written as (see App. B.4): where which consists of a superposition of the states |z⟩, where z is an integer in the decimal number system.

Measurement
The measurement of the state z a z |z⟩ will result in the collapse of the superposition and will give one of the possible z values, z 0 .This can be represented by: If θ has a value such that an integer z 0 ∈ [0, 2 Then, it is straightforward to calculate the probability p by substituting θ in Eq. (3) with the measured value of z 0 : If there is no z 0 such that ±θ − 2πz 0 /2 where N = 2 n is the total number of possible outcomes.Notably, the error in QAE decreases proportionally to 1/N (Eq.19), much faster than the 1/N 1/2 scaling of classical algorithms (Eq.2).Apart from the basic QAE algorithm described above which is based on quantum phase estimation (QPE), recent studies have explored other variants of the QAE family that do not require QPE [33][34][35].
2 Quantum gates and circuits for scenario generation

Equity risk factors
Consider an equity price, S t , that follows the stochastic differential equation: where µ is the drift, σ the volatility, t the time, and W t a Wiener process.Itô's lemma implies that and thus S t is log-normally distributed, with expected value and variance: The path of the price can be modelled with a binomial tree with m + 1 nodes at times t = {0, δt, 2δt, ..., T }, respectively, where δt = T /m is the time interval.At each node, the price S t can either go up by a factor u, S u t+δt = S t u, or down by a factor d, S d t+δt = S t d, with probabilities q and 1 − q, respectively.
By requiring the discrete model to have the same mean and variance as the continuous model, we obtain the following expressions for u and q, respectively (see App. C.1): Binomial trees are common in pricing equity derivatives [36].
2.1.1D eq : the distribution P (S t ) Since at each timestep the stock price has two possible outcomes, we can model a transition from time period t to t + δt with a qubit in superposition, |ψ⟩ t+δt rf , such that the states |0⟩ and |1⟩ represent downwards and upwards moves, respectively.Therefore, a scenario consisting of m timesteps can be modelled with m qubits: where the superscripts δt, 2δt, ..., mδt are labels of individual qubits.For m = 2, the binomial tree is: where we use the notation |∅⟩ = |0⟩ to denote a qubit that has not yet been through a gate.
At each time t, the probability q can be encoded into the angle θ u of a "risk factor" qubit with a y-rotation gate, R y (θ u ), i.e.
The inverse of this gate, D † eq , consists of the same rotation gates but with a negative angle, −θ u : The choice of the risk measure depends on the use case; here, we consider as examples the probabilities of observing the maximum and minimum values. 7For some risk measures, m anc additional ("ancilla") qubits are required to store the intermediate values of the calculation.We ensure that all assembled gates leave the state of these qubits to their initial state |0⟩ ⊗manc anc ;8 therefore, we do not explicitly show them when not needed.

Maximum
The gate that calculates the probability of S T taking its maximum value, F (S T ) = P (S max ) = P (|1⟩ ⊗m rf ) = q m , can be assembled with a sequence of and (Toffoli) gates, such that the "risk measure" qubit flips to the state |1⟩ rm if all "risk factor" qubits are in the state |1⟩ ⊗m rf ; namely, |ψ⟩ rm = (1 − q m ) |0⟩ + q m |1⟩.In its simplest form, an additional m − 2 "ancilla" qubits are required to store the result of the and operators, which are then applied a second time to revert the "ancilla" qubits back to their original |0⟩ ⊗manc anc state.
Note that if we apply M max twice, the "risk measure" qubit returns to its initial state |0⟩ rm , while the states of all other qubits remain unchanged: Minimum The probability of measuring the minimum value, F (S T ) = P (S min ) = P (|0⟩ ⊗m rf ) = (1 − q) m , can be constructed following the same logic.We first flip all "risk factor" qubits and then apply and operators such that only the state |0⟩ ⊗m rf will lead to the state |1⟩ rm of the "risk measure" qubit: The corresponding quantum gate can be assembled by leveraging M max : Here too, we notice that the inverse gate is Other risk measures Gates for other risk measures can be assembled following similar logic, e.g. for value-at-risk and expected shortfall see Refs.[8,9].In Sect.2.3 we show an example of probability distributions that involve inequalities, e.g.P (S T ≥ u j T S 0 ), where j T is a specified number of upwards moves.Generally, any risk measure can be calculated by using quantum gates for arithmetic operations and comparisons [37,38].

Phase estimation
To assemble the gate a gate that flips the sign of the state For Q ψ , we decompose the operator as (see App. C.2): where To apply a reflection only if all input qubits are in the state |0⟩, we first flip them with not gates, we then operate with a sequence of and gates storing the result in the last "ancilla" qubit, and finally we apply a controlled Z gate to flip the sign of the "risk measure" qubit if the last "ancilla" qubit was in the state |1⟩.Operating with the and and not gates again brings all qubits to their initial state (apart from the sign of the "risk measure" qubit depending on the initial state).
where the A and A † gates consist of the and gates:

Measurement
The QFT gate prepares the output qubits in the state |+⟩: Table 2: List of the binomial tree parameters for the equity risk factor evolution.
The QFT † gate converts the phases ±kϕ to an integer z ∈ [0, 1, ..., 2 n − 1]; Fig. 2 shows the implementation based on [39], where the controlled rotations between qubits l 1 and l 2 are: See App.C.3 for an example of a complete quantum circuit that estimates P (S max ) for m = 2 and n = 3.The accompanying figures show a visualisation of the qubit states and their transformations on the Bloch sphere, as well as the corresponding probability distributions when measured.

Results
To analyse the convergence of the estimate of the risk measure we assemble 9 quantum circuits, each one with a different number of output qubits, n ∈ [1, 2, ..., 9], and adopt the parameters listed in Table 2 (the value of S 0 is not needed).The top panel of Fig. 3 shows the probability distribution P (S T ) obtained after applying the gate D eq on the "risk factor" qubits.The distribution is represented by the states |j⟩ (see Eq. 6), which consist of all possible 2 m combinations of the "risk factor" qubits when j of them are in the state |1⟩ (i.e.j upwards price moves).Since q > 1/2, the distribution is positively skewed: P (S T ≥ u 2 S 0 ) > P (S T ≤ d 2 S 0 ).The gates M max and M min essentially measure the probabilities of the states |6⟩ and |0⟩, respectively, which are encoded in the "risk measure" qubit; see bottom panel of Fig. 3.The bar charts of Fig. 4 show the distribution P (|z⟩) obtained by measuring the output qubits (here n = 4 and 10,000 shots) for the two risk measures, P (S max ) (top) and P (S min ) (bottom).The left and right peaks correspond to z = 2 n θ/2π and z = 2 n (2π − θ)/2π, respectively, originating from the two signs of the phase kickback, ±kθ.The line charts of Fig. 4 show the convergence of the estimated probability p (Eq. 18), P (S max ) (top) and P (S min ) (bottom), and error δp (Eq.19), as a function of the number of output qubits, n.Here, the measured state of the output qubits is obtained from one shot.The expected values of the probabilities are P (S max ) = q m and P (S min ) = (1 − q) m , respectively.
Equity risk factors can also be based on trinomial trees, the implementation of which is presented in Sect.2.2.

Interest rate risk factors
The evolution of interest rates can be simulated with short-rate mean reversion models, the most basic of which is the Vasicek model [40]: constant for δt → ∞, whereas for finite δt the expected value depends on r t : Such models are often discretised with trinomial trees.For example, consider a simple tree that is bounded at both low and high interest rates, and, at each timestep, r t can take one of three possible values: r h t = b + δr (high), r m t = b (mid), and r l t = b − δr (low), with δr a constant.
The transition probabilities q t→t+δt from a node r t to a node r t+δt depend both on the t and t + δt nodes, and thus q t→t+δt is an array of 3 × 3 = 9 values.These probabilities can be derived by equating the expected value and variance of the continuous and discrete models, respectively (see App. D).

D ir : the distribution P (r t )
Given that at each timestep t there are 3 possible outcomes we need two qubits, |0⟩ t rf 1 |0⟩ t rf 0 , to encode the probabilities q; therefore, m timesteps require 2m "risk factor" qubits.At each timestep, we use the first qubit (rf 0 ) from the pair to represent whether the interest rate transitions to the mid level: r t → r m t+δt .Specifically, the state |0⟩ t rf 0 describes a transition to the mid node and the state |1⟩ t rf 0 a transition to a different node.In the latter case, we use the second qubit (rf 1 ) to model whether r t transitions to the high (r t → r h t+δt , described by |1⟩ t rf 1 ) or low (r t → r l t+δt , described by |0⟩ t rf 1 ) levels, respectively.Because the transition probabilities depend on the level of the interest rate, the "risk factor" state needs to be read at each timestep before encoding the probabilities for the next transition.This can be facilitated by including 3 additional "state" qubits -alongside the 2m "risk factor" qubits -to store the value of r t at each timestep; i.e. |001⟩ t st , |010⟩ t st , and |100⟩ t st , which represent the high, mid, and low interest rate levels, respectively.Assuming r 0 is at the mid level, the tree is: The quantum state at the first timestep is: where the first and second subscripts of the transition probabilities denote the start and end nodes.To assemble the gate D ir we put together a "read" operator R t = R l t R m t R h t , which reads the state |ψ⟩ t st and encodes the transition probabilities to |ψ⟩ t rf .As an example, the operator R m δt is: Here, the controlled R y (θ hm 0 ) gate encodes the probability q mm -namely the likelihood that the rate will remain at the mid level r δt = r 0 = b -into |ψ⟩ δt rf 0 .The second gate, and, checks whether both r 0 = b and r δt ̸ = b are truenamely whether the interest rate changed -and writes the result to an "ancilla" qubit.The third gate, controlled R y (θ mh 1 ), checks the result stored in the "ancilla" qubit, and if it is |1⟩ it encodes the conditional probability of r δt transitioning to the high interest rate value given that it did not remain at the mid level: P (r δt = b+δr|r δt ̸ = b) = P (r δt = b+δr)/P (r δt ̸ = b) = q mh /(1−q mm ).The fourth gate, and, ensures the "ancilla" qubit is in its original state.The logic for the R h δt and R l δt gates is similar, see their decomposition in Fig. 5 which shows an example of the entire "read" gate at the first timestep, R δt .
The "write" gates W t read the "risk factor" qubit pair |ψ⟩ t rf and write the result to the "state" qubits, |ψ⟩ t st : see Fig. 5 for its decomposition of W t into X and and operators.Before writing to the "state" qubits, the previous state needs to be erased; therefore, the application of W t is always preceded by the gate W † t−δt which resets the "state" qubits back to |000⟩ st .The inverses of the "read" and "write" gates, R † t and W † t , consist of the components of R t and W t put in inverse order.Finally, the operator D ir can be assembled by a sequence of "read" and "write" operators for each timestep as shown in Fig. 6.

M ir : risk measures F (r t )
For the implementation of the trinomial tree we consider as risk measure the probability of the interest rate being equal to its long-term mean level after m timesteps.In this case, the gate M m is simply: The decomposition of the "read" R t and "write" W t operators for the first timestep, assuming that r 0 = b (i.e.W 0 |000⟩ st = |010⟩ 0 st ).From left to right the R gates are R y (θ hm 0 ), R y (θ hh 1 ), R y (θ mm 0 ), R y (θ mh 1 ), R y (θ lm 0 ), and R y (θ lh 1 ).with M † m = M m .

Results
Table 3 lists the choice of parameters for a quantum circuit that implements trinomial trees for interest rate evolution (due to our parametrization, we do not need to choose values for a and b).For each one of the m = 3 timesteps we need 2 "risk factor" qubits, a total of 6: |ψ⟩ rf .We need an additional 3 qubits to store the interest rate state |ψ⟩ st , 1 qubit for the risk measure |ψ⟩ rm , and 9 "ancilla" qubits |ψ⟩ anc for the A gates.We can freely choose δr, which we set to a multiple of the standard deviation.Note that the definition 0 ≤ q t→t+δt ≤ 1 constrains the choice of δt (see App. D).Having defined δr and δt, we can calculate the transition probabilities, see Table 3.
When starting from r 0 = b, the probability of measuring the value r 3δt = b after 3 timesteps can be calculated by adding up the probabilities of all possible paths: where s 1 , s 2 ∈ {h, m, l} are the nodes of the first and second timesteps, respectively.Figure 7 shows the probability distribution of the "state" qubits (top panel) and the distribution of the "risk measure" qubit (bottom panel) at t = 3δt when measuring these qubits directly with 10, 000 shots.
Similar to the equity risk factor analysis, Fig. 8 shows the distribution of the output qubits for n = 4 (top panel) and the convergence of the measured value of p = P (r 3δt = b) as a function of the number of output qubits (bottom panel).

Credit risk factors
This section focuses on simulating default probabilities of issuers.Among the common approaches are structural and reduced-form credit risk models, as well as credit rating migration.

Structural credit risk models
In structural credit risk models, e.g. the Merton model [41], default takes place when the assets of a company become less than its liabilities.As a simple example, we assume that the liabilities D t have maturity at time T , and that the value of the assets A t follows the stochastic process: where µ is the mean, σ the volatility, and W t a Wiener process.Default occurs if at time t = T the value of the assets is less than, or equal to, the liabilities, A T ≤ D T ; therefore, the probability of default is P (A T ≤ D T ).
D def : the distribution P (A t ) Since this problem has a similar stochastic process to that of equity risk factors, we can model the evolution with a binomial tree using the gate D def = D eq described in Sect.2.1.As an example, we consider the same binomial tree parameters as those listed in Table 2 and set D T = A 0 d 4 .Based on the top panel of Fig. 3, default occurs if j = 0 or j = 1 (a "down" price move at all timesteps or a single "up" move before time T ).
M def : probability of default The risk measure here is the probability of default: For the implementation of the gate we also include "count" qubits, |ψ⟩ c = |j⟩ c , in order to store the binary value of j.For 6 "risk factor" qubits we have j ∈ {0, ..., 6}, and thus 3 "count" qubits are needed to encode these 7 values.We also include "state" qubits, |ψ⟩ st , to represent each of the values of j that correspond to default; since there are two such values here, j = 0 and j = 1, we include two "state" qubits.
The gate M def can be decomposed into three parts.The first part counts the number of up moves in |ψ⟩ rf , i.e. it computes j, and writes it to |ψ⟩ c .The second part reads the state |ψ⟩ c and flips the corresponding "state" qubit when that value is j = 0 or j = 1.The third part consists of an or gate than takes as input the two "state" qubits and flips the "risk measure" qubit if any of them is in the state |1⟩.
The first part can be achieved with the gate where each operator C l increments the count by one if the "risk factor" qubit of timestep l is an "up" move: After the operator C counts the "up" moves (j in total) and writes them as a binary number to |ψ⟩ c , the operator J = J m ...J 1 J 0 reads j and flips the corresponding qubit of the "state" qubits |ψ⟩ st , see Fig. 9.For our example, we are inter- ested in the values j = 0 and j = 1 so we only include gates J 0 and J 1 .Therefore, the components of gate M def are:

Results
The top panel of Fig. 10 shows the probability distribution of the "count" qubits and the bottom panel that of the "risk measure" qubit.Since the binomial tree parameters are the same as in the equity risk factor example, the top panel is identical to Fig. 3 apart from the stacking of the "default" states |0⟩ and |1⟩ (the probability of which is encoded in the "risk measure" qubit shown in the bottom panel).Figure 11 shows the measurement of the output qubits and the convergence of the probability distribution when assembling all gates into a quantum circuit.The expected value of the probability is

Reduced-form credit risk models
Another approach to estimate probabilities of default is reduced-form credit risk models, in which default is modelled as a statistical process.The survival probability from time t 0 to time t is given by: where T def is a characteristic timescale, the inverse of which is called the hazard rate, λ = Table 5: List of parameters for the reduced-form credit risk model.
To calculate the survival probability at time T we can discretise the time interval t ∈ [0, T ] with m timesteps, δt = T /m, such that the survival probability is: A visualisation of this process is: where S t and D t denote the survival or default states at time t, respectively.
D surv : the distribution P (T ) At each of the m timesteps we can represent survival with one "risk factor" qubit, such that |0⟩ represents survival and |1⟩ default.Thus, if the company has survived until time t = (l − 1)δt, then , where q def = 1 − P (δt).If the company has defaulted at a previous timestep, then: |ψ⟩ lδt rf = |1⟩.For the example of m = 3: Gate D surv can be assembled with rotation gates R y (θ def ) (shown below as θ d for brevity) obtained from q def = sin(θ def /2).In addition, in order to ensure that in the event of default at time t the company will also be in default at t + δt, we include a controlled gate R y (θ c def ), where θ c def + θ def = π: this breaks the superposition of the qubit representing t + δt and sets it to the state |1⟩.Therefore, the gate D surv is: The inverse gate, D † surv , has the rotation gates in reverse order and the signs of the rotation angles flipped.
M surv : survival probability The probability of survival at t = T is represented by the state |0...00⟩ T rf .Therefore, we can use the gate M surv = M min decribed in Sect 2.1, which flips the "risk measure" qubit if all "risk factor" qubits are in the state |0⟩.The expected value of the probability of survival at time T is (1 − q def ) m .and default (|0⟩ rm ) probabilities encoded in the "risk measure" qubit.Figure 13 shows the measurement of the output state and its convergence similarly to the previous use cases.

Credit rating migration
A more elaborate approach to simulate probabilities of default is with credit rating migration matrices.For example, consider the following three ratings: A (investment grade), B (high yield), and D (defaulted), and assume that, at t = 0, an issuer has the rating A 0 .The evolution of the credit rating can be described with multinomial trees, such as this: where each transition, e.g.q A→B has a predefined probability which is calibrated with historical data.Since we have already described the implementation of such trees in Sect.2.2, we do not provide a more detailed example here.The credit rating evolution and probability of default at time t can be modelled with the gate D migr = D ir (with a minor adjustment to set the initial rating to A, which would correspond to the high interest rate level), and the default probability can be encoded with M def = M l (corresponding to measuring the low interest rate level).

Discussion
We proceed to estimate the number of qubits required, and the resulting circuit depth, for typical financial risk use cases.We limit the analysis to scenario generation and ignore the additional qubits and gates that would be needed when, for example, the pricing of a derivative is also included in the circuit.Since the number of "risk factor" qubits, m rf , determines the number of time steps that discretises a time period, we can consider m rf to represent "risk model accuracy".Similarly, because the number of output qubits, n, determines the error of the estimate, we consider n to represent "measurement precision".The higher the number of input and output qubits is, the higher the accuracy and precision are, respectively.
Financial risk models ignore intra-day changes, thus the smallest timestep is one business day.For scenario generation over long time horizons, such as those that span decades, timesteps up to one month can be a sufficient as well as an efficient choice.
Equity price scenarios are used in pricing exchange-traded equity derivatives, most of which expire in less than 12 months, with some extending up to 2 years.With ∼260 business days in a year, the D eq gate would not require more than ∼520 "risk factor" qubits.Equity scenarios are also used in equity indices derivatives, structural credit risk models, convertible bonds, and over-the-counter equity derivatives, all of which can have time horizons from few months to several years.Even for periods as large as 50 years, and by considering a timestep of one month, the D eq gate has an upper limit of 600 qubits.Because the number of "ancilla" qubits, m anc , for the gates M min and M max scales linearly with m rf , these gates require roughly: m anc ≃ m rf .This is not the case for the gate M def , which only needs few additional qubits ("count", "state", and "ancilla") as m rf increases; e.g., only 8 qubits are needed to count from 1 to 256.Overall, the total number of input qubits ("risk factor", "risk measure", "ancilla", "count", "state") for typical use cases of equity risk factor scenarios has an upper limit of ∼1, 200.
Reduced-form credit risk models can be used to simulate the survival probability of an entity over several years, whether for credit default swaps or counterparty credit risk use cases.Similar to structural credit risk models, a timestep of one month can be sufficient for long time horizons; this limits the number of "risk factor" qubits of the D surv gate to be a few hundred at most (e.g.600 for 50 years).Because M surv needs a number of "ancilla" qubits similar to m rf , the total number of input qubits for this type of circuits would not exceed ∼1, 200 either.
For interest rate scenarios, the number of "risk factor" qubits has a linear dependence on the number of timesteps as in the case of equity scenarios.Because interest rates do not fluctuate as much on a daily basis as equities, a timestep of one month is often adequate to model their evolution.On the other hand, by increasing the number of nodes per timestep, the number of qubits needed to model the discrete interest rate values also increases (based on the implementation of the D ir gate here).The scaling is sublinear though, as each new additional qubit can double the amount of interest rate values modelled.Moreover, the M m gate of our example only needs one additional qubit, the "risk measure" one.While we refrain from a more detailed estimate, modelling a 50-year period would not require more than a thousand input qubits.The same analysis also applies to multinomial trees for the modelling of credit rating migration.
Therefore, when accounting for both input and output qubits, scenario generation for typical financial risk use cases would overall require around or a little more than a thousand qubits for high-accuracy, high-precision results.
Next, we proceed to estimate the circuit depth.With current quantum computers, the higher the number of gates the more prone the computations are to errors due to noise.We calculate the depth numerically by decomposing the gates or circuits of Sect. 2 into their constituent gates, a process that we repeat until no further decomposition is possible. 10The left panels of Fig. 14 show the depth of gates D and M as a function of the number of input qubits m (model accuracy); the depth is found to scale linearly with m.Since for m ≃ 10 the depth is ≲ 500, for m ∼ 1, 000 we expect the gate depth to be on the order of ≲ 50, 000.
The right panels of Fig. 14 show the total circuit depth (it includes the gates D, M, Q, QFT, and QFT † ) in log scale as a function of the number of output qubits n (model precision).The depth increases exponentially with respect to n because every extra output qubit doubles the number of times the Q gate is applied (see Eq. 14).For n = 14, the total depth is projected to be on the order of ≲ 10 8 .Estimates from pricing exotic derivatives report qubit numbers and circuit depths that are on the same order of magnitude, ∼10 3 -10 4 and ∼10 8 , respectively [14,26].
While quantum computers are expected to reach ∼1, 000 qubits in the next few years, the 9 "bp" stands for basis points. 10For the numerical calculation of the gate or circuit depth we use the Qiskit functions decompose() and depth() [42].For example, the depth of a 2-qubit circuit in which each qubit is going through an H gate, H |0⟩ ⊗ H |0⟩ = |++⟩, has a gate count of 2 and a circuit depth of 1 because the two gates act in parallel.An example of decomposition is breaking down the Toffoli gate into the basic gates it consists of, which gives a gate depth of 11.
estimated circuit depth prevents such use cases from being feasible without significant progress on fault tolerance.Moreover, note that all the above estimates apply when modelling a single risk factor.For a portfolio that depends on multiple risk factors, we would need that many times of input qubits (parallel run), or to generate scenarios sequentially (serial run) [7].Hardware limitation make the latter option more likely in the near term.

Summary and conclusions
QAE algorithms have been shown to provide a quadratic speedup over their classical counterparts, a result that has motivated several recent papers on financial risk applications.Most of these papers start from pre-computed risk factor distributions and focus on the calculation of common risk measures, distribution loading, and QAE optimisations.In this paper, we extend these studies by consistently integrating scenario generation -which we call QMC -into QAE quantum circuits.Specifically, we assemble quantum gates that implement stochastic risk models for the evolution of equity, interest rate, and credit risk factors.For equities, we generate scenarios by discretising a geometric Brownian motion with binomial trees, and for interest rates, by discretising mean-reversion stochastic differential equations with bounded trinomial trees.For credit risk factors, we calculate the default probability from structural models based on binomial trees and the survival probability from reducedform models based on a Poisson process.We also describe how multinomial tress can be used for the implementation of credit rating migration matrices.Moreover, we assemble quantum gates to encode generic risk measures, such as the probabibilities of measuring the minimum, maximum, and the tail of a distribution.For each use case, we build end-to-end QMC/QAE circuits that incorporate: the generation of risk factor scenarios (QMC), the encoding of the risk measure, and the estimation of the risk measure value (QAE).We then validate the quantum computation with simulated runs, and demonstrate that the measured value converges to the expected value and that the error goes to zero as the number of output qubits increases.
For the typical model accuracy and measure-  ment precision of realistic financial use cases, we estimate that risk factor evolution requires ≲1, 200 qubits, which is within the capabilities of the quantum computers expected in the next few years.However, we estimate that the typical circuit depth is on the order of ≲10 8 , which poses the biggest challenge until fault-tolerant quantum devices are available.The probabilistic output of quantum gates combined with the quantum property of superposition provide a natural framework for the implementation of stochastic risk models.On the one hand, quantum gates can model the output states of a random variable by encoding the probabilities of the outcomes.On the other hand, superposition enables the quantum circuit to simultaneously model all possible paths of a time-dependent random variable, eliminating the classical-computation constraint of iterating over paths.We conclude that quantum financial risk applications can benefit from consistently incorporating scenario generation as part of QMC/QAE simulations, further reducing their dependency on classical computers.A Qubits, gates, and quantum circuits Quantum computers consist of qubits, which are the equivalent of classical bits.The quantum states |0⟩ and |1⟩, which represent the values of 0 and 1, are shown on the Bloch sphere in the left and middle panels of Fig. 15, respectively. 11The key property of qubits is that they can exist in any superposition of these two states, i.e. |ψ⟩ = a 0 |0⟩ + a 1 |1⟩, where a 0 , a 1 are complex numbers satisfying the condition |a 0 | 2 + |a 1 | 2 = 1.When such a qubit is measured, it will give either the state |0⟩ or |1⟩ with probabilities a 2 0 and a 2 1 , respectively. 12Due to the probabilistic nature of the measured outcome, repeated experiments -called shots -are often needed to improve the precision of a result.Quantum states of single qubits can be conveniently written using the real-valued parameters θ ∈ [0, π] and ϕ ∈ [0, 2π]: where θ determines the probability of each state and ϕ is the relative phase (we have ignored the global phase).Quantum circuits are composed of quantum gates operating on qubits.Because qubits can be put in a superposition of states, quantum gates process multiple states simultaneously, when classical gates can only process one at a time. 13Single-qubit gates modify the state of a qubit -for instance, see the middle panel of Fig. 15 that shows the X, or not, operator flipping |0⟩ to output |1⟩.Generally, single-qubit gates modify the parameters θ and ϕ.An example is shown in the right panel of Fig. 15, where the operator R π/2 y rotates the qubit |0⟩ by θ = π around the y-axis, and then R π/3 z rotates it by ϕ = π/3 around the z-axis.The quantum circuits for the three qubits of Fig. 15 can be written as where the third qubit has a 50% chance to be found in either the |0⟩ or |1⟩ state.Two-qubit gates leverage quantum entanglement, a property that binds the states of two qubits together, and may alter the qubits depending on their initial states.This mechanism allows to implement logical operators similar to an "if" statement, e.g. the cnot (controlled not) gate below: When the "control" qubit (top) is in the state |1⟩, the cnot gate flips the "target" qubit (bottom).If the "control" qubit is in the state |0⟩, the "target" qubit remains unchanged.Another example with the cnot gate is the "phase kickback" mechanism, where the phase of the target is "kicked back" to the controller, e.g.
where |+⟩ and |−⟩ is another basis, with the qubits along the x-axis, see Fig. 16. 14he cnot gate is a building block of the three-qubit and gate (also known as Toffoli or ccnot gate): With the help of the not and and gates we can build the logic for an or gate: Other multi-qubit gates can be assembled as sub-circuits by combining basic two-qubit gates, however, their depth is currently limited by hardware noise.

B Calculations
In the below we drop the subscript "in" for brevity.

B.1 Calculation of Q |ψ⟩
From Eq. (7) notice that: and also which, because it should hold for any p, implies: B. 4 The output qubits after the controlled gate Q We set the output qubits -which we label here with l = 0, 1, ..., n − 1 -as controls to the gate Q, and apply the gate 2 l times for each qubit, respectively.Their output state is: (62)

Figure 6 :
Figure6: Gate D ir consists of a sequence of "read" and "write" gates.

Figure 7 :
Figure 7: The distribution P (r 3δt ) (top panel) and superposition of the "risk factor" qubit that encodes P (r 3δt = b) (bottom panel).

Figure 8 :
Figure 8: Top panel: the distribution P (|z⟩) of the measured output state for n = 4 and 10, 000 shots.Bottom panel: the measured value of p as a function of the number of output qubits for 1 shot.

PFigure 10 :Figure 11 :
Figure 10: Top panel: the distribution of A T as generated from 10,000 shots; the first bar represents the two "default" states.Bottom panel: the distribution of the "risk measure" qubit representing the probability of default.

Figure 12 :
Figure 12: The probabilities of the "risk measure" qubit states: |1⟩ denotes survival up to t = T and |0⟩ denotes default at any timestep before reaching T .

Figure 13 :
Figure13: Top panel: the probability distribution of the output qubits for m = 4 and 10,000 shots.Bottom panel: the estimated probability (one shot) and its convergence when increasing the number of output qubits.

Figure 14 :
Figure 14: Left panels: depth of the gates D and M as a function of the number of input qubits, m, which represents model accuracy.Right panels: depth (in log scale) of the entire quantum circuit as a function of the number of output qubits, n, which represents measurement precision.

Figure 15 :
Figure 15: Left: the quantum state |0⟩ on the Bloch sphere.Middle: the quantum state |1⟩, which can be obtained by acting on |0⟩ with the not operator, X.The dashed line indicates that the point is on the non-visible part of the sphere's surface.Right: the superposition |ψ⟩ = cos(π/4) |0⟩ + e iπ/3 sin(π/4) |1⟩ obtained by the operation of two rotation gates.

θ rf y |0 1 rf |ψ rf = D|00 rf θ = π 4 |ψFigure 17 :
Figure17: The qubit states before and after the operation of the quantum gates.Top left: gate D rotates the "risk factor" qubits (green) around the y-axis.Bottom left: the controlled gate M reads the "risk factor" qubits and sets the "risk measure" qubit in superposition (red), encoding the probability that both "risk factor" qubits are in the state |1⟩ (since no rotation is involved, the phase of the "risk measure" qubit does not have a specific value and we draw the state as a circle).Left vertical panel: the output qubits (blue) before and after the application of the QFT gate, which consists of a Hadamard gate, H, applied to each qubit.Middle vertical panel: the controlled gate Q imprints the angle θ of the "risk measure" qubit as a positive (+ϕ, blue) or negative (−ϕ, orange) phase onto the first output qubit (top); the controlled gate Q 2 imprints the angle 2θ onto the phase of the second qubit (middle); the controlled gate Q 4 imprints the angle 4θ onto the phase of the third qubit (bottom).Right vertical panel: the inverse quantum Fourier transform gate, QFT † , leverages quantum interference to transform the phases of the output qubits to a binary number expressed with |0⟩ and |1⟩ states.
To estimate a statistical measure F (X t ) ∈ [F min , F max ] of a risk factor X t , a QAE circuit would typically consist of: 1. m "risk factor" (rf) qubits to model the distribution of X t (the initial state of which is denoted with |0⟩ ⊗m rf ), 2. one "risk measure" (rm) qubit to encode the normalised value of the risk measure 4 f (X t ) ∈ [0, 1] in the angle θ ∈ [0, π] (the initial state of which is denoted with |0⟩ rm ), 3. n output (out) qubits to imprint multiples of θ onto their phases (the initial state of which is denoted with |0⟩ ⊗n out ).5Without loss of generality, in the following example we choose f (X t ) = p, i.e. the risk measure to be a probability of an outcome that depends on X t , i.e. f (X t ) = p.

Table 1 :
Notation of states.

Table 3 :
List of the trinomial tree parameters for the interest rate risk factor evolution.

Table 4 :
The transition probabilities of the trinomial tree.
While in the equity risk factor examples the gates M max and M min pick up a single value of |ψ⟩ rf (|11...1⟩ rf and |00...0⟩ rf , respectively), here we assemble the gate M def such that it flips the "risk factor" qubit for any value of |ψ⟩ rf that satisfies A T ≤ D T ; namely, if/when the "risk factor" qubits takes one of the following 7 values: |000000⟩, |000001⟩, |000010⟩, ..., |100000⟩.