1 Introduction

The term ‘quantum computing’ refers to using quantum mechanics, i.e. the theory to describe physical properties and effects of atoms and subatomic particles, on specially designed devices.Footnote 1 Compared to ‘classical’ computations on CPU and GPU hardware,Footnote 2 the use of quantum hardware and specially designed software promises a significant speed advantage, dependent on the problem at hand. For certain types of applications, such as integer factorisation—often used as a basis for encryption—quantum computing is the only known way to obtain solutions in an acceptable timeframe.

The landscape of quantum technologies, research and investments has seen an exponential growth over recent years [55]. Financial institutions such as large banks have been investing substantially into quantum research—mainly on rented hardware with so far limited capabilities—and the exploration of its use cases. High hopes have been expressed for applications such as trading and risk management [11, 20, 22, 44, 69, 90]. The recent trend of using machine learning for financial problems offers a straightforward extension to quantum computing. It is as such vigorously pursued by banks [19]. Suitable quantum applications are especially those where a large number of algorithmic repetitions is required, for example, the brute-force enumeration of possible solutions for a system of equations and, to a lesser extent, in Monte Carlo simulation.

The contribution of this study is an exploration of the feasibility of using quantum computing in actual large-scale risk applications in financial institutions. In a typical market risk application that makes use of simulating future market scenarios—such as a Monte Carlo-based Value-at-Risk (VaR)—a large number of risk factors and their joint evolution need to be reflected. Furthermore, the corresponding changes in the present value (PV) of instruments in a portfolio require revaluations in each potential future state. The situation in a counterparty credit risk context is similar: scenarios across a multitude of risk factors and, additionally, numerous time steps need to be combined with portfolio revaluations.

The analysis shows that the capacity of current state-of-the-art quantum systems, measured through the number of ‘qubits’, severely limits both the number of risk factors that can be simulated as well as the accuracy of their marginal and joint distributions. In conjunction with typical ‘noise’ patterns that quantum circuits experience in practice, risk measurement applications with real-life use cases are out of reach for the foreseeable future.Footnote 3 Bearing in mind that practical risk applications in financial institutions using classical computing are meanwhile mature and deliver accurate enough results in acceptable amounts of time even for large-scale portfolios, the business case for a move to quantum computing is not apparent at this point.

The paper is organised as follows. Sect. 2 summarises the current state of research into quantum applications in quantitative finance. Sect. 3 defines the framework for practical quantum use cases in risk measurement. It outlines fundamental challenges in terms of size, speed and accuracy requirements and recalls some essentials on quantum computing. The basic building blocks in the form of quantum amplitude estimation as well as techniques for scenario modelling and working with profit-and-loss (P &L) distributions are described. Furthermore, quantum-specific challenges for real-life use cases such as the handling of noise are covered. Sect. 4 presents an application to market risk as typically encountered in financial services. Starting from the underlying risk factor model with its calibration and the VaR calculation, the creation of a suitable quantum circuit is described. This is followed by an analysis of the estimation results. Covering the same aspects, a worked example for measuring counterparty credit risk is discussed in Sect. 5. In Sect. 6, the influence of adding typical quantum noise as present in current devices is illustrated. The Python-based Qiskit frameworkFootnote 4 of IBM is used for the actual implementations. Section 7 concludes and provides an outlook for future research.

2 Research landscape in quantitative finance

Quantitative finance is a prime candidate for the use of quantum computing, given that many algorithms rely on simulation or on solving complex optimisation problems which either demand a vast amount of computational power or are even unsolvable with classical approaches.Footnote 5 Practical applications of quantum computing in quantitative finance are still comparatively limited.

Pricing of derivatives. Amongst financial instruments, some classes are easier to handle than others. For the purpose of ‘pricing’, i.e. the determination of the PV, one will typically rely on (1) replication arguments—assembling the same payoff from more basic building blocks whose PVs are known or easier to obtain—and/or (2) assumptions on the future evolution of the value drivers (e.g. stock prices) and obtain the PV through mathematical derivation or simulation. A particular challenge are derivatives, whose values depend on that of one or more underlying variables. Especially the pricing of instruments with nonlinear payoffs such as options is an established challenge.Footnote 6 In case no closed-form pricing formulas or efficient PDE-basedFootnote 7 approaches are available, Monte Carlo simulation is the standard tool. Quantum approaches have been proposed for a variety of applications, for example:

  • Pricing of standard (‘vanilla’), path-dependent (e.g. barrier and Asian) and multi-asset options in a Black-Scholes [9] and local volatility [28] framework [4, 18, 33, 38, 51, 54, 64, 72, 73, 75, 76, 80]

  • Pricing of options under a stochastic volatility [16] and jump-diffusion process [95]

  • Pricing of American-style options [27, 62]

  • Pricing of interest-rate derivatives with a multi-factor model [58, 84]

  • Pricing of collateralised debt obligations (CDOs) [83]

Risk measurement. In a financial context, ‘risk’ usually refers to an adverse event associated with a (financial) loss. Quantum applications that have been proposed so far span, for instance:

  • Estimation of risk measures such as VaR (see also Sect. 4), Conditional VaR (CVaR) [91] and the corresponding risk contributions [63]

  • Estimation of credit risk (Economic Capital) [30]

  • Sensitivity analysis for a (business) risk model at an exchange [15]

Miscellaneous. Quantum algorithms have been applied across a range of other areas in finance as well. For example:

  • Portfolio optimisation—construction of ‘optimal’ portfolios, for instance, in terms of the best trade-off between expected return and risk [6, 26, 46, 56, 70, 87, 88]

  • Time series forecasting [31]

  • (High-frequency) trading and arbitrage [21, 94]

  • Credit scoring and classification [61]

  • Handling of transaction settlements (i.e. the exchange of securities and cash between parties) at a clearing house [13]

Notably, techniques for estimating gradients and higher-order derivatives on quantum hardware [57, 78, 81] are highly relevant for many applications in finance such as pricing, hedging and risk management. The same is true for techniques to reflect pseudo-random numbers, as an essential building block in typical Monte Carlo use cases, in a quantum circuit [50, 65]. Crucial for risk applications is the reflection of the dependence structure amongst value drivers, usually expressed by means of copulas (see also Sect. 4). The corresponding quantum implementation [60, 93] is therefore an important component. Furthermore, Quantum Machine Learning (QML) has received considerable attention across the full range of techniques such as supervised and unsupervised learning as well as generative modelling tasks [7, 8, 71, 77]. Specifically for financial applications, methods for market scenario generation, such as the joint evolution of dependent risk factors [53], are a promising route [3, 23, 52, 97].

3 Framework for quantum computing in risk measurement

3.1 Fundamental requirements

Practical use cases in quantitative finance usually exhibit several vital challenges. One of the most important ones is the scalability of any application—such as the pricing and/or risking of instruments—so that calculations with a minimum accuracyFootnote 8 are technically feasible within acceptable runtimes.

For instance, a market risk application in a large financial institution typically encounters the following ‘size challenges’:

  • Portfolios: 1,000 to 10,000

  • Instruments/trades:Footnote 9 100,000 to 1,000,000

  • Valuation parameters: 10,000 to 10,000,000

For the actual risk quantification, one would rely on:

  • Scenarios (for a subset of the valuation parameters): 100 to 1,000,000

  • Time horizons (not necessarily equally spaced): 1 to 1,000

In spite of the inherent model risk, accuracy of risk measures is expected to be high in practice, usually not exceeding \(\pm 10\%\) around the ‘true’ value. Risk calculations need to fit into a few hours as a maximum (e.g. overnight batches), but, dependent on the application, outputs can be required in a matter of minutes or even seconds (e.g. for intraday risk and what-if analyses for trading decisions).

These requirements drive, amongst others, storage needs as well as the minimum processing speed of a risk system.

3.2 Essentials on quantum computing

The core idea behind quantum computing is the ability to perform parallel computations at scale. As a building block, a two-dimensional quantum-mechanical system—a qubit—is used, which encodes the classical ‘0’ and ‘1’ bits in its basis states, \(|0\rangle \) and \(|1\rangle \). Through superposition the quantum system can be in all of its states at the same time, which can be exploited from a computational angle.

In a practical application, one will usually (a) encode the input data through the initial states of the qubits, (b) bring those qubits into superposition, (c) apply an algorithm (also: oracle) across all states (see, for example, Sect. 3.3) and (d) measure one or several qubits. This measurement has a random result whose interpretation is to reflect the solution to the problem at hand.Footnote 10

3.3 Quantum amplitude estimation as a basis

Quantum Amplitude Estimation (QAE) [14] promises a speed-up in the calculation of expected values compared to ‘classical’ simulation. Concretely, with an operator \({\mathcal {A}}\) acting on a systemFootnote 11,

$$\begin{aligned} | \Psi \rangle = {\mathcal {A}} | 0 \rangle = \sqrt{\beta } | \tilde{\Psi }_1 \rangle | 1 \rangle + \sqrt{1-\beta } | \tilde{\Psi }_0 \rangle | 0 \rangle , \end{aligned}$$

the unknown parameter \(\beta = | \langle \tilde{\Psi }_1 | \tilde{\Psi }_1 \rangle | \in [0, 1]\) is estimated, the amplitude of the state \(| \tilde{\Psi }_1 \rangle \).

Quantum phase estimation leads to an estimator \(\tilde{\beta }\) with the property

$$\begin{aligned} |\beta - \tilde{\beta }| \le \frac{\pi }{M} + \frac{\pi ^2}{M^2} = {\mathcal {O}}(M^{-1}) \end{aligned}$$

with a probability of at least \(8/\pi ^2 \approx 81.1\)% (see, for example, [29]). M is hereby the number of quantum samples. Estimating \(\beta \) in this way leads to a quadratic speed-up compared to classical Monte Carlo simulation with its convergence rate \({\mathcal {O}}(M^{-{1/2}})\) .

The original QAE requires large circuits and is computationally expensive. Various improvements have been developed over time [16, 36, 41, 43, 66, 74, 82] and form part of industry-standard implementations by now, for example, Iterative QAE (IQAE).

3.4 Modelling future scenarios

Distributions. In the context of quantitative finance, the evolution of asset prices is regularly modelled with the help of distributions. These can either reflect the prices directly or their changes (returns) relative to fixed (= current) values. Alternatively, one can simulate the valuation parameters that—in conjunction with pricing functions—determine the future value or return distribution of the assets in question. An example are stock prices that feed an option pricing formula.

For instance, assuming a log-normal asset distribution, the asset price \(S_T\) at a time horizon T can be expressed through

$$\begin{aligned} {\mathbb {P}}(S_{T}) = \frac{1}{S_0 \sigma \sqrt{2 \pi T}} e^{-\frac{\left( \ln S_T - \mu \right) ^2}{2 \sigma ^2 T}} \end{aligned}$$
(1)

with \(\mu := \left( r-\frac{1}{2}\sigma ^2 \right) T + \ln S_0\), \(S_0\) as the current price, r as the risk-free interest rate and \(\sigma \) as the asset volatility.

In the quantum setup, one generally represents a random variable X through a quantum state consisting of n qubits [80]. The first step usually consists of a truncation to \([ X_{\text {lower}}, X_{\text {upper}} ]\) and a discretisation of the distribution. For the latter, let \(i = 2^{n-1} j_{n-1} + \dots + 2j_1 + j_0\) with \(j_k \in \{0,1\}\) and \(k = 0, \dots , n-1\). The affine-linear transformation

$$\begin{aligned} \{0, \dots , 2^n - 1\} \ni i \longrightarrow X_{\text {lower}} + \frac{X_{\text {upper}} - X_{\text {lower}}}{2^n -1} i \in [ X_{\text {lower}}, X_{\text {upper}} ] \end{aligned}$$

then fulfills the requirement. With \({p_i \in [0, 1]}\) as the corresponding probabilities, one can use a loading operator \({\mathcal {P}}_X\) to create a state

$$\begin{aligned} | 0 \rangle _n \xrightarrow {{\mathcal {P}}_X} | \psi \rangle _n = \sum _{i=0}^{2^n-1} \sqrt{p_i} | i \rangle _n, \end{aligned}$$
(2)

with an n-qubit state \(| i \rangle _n = | j_{n-1} \dots j_0\rangle \). The d-dimensional extension of (2) reads

$$\begin{aligned} |\psi \rangle _n = \sum _{i_1, \dots , i_d} \sqrt{p_{i_1, \dots , i_d}} |i_1 \rangle _{n_1} \otimes \dots \otimes |i_d \rangle _{n_d}, \end{aligned}$$
(3)

whereby \(\otimes \) denotes the tensor product.

This setup allows the reflection of future scenarios of quantities such as asset prices, if required also jointly with other factors.

Stochastic processes. In order to express the evolution of asset prices, their returns or those of their valuation drivers through time, stochastic processes are a convenient way to formalise the dynamics. Notably, a stochastic process \((S_t)\) implies a distribution of its modelled quantities at any future time point \(0 < t \le T\).

An important and flexible class of stochastic processes is the Ornstein-Uhlenbeck (O-U) type [85]. It has many applications in quantitative finance and can be used, for example, to model mean-reverting behaviour. A typical application is the modelling of interest rates, whose values tend to be ‘constrained’ to certain corridors through time. An O-U process is Gaussian and Markovian.Footnote 12 The general form reads \(dx_t = \theta \left( \mu - x_t\right) dt + \sigma dW_t\). Assuming the Markov property, in a discrete setting, the increments of \((S_t)\) between t to \(t+1\) can be expressed by a distribution that depends only on \(S_t\).

In the quantum setup, in analogy to (3), one can prepare \(|\psi \rangle _n\) as

$$\begin{aligned} | \underbrace{i_1}_{\Delta t} \underbrace{i_2}_{2\Delta _t} \dots \underbrace{i_N}_{T} \rangle , \end{aligned}$$

to reflect the prices or returns over time, based on N discrete time steps of length \(\Delta t = T/N\). An extension to reflect the joint evolution of multiple stochastic processes follows the same building blocks.

3.5 Distributional properties: mean and quantiles

As explained, for example, in [91], one can define a function \(f: \{0, \dots , {2^n-1} \} \rightarrow [0,1]\) and with this an operator

$$\begin{aligned} F: | i \rangle _n | 0 \rangle \rightarrow | i \rangle _n \left( \sqrt{1-f(i)} | 0 \rangle + \sqrt{f(i)} | 1 \rangle \right) , \quad i \in \{0, \dots , 2^n-1\} \end{aligned}$$

that acts on an ancilla qubit. After applying F to \( | \psi \rangle _n | 0 \rangle \) as per (2), one can use the resulting expression,

$$\begin{aligned} \sum _{i=0}^{2^n-1} \sqrt{1-f(i)} \sqrt{p_i} | i \rangle _n | 0 \rangle + \sum _{i=0}^{2^n-1} \sqrt{f(i)} \sqrt{p_i} | i \rangle _n | 1 \rangle , \end{aligned}$$

to approximate various quantities of the distribution. QAE can be applied to obtain the probability of measuring \(|1\rangle \) in the last qubit, equal to \(\sum _{i=0}^{2^n-1} p_i f(i)\). This expression is also that of the expectation of a (discrete) random variable X, i.e. \({\mathbb {E}}[f(X)]\).

Estimation of the mean. With

$$\begin{aligned} f(i) := i/(2^n - 1), \end{aligned}$$

one can estimate \({\mathbb {E}} [\frac{X}{2^n-1}]\) and from that \({\mathbb {E}} [X]\).

Estimation of distribution quantiles. Quantile estimation is integral to risk measurement. Given the stochastic nature of the evolution of value drivers for financial instruments, their future values are expressed through distributions. By zooming into a particular quantile, one can summarise the risk in a single figure. For a random variable X and a given probability level \(\alpha \in [0,1]\), the quantile measure is defined as \(Q_\alpha (X) = \inf \{x \in {\mathbb {R}}: {\mathbb {P}} [X \le x] \ge \alpha \}\). In a quantum setup, let

$$\begin{aligned} f_I(i) = {\left\{ \begin{array}{ll} 1, &{} \text {if } i \le I \\ 0, &{} \text {otherwise} \end{array}\right. } \end{aligned}$$

so that applying the corresponding \(F_I\) to \( | \psi \rangle _n | 0 \rangle \) yields a probability of measuring \(|1\rangle \) in the last qubit of \(\sum _{i=0}^{I} p_i = {\mathbb {P}}[X \le I]\). With an interval search over I one can find the smallest \(I_\alpha \) that fulfils \({\mathbb {P}}[X \le I_\alpha ] \ge \alpha \) and that is hence an estimator for \(Q_\alpha (X)\).

3.6 Motivation for application in risk measurement

Many risk calculations are based on Monte Carlo simulation in order to obtain a distribution of future ‘states of the world’, from which measures can be derived—and on which usually risk controls such as limits will be imposed.

Basic Monte Carlo approaches can be improved in various ways to enhance convergence beyond \({\mathcal {O}}(M^{-{1/2}})\). A typical example is the use of quasi-Monte Carlo simulation that relies on deterministic, low-discrepancy sequences of random draws. However, these are difficult to work with in higher dimensions that are required in financial risk calculations with a large numbers of risk factors. Not only is a better convergence rate not guaranteed, but results can even be subject to biases.

A quantum implementation for risk measurement purposes aims at exploiting the quadratic speed-up of Monte Carlo simulation offered through the use of QAE, as described in Sect. 3.3, i.e. a convergence rate \({\mathcal {O}}(M^{-1})\). Established techniques to reduce further the variance of estimators can be applied if considered necessary and suitable for high-dimensionality problems.

3.7 Quantum-specific challenges

Commercially relevant risk calculations present a particular challenge for quantum computing, especially for the following reasons:

  • Number of risk factors and their dependence structure. The currently available quantum hardware exhibits only a limited number of qubits, typically not more than around 100 [34]. This can be a severe limiting factor for large-scale practical applications. Financial risk calculations often require a significant number of risk factors (see Sect. 3.1), modelled as correlated random variables. It is in part an algorithmic problem to construct these factors as quantum states in order to minimise the use of qubits as well as gates. Even the accurate reflection of distributions as per (2) and (3) already demands at least five qubits for each dimension (equivalent to a support with \(2^5 = 32\) discrete points). Operations for risk factor convolutions, the application of payoff profiles, the determination of distributional properties and QAE itself require a non-negligible number of additional qubits. While it is possible to ‘re-use’ qubits in a quantum circuit—essentially by ‘undoing’ previous operations, exploiting the unitary nature of all quantum gates—this process is not only adding complexity but also subjects the circuit to noise (see below). Furthermore, while the number of available qubits in hardware grows, not all designs allow all operations across all qubits. An example is a ‘swap’ of any two qubits, which might be limited to certain parts of the system. Quantum simulators can be used to develop and test algorithms, but the size of the problems cannot exceed a certain size, given that the calculations would tend to be prohibitively expensive in terms of computation time on classical machines. As a consequence, at least until quantum hardware has reached a much more mature state, ‘hybrid’ approaches have been suggested: only time-critical and suitable operations—ideally in a highly QPU-optimised format—are passed from the CPU to the QPU and back afterwards, also bearing in mind noise implications [24].

  • ‘Noise’. Randomness arising from experiments like Monte Carlo simulation can be addressed by established statistical means such as confidence intervals as a function of the number of runs. An added layer of complexity in a quantum system stems from the fact that operations like gates are subject to ‘quantum noise’. This encompasses any undesired sources that change the quantum system and can originate, for example, from hardware imperfections or thermal noise. Any practical quantum algorithm therefore needs to take the impact of noise on the estimation results into account (see also Sect. 6) and, ideally, mitigate them to the largest extent possible [35, 48].

4 Application to market risk

4.1 General setup

Market risk relates to adverse changes in the PV of financial instruments. The projection horizon is usually short, between one and ten business days. It is quantified by determining the future distribution of changes to a portfolio PV. An extreme outcome of this P &L distribution is the VaR, which serves as a standard market risk measure.Footnote 13 It quantifies the extent of possible financial losses over a specific time horizon and for a given level of confidence. For a random variable \(\Delta P\) representing the P &L and a probability \(\alpha \in [0,1]\), the measure is defined as

$$\begin{aligned} \text {VaR}_{1-\alpha }(\Delta P) = -\inf \{p \in {\mathbb {R}}: {\mathbb {P}} [\Delta P \le p] \ge \alpha \}. \end{aligned}$$

Typical values in practice are \(\alpha = 0.01\) and \(\alpha = 0.05\).Footnote 14

For the actual risk calculation, it is common to model the joint distribution of the returns, i.e. moves, of all relevant risk factors (e.g. stock prices and interest rates for various maturities). In conjunction with a repricing of the instruments in a portfolio, this allows to determine the P &L distribution and, from that, the VaR. One distinguishes three key methods for its calculation:

  1. A.

    Historical VaR. Risk factors are modelled by directly applying historically observed returns to current market values. The dependence structure between risk factors is implicitly determined by their past co-movements.

  2. B.

    Parametric VaR. Risk factors are modelled using probability distributions calibrated to historical returns; simplifying assumptions such as a multivariate normal distribution are made in order to obtain closed-form expressions for the VaR.

  3. C.

    Monte Carlo VaR. Risk factors are again reflected by probability distributions calibrated to historically observed returns. The joint distributions are often fitted to historical data more closely than in the case of a Parametric VaR and, as such, usually do not allow for closed-form expressions.

The Monte Carlo VaR lends itself well to applying the QAE algorithm (as per Sect. 3.3). Practical use cases typically rely on a good representation of the marginal risk factor returns for which a normal distribution is an over-simplification.

Figure 1 summarises the components of a Monte Carlo-based market risk calculation and how classical and quantum computer implementations differ. In Sect. 4.2, the risk factor modelling and its calibration are described. Besides the move from normal to non-normal marginal factor distributions, the way to ‘decouple’ those from the dependence structure with the help of copulas is introduced. Starting from the derivation of the underlying P &L distribution, the VaR calculation itself is covered in Sect. 4.3. In Sect. 4.4, following the approach in [91], the model implementation on a quantum computer is presented; a special focus hereby lies on the distribution loading. Sect. 4.5 analyses the estimation results.

Fig. 1
figure 1

Components of a market risk calculation—comparing classical and quantum implementations. In Step A, risk factor model parameters are inferred from historical market data. With the exception of more complex model-fitting routines, there is no specific use case for a quantum algorithm, and the approach is identical to the classical one. Based on current market data, future scenarios of the world are then simulated in Step B. Combining those with risk factor sensitivities leads to the corresponding P &Ls (Step C). These two steps are formulated differently on a quantum compared to a classical computer: there are no Monte Carlo scenarios, with each being a realisation of a random variable. Instead, quantum registers represent the random variables for both the risk factor returns and the P &Ls. In order to obtain the output in the form of a risk measure (Step D), the classical approach makes use of the simulated P &L distribution and its statistics, such as an extreme quantile. A quantum algorithm will encode this last step (see Sect. 3.5) and ultimately rely on [Iterative] Quantum Amplitude Estimation to obtain a measurement

4.2 Risk factor model

4.2.1 Return definitions

Let the set of d relevant risk factors for a portfolio, for example, stocks or commodity prices, at a time point t be denoted by

$$\begin{aligned} \varvec{S_t} := (S_{1, t}, S_{2, t}, \dots , S_{d, t}). \end{aligned}$$

Between any two points t and \(t+\Delta t\), the vectors of absolute, logarithmic and relative risk factor returns are given by

$$\begin{aligned} \varvec{\Delta S_t^{\textrm{abs}}}&= \varvec{S_{t + \Delta t}} - \varvec{S_t},\\ \varvec{\Delta S_t^{\textrm{log}}}&= \ln (\varvec{S_{t + \Delta t}}) - \ln (\varvec{S_t}),\\ \varvec{\Delta S_t^{\textrm{rel}}}&= \varvec{\Delta S_t^{\textrm{abs}}} / \varvec{S_t} \approx \varvec{\Delta S_t^{\textrm{log}}}. \end{aligned}$$

The approximation for the relative returns follows from series expansion and tends to hold in the case of small returns.

4.2.2 Accommodating empirical risk factor distributions

A common approximation used particularly in Parametric VaR is that risk factor returns over a period \(\Delta t\) follow a multivariate normal distribution:

$$\begin{aligned} \varvec{\Delta S_t^{\textrm{log}}} \sim {\mathcal {N}}(\varvec{\mu }, \varvec{\Sigma }), \end{aligned}$$
(4)

with mean vector \(\varvec{\mu }\) and covariance matrix \(\varvec{\Sigma }\), both assumed to be constant over time. The associated risk factor distribution is then given by a multivariate extension of (1). An advantage of this normal model is that efficient implementations exist for the distribution loading, i.e. the preparation of quantum registers holding correlated normal random variables (see Sect. 4.4.1).

In many empirical cases, however, marginal probability density functions (PDFs) of risk factor returns are leptokurtic, and the simple normal model is not sufficiently accurate. A more appropriate modelling of actual marginal distributions is one of the main reasons for choosing a Monte Carlo over a Parametric VaR.

Copulas [60, 67] provide a convenient way of separating the marginal risk factor PDFs from the underlying dependence structure. This facilitates both calibration and efficient implementation of the Monte Carlo VaR, even for a large number of risk factors. The Sklar theorem of copula theory states that for real-valued random variables \((X_1, \dots , X_d)\) with joint cumulative density function (CDF) \(F^{X}(x_1, \dots , x_d) = {\mathbb {P}}[X_1 \le x_1, \dots , X_d \le x_d]\), there exists a copula \(C:[0,1]^d \rightarrow [0,1]\) such that

$$\begin{aligned} F^{X}(x_1, \dots , x_d) = C \left( F_1(x_1), \dots , F_d(x_d) \right) . \end{aligned}$$

Here \(F_k(x_k) = {\mathbb {P}}[X_k \le x_k]\) is the marginal distribution of random variable \(X_k\), \(k=1, \dots , d\).

For extreme market events, reflecting strong ‘tail dependence’ between the marginal risk factor distributions can be required. Here, as a simplifying assumption and in line with industry practice, a Gaussian copula is chosen:

$$\begin{aligned} C^{\text {Gaussian}}_K({\textbf{u}}) = \Phi _d(\Phi ^{-1}(u_1), \dots , \Phi ^{-1}(u_d);{\textbf{K}}), \end{aligned}$$
(5)

where \(\Phi (z)\) is the CDF of a standard normal variable, and \(\Phi _d({\textbf{z}}; {\textbf{K}})\) denotes a joint standard normal multivariate CDF with mean zero and correlation matrix \({\textbf{K}}\).Footnote 15 For classical and quantum computers, variates reflecting empirical distributions can then be generated efficiently by applying functions \(G_k\) such that \(X_k = G_k(Z_k)\). Hereby, \(Z_k\) are random variables governed by \({\varvec{Z}} \sim {\mathcal {N}}({\varvec{0}}, {\varvec{K}})\). This is apparent when first considering the CDF of \({\varvec{Z}}\) expressed in terms of the Gaussian copula, i.e.

$$\begin{aligned} F^{Z}(z_1, \dots , z_d) = C^{\text {Gaussian}}_K \left( \Phi (z_1), \dots , \Phi (z_d) \right) . \end{aligned}$$

With \(x_k = G_k(z_k) \Leftrightarrow z_k = G^{-1}_k(x_k)\), the CDF of the targeted random variables can then be written as

$$\begin{aligned} F^{X}(x_1, \dots , x_d) = C^{\text {Gaussian}}_K \left( \Phi (G^{-1}_1(x_1)), \dots , \Phi (G^{-1}_d(x_d)) \right) . \end{aligned}$$

In classical Monte Carlo simulation, samples \({\textbf{z}} = (z_1,\ldots ,z_d)\) are drawn from the multivariate normal distribution \(\Phi _d\). From this, non-normal variates are obtained through

$$\begin{aligned} x_k = G_k (z_k). \end{aligned}$$
(6)

On a quantum computer, a register represents a random variable, and the transformation \(G_k\) is applied to each of them. Given the limited number of available qubits, it is convenient to define and calibrate the quantities of interest in the following standardised way, to ensure numerical values of \(X_k\) of similar magnitude:

$$\begin{aligned} X_k := \frac{\Delta S_k^\textrm{rel}}{\sigma _k} = G_k(Z_k), \end{aligned}$$
(7)

with \(\sigma _k\) obtained from \(\varvec{\Sigma }\) in (4). The aim of the model calibration is to determine the \(G_k\) for all k.

4.2.3 Calibration

Market risk models project the P &L over a short time horizon of length \(\eta \) (years). A typical value found in practice amounts to ten business days. An assumption of 252 business days per year translates into \(\eta =10/252\). The model calibration uses at least one year of historical data prior to the risking date. In the following, four years are chosen. This is helpful in obtaining sufficiently large samples in the tails of the distributions and thereby allowing a good demonstration of the approach.

For illustration purposes, a portfolio driven by two risk factors—the stock prices of Microsoft Corporation (msft) and Apple Inc. (aapl)—is created. \(S_1\) relates to msft and \(S_2\) to aapl. Such a portfolio can consist of various financial instruments. If these were to be solely stocks, the sensitivity to price changes would be constant and equal to one (or minus one for stocks that are sold short). In the more general case, the portfolio with a current value of P will have sensitivities \(\delta _k = \frac{\partial P}{\partial S_k}\) to each risk factor and potentially higher-order ones as well.

The reference date for the calibration is selected as 1st April 2021, and the calibration data comprises the period 31st March 2017 through 31st March 2021.Footnote 16 The history of the prices for msft is plotted in Fig. 2a. By choosing ten-day returns for the calibration, the resulting distribution reflects the targeted risk projection horizon. As an initial step, the individual series of (overlapping) log-returns for the stock prices are calculated (omitting the risk factor index k in the following for clarity):Footnote 17

$$\begin{aligned} \Delta s^\textrm{log}_{t_i} = \ln (s_{t_{i + 10}}) - \ln (s_{t_i}), \end{aligned}$$

where \(s_{t_i}\) is the historical closing price at time \(t_i\), with \(i=1,2,..., n\) indexing the business days.

For the actual marginal risk factor calibrations, it is useful to postulate that the mean (‘drift’) for each stock is equal to zero. This assumption is justifiable given that the estimation of the drifts from historical data points is not only prone to large estimation uncertainty but also not necessarily predictive of the future stock price trends.

Fig. 2
figure 2

Marginal CDF. The figures are derived from msft stock price data (in USD), as shown in a. Ten-day overlapping log-returns are calculated and expressed in units of standard deviation for b through d. The distribution is leptokurtic; for example, a cumulative probability of 1% corresponds to a normal return of \(-2.33\) standard deviations and an empirical return of \(-3.26\) standard deviations. In d, for the cumulative probability associated with each empirical return on the y-axis, the corresponding normal return is plotted on the x-axis (a form of Q–Q plot); a function G as per (7) can be fitted to this data

In a multivariate normal model as per (4), the resulting parameters read \(\varvec{\mu } := ({\varvec{0}})\) and

$$\begin{aligned} \varvec{\Sigma } = \begin{pmatrix} 1.854 &{} 1.698\\ 1.698 &{} 3.446 \end{pmatrix} \cdot 10^{-3}. \end{aligned}$$

This covariance matrix equates to standard deviations of the msft and aapl stocks of \(\sigma _1 = 0.0431\) and \(\sigma _2 = 0.0587\), respectively.Footnote 18 The pairwise linear correlation amounts to about +67%.

In line with the standardised form of (7), let

$$\begin{aligned} x_i = \frac{\Delta s^\textrm{log}_{t_i} - \mu }{\sigma } \end{aligned}$$

denote the standardised risk factor series, with mean \(\mu \) and standard deviation \(\sigma \) as their respective moments. From this, the empirical cumulative probability of each value \(x_i\), \(f_i\), is calculated asFootnote 19

$$\begin{aligned} f_i = \frac{1}{n} \sum _{j=1}^n \mathbbm {1}_{ x_j \le x_i }. \end{aligned}$$

The result for msft is plotted in Fig. 2b (linear scale) and 2c (log-scale).

As outlined in Sect. 4.2.2, the aim is to obtain functions \(G_k\) for each return series k as per (7). To this end, Fig. 2d is a scatter plot for msft with \(x_i\) on the y-axis (‘empirical returns’) and \(\Phi ^{-1}(f_i)\) on the x-axis (‘normal returns’). \(G_k\) is then fitted to this data.Footnote 20 Piecewise polynomials of low order will often be sufficient for this step, which is helpful for the implementation on a quantum computer.

For the marginal msft returns, a piecewise cubic fit using seven knot points is shown in Fig. 3a. The corresponding density is plotted in Fig. 3b, over a histogram of the empirical returns. Such an approach can capture the specificities of the marginal distribution. Even a simple piecewise linear fit using only two knot points (Fig. 3c) already provides a significant improvement over a normal distribution. In particular, as shown in Fig. 3d, a much-improved fit to the 1% cumulative probability is obtained.

Fig. 3
figure 3

Fitting of marginal CDF. The functions \(G_k\) as per (7) are obtained by fitting empirical to normal returns. A piecewise cubic fit is used in a and b, with the latter demonstrating a ‘smoothing effect’ on the PDF. c and d are based on a piecewise linear fit, which already provides a reasonable approximation of the tails of the empirical distribution

4.3 VaR calculation

The portfolio P &L—between t and \(t + \Delta t\)—is a random variable, \(\Delta P\), and expressed as a function of the changes in the risk factors, here \(\Delta S^\textrm{abs}_1\) and \(\Delta S^\textrm{abs}_2\). With \(\delta \) as the stock-specific portfolio sensitivity to price changes and only retaining first-order terms:Footnote 21

$$\begin{aligned} \Delta P&= \delta _1 \Delta S^\textrm{abs}_1 + \delta _2 \Delta S^\textrm{abs}_2\\&= \delta _1 S_{1, t} \sigma _1 \frac{\Delta S_1^\textrm{rel}}{\sigma _1} + \delta _2 S_{2, t} \sigma _2 \frac{\Delta S_2^\textrm{rel}}{\sigma _2}. \end{aligned}$$

To facilitate the implementation on a quantum computer, the P &L equation is expressed using two constants a and b.Footnote 22 Furthermore, (7) is substituted:

$$\begin{aligned} \Delta P&= \delta _1 S_{1, t} \sigma _1 \left( \frac{\Delta S_1^\textrm{rel}}{\sigma _1} + b \frac{\Delta S_2^\textrm{rel}}{\sigma _2} \right) \\&= a \left( G_1(Z_1) + b G_2(Z_2) \right) \end{aligned}$$

where

$$\begin{aligned} a&= \delta _1 S_{1, t} \sigma _1 \\ b&= \frac{\delta _2 S_{2, t} \sigma _2}{\delta _1 S_{1, t} \sigma _1}. \end{aligned}$$

The normalised P &L is defined by omitting the constant a:

$$\begin{aligned} \Delta P&= a \Delta P_\textrm{norm} \nonumber \\ \Delta P_\textrm{norm}&= G_1(Z_1) + b G_2(Z_2). \end{aligned}$$
(8)

The VaR is calculated from the quantiles of \(\Delta P_\textrm{norm}\), multiplied by a in order to obtain the final result.

4.4 Setup for a quantum computer

4.4.1 Distribution loading for probability density functions

A range of algorithms has been proposed to create a joint PDF in a quantum state. The authors of [79] describe how an arbitrary quantum state can be initialised using \(2^{q-2} - 2q\) CNOT gates, where q is the total number of qubits used in all quantum registers representing the random variables. [42] describes an algorithm that can be used for ‘efficiently integrable’ PDFs. While a normal distribution can be handled, there is a restriction on the distributions that can be generated. More recent work attempts to find algorithms that can load arbitrary distributions with fewer gates [25, 96].

The functions \(G_k\) as defined in (7) can be applied to reflect the empirical marginal risk factor distributions needed for the VaR calculation. This provides an alternative to the ‘direct’ approach of [79]. The ‘piecewise transformation’ technique avoids the problem with the direct method that the number of required gates becomes prohibitive when generating large sets of risk factors as in typical market risk applications. Each approach has its advantages, however, and is presented in turn.

‘Direct’ loading. The approach of [79] is used to initialise two quantum registers representing the risk factor returns to a vector of amplitudes. This is the implementation of the loading operator \({\mathcal {P}}_X\) from Sect. 3.4.Footnote 23 The amplitudes are calculated using the joint PDF. This can be achieved by expressing the PDF with the help of the copula C:

$$\begin{aligned} f(x_1, \dots x_d)&= \frac{\partial ^d C}{\partial x_1 \dots \partial x_d}\nonumber \\&= c \left( F_1(x_1), \dots , F_d(x_d) \right) f_1(x_1) \dots f_d(x_d), \end{aligned}$$
(9)

whereby c denotes the copula density and \(f_k(x_k) = \frac{d F_k}{d x_k}\). For the case of the Gaussian copula as in (5), the density is given by

$$\begin{aligned} c^{\text {Gaussian}}_K({\varvec{u}})&=|{\varvec{K}} |^{-1/2} \exp (-{\varvec{\zeta }}^{\top } ({\varvec{K}}^{-1} - {\varvec{I_d}}) {\varvec{\zeta }}/2), \end{aligned}$$

with \({\varvec{\zeta }} := (\Phi ^{-1}(u_1),\dots ,\Phi ^{-1}(u_d))^{\top }\) and \({\varvec{I_d}}\) as the identity matrix [67].

In the d-dimensional case, the probabilities, \(p_{i_1, \dots , i_d}\), are computed using the joint PDF from (9). The discrete values of \(x_k\) are given by \(x_k^{i_k}\) with \(i_k \in \{0, \dots , n-1\}\) and n indicating the number of possible values of \(x_k\):

$$\begin{aligned} p_{i_1, \dots , i_d} = f(x^{i_1}, \dots , x^{i_d}) / \sum _{i_1, \dots , i_d} f(x^{i_1}, \dots , x^{i_d}). \end{aligned}$$

A ‘loaded state’ for the msft returns based on \(q=4\) qubits is shown in Fig. 4. For this calculation, piecewise cubic fits (as per Fig. 3a) are used to generate the CDF.Footnote 24

Fig. 4
figure 4

Marginal PDF of a calibrated quantum state. Using \(q=4\) qubits, the distribution—with \(2^4=16\) discrete states—is generated by (noise-free) simulation. The underlying CDF is the piecewise cubic fit of msft returns as per Sect. 4.2.3

Piecewise transformation. An alternative way to load the distribution is to apply transformations—the functions \(G_k\) as in (7)—to quantum registers that have been loaded in a multivariate normal state (for which efficient algorithms exist). These transformations are applied to each register in isolation. The number of required gates therefore scales linearly with the number of risk factors, rendering the algorithm suitable for large-scale calculations. The functions \(G_k\) themselves are constructed as piecewise transformations.

For the distribution loading, a three-section piecewise linear transformation is applied to a quantum register \(| i \rangle _n\), a discretised random variable defined by (2) and based on n qubits. The function is shown in Fig. 3c on the example of msft. The transformation can be written as

$$\begin{aligned} {\mathcal {F}}(i) := a_p \cdot i + b_p, \; \; \; c_{p-1} \le i < c_p, \end{aligned}$$
(10)

with \(p = 0, 1, 2\) and \(c_{-1} := -\infty \). Integer arithmetic is used: \(a_p\), \(b_p\) and \(c_p\) are all integers and, as above, \(i \in \{0, \dots , 2^n - 1 \}\). The register holding \({\mathcal {F}}(i)\) requires \(n + m\) qubits; the additional m qubits are needed as a result of the multiplication and addition/subtraction operations, i.e. m depends on \(a_p\) and \(b_p\). This setup allows a non-integer transformation of a normal return (in units of the standard deviation), z(i), to an empirical return (in units of the standard deviation), x(i). Explicitly, normal returns are discretised byFootnote 25

$$\begin{aligned} z(i) = Z_{\text {lower}} + \frac{Z_{\text {upper}} - Z_{\text {lower}}}{2^n - 1} i \end{aligned}$$

and empirical returns by

$$\begin{aligned} x(j) = X_{\text {lower}} + \frac{X_{\text {upper}} - X_{\text {lower}}}{2^{n + m} - 1} j. \end{aligned}$$

The transformation is given by

$$\begin{aligned} x(i) = G(z(i)) = X_{\text {lower}} + \frac{X_{\text {upper}} - X_{\text {lower}}}{2^{n + m} - 1} {\mathcal {F}}(i). \end{aligned}$$

As an example, a three-qubit normal distribution is converted into a five-qubit empirical distribution (\(n = 3, m = 2\)). Figure 5a shows the transformation of the actual values, and Fig. 5b plots the integer transformation as per (10). For comparison, the piecewise transformation of the real quantities without discretisation is displayed. Five qubits are chosen to represent \({\mathcal {F}}(i)\), a compromise that provides a sufficiently good fit whilst keeping the number of qubits low.

Fig. 5
figure 5

Piecewise transformation applied to a three-qubit register. a and b show a piecewise linear fit of the transformation from normal to empirical returns and a discretised form of this transformation that can be applied to the (integer) quantum registers. c and d provide the PDFs of the quantum registers pre- and post-transformation, respectively, illustrating the redistribution of probabilities. Note that an extra two qubits are added for d

This form of distribution loading is not identical to the ‘direct’ approach but instead represents a redistribution of the probability density. The normal distribution in Fig. 5c is transformed into the empirical distribution as per Fig. 5d.

4.4.2 Quantum circuit

Following the approach of [91], QAE (see Sect. 3.3) is used to compute the VaR. Figure 6a shows the layout of the circuit. It calculates cumulative probabilities of the normalised P &L \(\Delta P_\textrm{norm}\) as per (8); all numerical values derived and shown subsequently are for the case \(a := 1\), which is just a multiplicative constant. Furthermore, an example value of \(b := 1\) is chosen, although the circuit can accommodate an arbitrary value by means of modifying the piecewise transformation coefficients.Footnote 26

A correlated normal distribution is first loaded into two three-qubit registers by circuit P(x) of Fig. 6a.Footnote 27 Each three-qubit random variable is then transformed into an empirical random variable using a piecewise linear transformation circuit and added to the result register; three extra qubits are needed to store the result. Finally, an additional integer comparator—as described in [91]—is used to generate the single-qubit objective, the amplitude of which is to be estimated. A bisection search applied to the CDF is then employed to calculate the VaR (see as well [91] for more details).

Fig. 6
figure 6

Quantum circuit for market risk. a shows the circuit that obtains a quantum register of P &Ls. As a final step, an integer comparator (‘cmp’) is applied, which flips the objective qubit if the register value is less than a specified integer; the amplitude of this objective is then estimated using QAE. In order to test the Qiskit implementation, one million measurements of the result register are used to construct the probability distribution of the P &L, as shown in b. For comparison, the equivalent distribution is obtained by classical Monte Carlo simulation through one million samples drawn from a continuous multivariate normal distribution and transformed using (6); the result is displayed in c

The details of the piecewise transformation circuits are shown in Fig. 7. Integer comparators compare the value in the n-qubit register to \(c_0\) and \(c_1\) of (10). The resulting qubits are used to control three in-place multiply-add circuits that apply the three linear transformations of (10) for \(p \in \{ 0, 1, 2 \}\). Each of the three performs an in-place multiplication by a classical integer and in-place addition with the result, followed by an addition with a classical integer. This arithmetic makes use of circuits adapted from [86].Footnote 28 A number of ancilla qubits are required to perform the piecewise transformation. These are ‘uncomputed’ following each transformation and then re-used for each marginal distribution.

Fig. 7
figure 7

Quantum circuit for piecewise transformation applied to a three-qubit register. Three conditional in-place multiply-add circuits are used to apply (10) for \(p \in \{ 0, 1, 2 \}\). The coefficients \(a_p\) and \(b_p\) used in the multiply-adds are classical. Two integer comparators store the result of \(i \ge c_0\) and \(i \ge c_1\) into ancilla qubits ancilla_0 and ancilla_1, respectively. Two additional qubits, ancilla_8 and ancilla_9, are used to calculate booleans \(i < c_0\) and \(c_0 \le i < c_1\) from these qubits. ancilla_8, ancilla_9 and ancilla_1 are then utilised to condition the multiply-add circuits. The multiply-add circuits include an ‘uncompute’ step, and additional gates (shown) are added to uncompute ancilla_8, ancilla_9 and ancilla_10. Finally, the comparator ancillas ancilla_0 and ancilla_1 are uncomputed. These steps allow the ancilla qubits to be re-used

The circuit ‘depth’, as a measure of size and representing the smallest number of steps required to execute an experiment, depends on the circuit transpiler and the quantum hardware to run on. While gates without common qubits can be processed in the same step, every gate that has at least one qubit in common needs to act on a different step. Using only elementary rotation and conditional NOT gates, the depth amounts to 9,387 (\(q=2\) per risk factor) and 22,589 (\(q=3\)), respectively.Footnote 29

4.5 Estimation results

All computations are carried out on a quantum simulator.Footnote 30 The implementation of the quantum circuit is tested by executing the quantum circuit and the final comparator of Fig. 6a to calculate the probability distribution of the normalised P &L. This is shown in Fig. 6b. The analogue can be achieved classically, by using the PDF of the discretised quantum register output from P(x) of Fig. 6a and the same coefficients for the piecewise approximation as in the quantum case. In this way, it is verified that the same distribution is produced. The classical calculation without using the same discretisation as the quantum circuit—in fact, without discretisation at all—is shown in Fig. 6c.

Fig. 8
figure 8

Cumulative normalised P &L probability distribution. The normalised P &L refers to the definition in (8). The values obtained using \(q=2\) and \(q=3\) qubits per risk factor are shown, together with the ‘continuous’ values—i.e. with no discretisation

With this validation complete, the (Iterative) QAE algorithmFootnote 31 is applied to the objective qubit of the circuit of Fig. 6a. This is used to obtain the CDF of the normalised P &L as per (8). The cumulative probabilities are shown in Fig. 8a, b which are identical apart from the scale. The results are plotted with three qubits for each of the two correlated normal registers (the case shown in Fig. 7), as well as the two-qubit case for comparison. The result obtained without discretisation error is also provided as a reference. For this comparison, continuous normal distributions are used in place of the discretised versions, in conjunction with a piecewise linear transformation free from discretisation error.Footnote 32 This can be thought of as being the result calculated with a large number of qubits. Results for three typical P &L quantiles are found in Table 1.Footnote 33 Using \(q=3\) qubits for each normal register provides a tolerable—though still rather large—level of discretisation error. The 99% VaR calculated using three qubits amounts to -6.22 and differs by around 14% from the correct value of -5.44. Practitioners would therefore likely require a larger number of qubits.Footnote 34

Table 1 Estimation results for the market risk example

5 Application to counterparty credit risk

5.1 General setup

Counterparty credit risk (CCR) is concerned with cases where one party to a portfolio of instruments—usually bilaterally negotiated financial derivatives—defaults and is not able to honour its obligations.Footnote 35 Examples of such transactions are forwards, which allow to lock in an exchange rate such as USD/EUR in advance, and options, which entail the right to purchase or sell assets such as stocks or commodities at a pre-determined price at a later date. While market risk is centred around losses occurring from a decline in the value of instruments, CCR arises from portfolios that have a positive PV and which cannot be realised if the counterparty defaults. Since the surviving party, such as a bank, will typically have hedged the exposure with other—non-defaulted—counterparties, it is left with ‘open’ positions in this case. Replacing those in the market will in some circumstances only be possible at worse conditions than at origination. CCR is therefore the loss associated with these replacement costs.

Contrary to straightforward loans, the exposure over time versus a particular counterparty is not deterministic if the instruments are exposed to PV changes. This is nearly always the case with derivatives.Footnote 36 CCR modelling is about estimating the Potential Future Exposure (PFE).

If trade netting has been agreed between the parties, positive and negative PVs can be offset against each other in the case of a default. A notable mitigant of CCR exposure is the use of collateral, which can be posted between the counterparties or by one or both of them to an independent depositary. As an example, if party A buys an option from party B, B will post the PV of the option at inception as collateral (‘variation margin’). This, in turn, renders the resulting exposure equal to zero since A could use the collateral to enter a new option trade in case B were to default. As the value of the option evolves over time, the collateral balance is either topped up or decreased—or in some cases, left unchanged.Footnote 37 For the purposes of PFE measurement, the collateral balance through time is added to the portfolio PVs to determine the overall counterparty exposure profile.Footnote 38 In spite of using variation margin, residual CCR can result from the legal and operational process associated with a default requiring several days or even weeks to complete. A re-hedging in the market by the surviving counterparty might hence only take place with a delay. During this ‘slippage’ period, the market value of the portfolio can evolve and lead to non-zero replacement costs even after taking any received collateral into account. As a solution, additional ‘initial margin’ can be posted by both parties, these days typically to a third-party custodian bank. In case of a default, the amount is released to cover any slippage-related costs.Footnote 39

In order to obtain the PFE of a portfolio, one will focus on a projection horizon (T) that covers the period up to the longest maturity across all instruments. The time interval is divided into N, not necessarily equally spaced discrete points \(t_i \in [0, T], i = 1, 2, \dots N\) with \(t_{i} < t_{i+1}\) and \(t_0 = 0\). In the first process step, risk drivers of the instruments (e.g. stock prices) are diffused over time, expressed either by means of stochastic processes or through distributions.Footnote 40 In certain cases, the resulting risk factor distribution at each \(t_i\) is known in closed form; in the most general case, it can be approximated through Monte Carlo simulation. On the back of the joint risk factor distributions across time, the corresponding instrument PVs as well as the resulting portfolio PVs are determined as a second step.Footnote 41 In cases where collateral is exchanged between the parties, a third step is added, applying the projected collateral value across time and adding it to the PVs. Since CCR is only concerned with positive balances vis-a-vis a counterparty, the portfolio PVs including collateral are transformed into exposures by flooring them to zero. The result of these steps is a series of exposure distributions \(E_{t_i}\), \(i = 1, 2, \dots N\).Footnote 42\(^{,}\)Footnote 43 Given the stochastic nature of the exposure, one will often work with quantile measures, \(q_c(E_{t_i})\), to quantify the CCR. Hereby, \(c \in \{0.90, 0.95, 0.99\}\) are typical quantiles chosen in practice.Footnote 44 One can loosely interpret CCR as a through-time variant of market risk, with a focus on the positive rather than the negative tail of the P &L distributions.

The following exploration builds on the market risk example from Sect. 4. In this case, let the portfolio consist of bought call options on each of the two stocks, msft and aapl, and both maturing at time \(T = 2\) (years from now). The respective stock prices over time shall be denoted by \(S_{k, t}\), \(k = 1,2\). The options give the holder the right to purchase the underlying stock at T and a pre-determined price (‘strike’) K. If the stock price ends up above K at maturity, the option will be ‘in-the-money’ and can be exercised against the seller accordingly.Footnote 45 For simplicity, let \(K=0\) for both options here, which means that they are always exercised at maturity and, importantly, that their PVs are equal to \(S_{k, t}\) for all t. With risk factors and instrument values coinciding in this case, the revaluation over time (see step two above) can be avoided. The initial option premia are assumed to sum up to 100. They have been paid by the buyer, and collateral (variation margin) in the same amount has been posted by the seller; this hence renders the initial exposure \(E_0 = 0\). No further collateral is exchanged throughout the life of the instruments. The PFE projection interval [0, T] is reflected by \(N = 2\) equidistant time steps of length T/N.

Fig. 9
figure 9

Components of a counterparty credit risk calculation—comparing classical and quantum implementations. The components of the counterparty credit risk calculation are broadly analogous to those in the market risk case (see Fig. 1). Again, the main implementation difference lies in the move from Monte Carlo scenarios to working directly with random variables in the form of qubit registers

Figure 9 provides a sketch of the components required for a counterparty credit risk calculation and how classical and quantum computer implementations differ.

5.2 Risk factor model

The risk drivers behind an exposure calculation need to be evolved in a dependent (‘correlated’) way, as for market risk applications. The historical calibration period in practice usually stretches over three years or more. A particular challenge in CCR modelling is to capture the long-term evolution of risk drivers and their dependence.

For the postulated example portfolio composed of call options, the two stock prices are the only relevant risk drivers.Footnote 46 Assuming that these evolve according to (4) as in the market risk case, the means (‘drifts’) \(\varvec{\mu }\) again amount to zero for both stocks. Recalling that the covariance matrix \(\varvec{\Sigma }\) in Sect. 4.2.3 is based on ten-day returns, its values are scaled to \(\varvec{\Sigma '} = \varvec{\Sigma } \cdot \frac{252}{10}\) in order to reflect an annual horizon.

5.3 Exposure calculation

The starting point is given by \(E_0 = 0\). With a time horizon of \(T=2\) (years) and \({N=2}\) time points for the process discretisation, the PFE for the options portfolio from the buyer’s perspective is to be determined at \(t = 1\) and \(t = 2 (= T)\). In each of these periods, the joint stock returns are governed by \({\mathcal {N}}(\varvec{\mu }, \varvec{\Sigma '})\). This, in turn, describes the PV evolution of the two options over time and, as such, determines the counterparty exposure for the option holder.

Ignoring a flooring to zero for better illustration, the CDFs of the respective exposures \(E_t\) are described by the distributions of PVs, including the initial collateral. The 90%, 95% and 99% quantiles serve as dedicated exposure measures.

5.4 Setup for a quantum computer

The approach follows the technique for measuring credit risk in [91], extended to a multi-period setup.Footnote 47 The steps to reflect the task on a quantum computer consist in

  • loading the probability distributions (see Sect. 3.4);

  • adding the distributions across time steps;Footnote 48

  • using (Iterative) Quantum Amplitude Estimation (see Sect. 3.3) to determine the values of the CDF and, from that, the exposure quantiles.

Fig. 10
figure 10

Stylised quantum circuit for counterparty credit risk. The setup shows a two-period setting. The first block of qubits (risk_factor_prob1) reflects the two risk factors, discretised with two qubits each. The second block (risk_factor_prob2) is the equivalent set for the second period. qae_objective is the objective qubit required for the (iterative) quantum amplitude estimation. sum_factor_risk_factors serve for the addition of the risk factor distributions. The final CDF_return_sum are used to evaluate the CDF at a given point. aux_addition and aux_compare are the required ancillaries for the circuit

For the two-dimensional risk factor distribution, assume that each of the marginal stock return distributions is discretised using q qubits. Repeating this over all N time steps results in 2qN qubits required for the quantum setup. The addition of the distributions across time steps as well as the final IQAE step demand additional qubits. In Fig. 10, the case of \(q=2\) and \(N=2\) is depicted in a stylised circuit diagram. Figure 11 provides a snapshot of the first few gates when preparing the actual quantum circuit scheme. In a two-time step setup and again using only elementary rotation and conditional NOT gates, the circuit depth reads 1,015 (\(q=2\) per risk factor) and 2,237 (\(q=3\)), respectively.

Fig. 11
figure 11

Quantum circuit for counterparty credit risk—gate decomposition. The graph shows the first set of gates behind the loading of the probability distribution for the first risk factor, as per Fig. 10. \(U(\theta , \phi ,\lambda )\) standards for single-qubit gate and its Euler rotation angles. In the given case, \(U(\theta , 0, 0)\) represents rotations along the Y-axis with angle \(\theta \). The two-qubit ‘+’ operations are conditional NOT (‘CNOT’) gates. Using only these two elementary building blocks, the entire circuit with its 20 qubits (of which twelve are ‘state qubits’) has a depth of 1,015—a number that typically also depends on the optimisation during the transpilation.

Note that it is not obvious how to create a single quantum circuit that can provide measures for distributional quantiles at several time points as an output. A pragmatic way to generate exposure figures over multiple forecasting horizons is to use separate quantum circuits for each, which can be generated algorithmically in a straightforward manner.

5.5 Estimation results

The main output from the estimation is the CDF of the exposure at a given time point. Results are again obtained with the help of a quantum simulator. In Fig. 12, the classically derived CDF are compared to those from the quantum computation; for the latter, \(q=2\) or \(q=3\) qubits are used for each of the risk factor distributions.Footnote 49 In the given example, the ‘correct’ CDF is depicted (right scale), together with its 90% quantile as a typical risk quantity in the CCR context.

At both \(t=1\) and \(t=2\) (years), when using only \(q=2\) qubits per risk factor, the resulting CDF is very far off (left scale). This is driven by the fact that the risk factor distributions are discretised only very coarsely (four points each). With \(q=3\) qubits per risk factor (eight points each), the approximation is much better. In the latter case, the deviation from the correct CDF is well below 0.05 across the range for both projection horizons.

Fig. 12
figure 12

Distribution functions for the counterparty credit risk example. For two time horizons, (a) \(t=1\) and (b) \(t=2\) (years), the figures compare the CDF of the PFE between classical and quantum computation. For the example at hand, the results for the classical case are known in closed form (dotted CDF, right scale). The quantum estimations are obtained by using \(q=2\) or \(q=3\) qubits to reflect each of the distributions; notably, the actual quantum circuits require a series of additional (ancillary) qubits to execute the required operations. The figures show the differences in CDF across the distribution range (left scale). The 90% quantile, as a typical quantity to measure counterparty credit risk exposure, is marked explicitly (vertical dotted line). Confidence intervals around the quantum estimates, obtained by applying IQAE with \(2^{10} = \text{1,024 }\) shots each, are very tight and hence omitted in the figures. Notably, they are of much lower magnitude than the differences in the CDFs themselves.

Table 2 summarises how the CDF estimations translate into actual exposure figures. At inception at \(t=0\), the exposure is zero. The table provides the PFE at both time horizons, \(t=1\) and \(t=2\), and for the 90%, 95% and 99% quantile.

Table 2 Estimation results for the counterparty credit risk example

The results from the classical computation—here obtained as the sum of two multivariate normal distributions and hence available in closed form—are shown in Panel A. These figures reflect scenarios where the (highly correlated) stock prices increase substantially, giving rise to high PVs of the options in the portfolio. In spite of the initial collateral exchange, a counterparty default could result in a sizable undercollateralisation and associated replacement costs for the option holder.

As evidenced in Panel B, in line with results for the CDF in Fig. 12, using only two qubits per risk factor leads to significant errors in the exposure estimates.Footnote 50 This renders those essentially unusable in practice. The case of three qubits per factor limits the PFE errors to about \(\pm 10\%\), which is more tolerable and reaches a level of approximation that might be suitable for practical applications in risk measurement. For example, the actual 90% quantile one and two years ahead reads 82 and 134, respectively. The quantum equivalents with three qubits per risk factor are 75 and 127, i.e. off by 9% and 5%.

6 Influence of quantum noise

The analyses in Sects. 4 and 5 assume ideal, not yet available quantum hardware. Besides the discussed loss of accuracy from a limited number of qubits, quantum circuits experience ‘noise’ in practice. This results from quantum processors being susceptible to their environment and losing their quantum state due to quantum decoherence [35, 48]. The theoretical quadratic speed-up compared to classical Monte Carlo simulation is therefore highly dependent on whether this quantum error can be contained and ideally eliminated in future [5]. Until this is achieved, quantum noise needs to be factored into any results obtained from circuits like those proposed here for risk measurement. Otherwise, certain conclusions would not be valid: for instance, even when adding more and more qubits to a system, the measurement of financial risks could still be of no use if noise levels distorted the resulting figures.

While the aspect of quantum noise lends itself to further in-depth research, at least an approximate impact analysis is required for the cases discussed here. Understanding the sensitivity of the measurements to typical noise levels sheds light on how much noise can be tolerated to render results accurate enough for practical applications.

The magnitude of quantum noise on current state-of-the-art gate-based devices amounts to about 0.1% for each gate, somewhat varying, for example, based on how many qubits a gate is applied to [39]. In the following, all one- and two-qubit gates in the quantum circuit as well as the final measurement are subjected to these noise levels to form a simplified ‘noise model’. Practically, this entails flipping each bit with the given probability on every affected operation in the circuit. Continuing the work on a quantum simulator,Footnote 51 the model is applied to the example for counterparty credit risk from Sect. 5.Footnote 52

Using \(q=3\) qubits per risk factor and time point \(t=1\), Fig. 13a compares the CDF for the PFE in the case of no noise as well as with the defined noise model. It is visually evident that the resulting perturbation can have a non-negligible influence on the risk measurement. In Fig. 13b, the noise level is varied around the base case of 0.1% with a factor of \(2^i, {i=-3,-2,\dots ,+3}\); from this, the resulting relative errors in the CDF quantiles relative to the ‘noise-free’ case are calculated. For instance, the 90% quantile in the base case with 0.1% of noise exhibits a relative error of about 15%. For lower noise levels, the relative error in the quantile(s) tapers down, while it increases substantially in the case of more pronounced noise.

Fig. 13
figure 13

Influence of ‘noise’ in the counterparty credit risk example. When adding ‘noise’ of 0.1% to all one- and two-qubit gates in the quantum circuit as well as for the final measurement, a shows the influence on the CDF for a horizon of \(t=1\) (years) and \(q=3\) (qubits) for both risk factors. b illustrates how different levels of noise translate into errors in the estimation of typical PFE quantiles

According to Table 2, even for the promising case with \(q=3\) qubits per risk factor, the typical noise levels distort the estimations and—given relative errors easily exceeding \(\pm 25\%\)—render them essentially unusable.

7 Conclusion and outlook

The study investigates the feasibility of implementing real-world risk measurement applications on quantum computers. Typical use cases in financial institutions such as banks require large-scale solutions with usually several thousands of risk factors. The core challenge is to project those at one or over several future time points and revalue portfolios of instruments accordingly. Extending previous research, this paper contributes a feasibility analysis with respect to running realistic market and counterparty credit risk applications on quantum devices.

On a conceptual level, modelling risk factors and simulating their joint behaviour that ultimately determines the relevant distributions for risk measurement is feasible. The single-horizon nature of a market risk measure renders the setup more accessible than for the case of counterparty credit risk, which demands multiple, longer-term projections. Moving away from idealised normal distributions and potentially even a linear dependence structure amongst risk factors is achievable.

The central limiting aspect from a practical angle is the far too-limited capacity in terms of available qubits on real-world devices that would be necessary to reflect the large set of required risk factors with sufficient accuracy and across multiple forecasting horizons. Specific optimisations such as in-place additions of risk factors are possible, but this does not materially address the limitation. A secondary though still important aspect is quantum noise: even for basic examples of VaR and PFE calculations, the accuracy of risk estimations is quickly downgraded beyond a tolerable level. Loading realistic probability distributions to quantum registers and representing non-trivial payoffs and pricing functions are additional obstacles.

In the current ‘noisy intermediate-scale quantum’ (NISQ) era, the path to real-world applications in risk measurement depends heavily on progress in the various active areas of quantum research. Besides the hardware and its accessibility, error control and mitigation are essential topics to be addressed. Hereby, the trade-off between model and circuit complexity on one side and acceptable measurement error tolerance on the other side need to be operationalised for practical use. The optimal interaction between CPU, GPU and QPU is another field for further exploration, specifically for risk applications. In [89], three critical attributes for quantum computing performance are put forward—quality (measured by quantum volume), speed (measured by circuit layer operations per second), and scale (measured by number of qubits). The ultimate aim is to define holistic benchmarks that capture all system components, are appropriate for real-world applications, without being too cumbersome to execute and difficult to interpret.

Overall, the analysis evidences that the number of qubits available on current hardware, and even within quantum simulators, is still far too low to render an actual business application viable. This constraint might be eased in the not-too-distant future, however, based on claims that hardware with more than 1,000 qubits are deemed achievable by 2023 [34]. Nevertheless, only once the stated target of 1,000,000 qubits on a fault-tolerant quantum computer by 2029 is reached [17], at least certain computationally intensive algorithms and applications from the financial engineering world might be routinely handled with quantum hardware.

Given the comparatively new technology, applying quantum computing—especially in established areas such as risk measurement—will face certain scepticism at the beginning. This is even more relevant when also applied for calculating regulatory capital requirements and, as such, demanding approval from supervisors. The initial enthusiasm by banks is already wearing a bit thin meanwhile, given that ready-to-use technology is still a long way off [22]. The business case from a computational angle is not very strong in areas such as market and counterparty credit risk since running ‘traditional’ calculations even in large financial institutions is currently a matter of minutes or at most a few hours. A quadratic speed-up of Monte Carlo simulations is hence not removing major obstacles. The pricing of derivatives, even complex ones, has already been established in principle by now—with promising short-term feasibility [18]. However, the commercial need for a large-scale roll-out is not apparent even here, given that the speed-up is ultimately limited and that latency for non-vanilla derivatives is not a significant concern in practice. The same might not be true for so far intractable problems such as portfolio optimisation, which are therefore more suitable contenders for a first wave of real-world (risk) applications.