View on GitHub
Open this notebook in GitHub to run it yourself
Value at Risk
Introduction
Value at Risk (VaR) is a widely used financial risk metric that estimates the maximum expected loss of a portfolio over a given time horizon at a specified confidence level, based on the probability distribution of returns. Classical VaR calculations for complex portfolios often rely on Monte Carlo simulations, which can be computationally expensive and slow to converge. Quantum computing can improve this process by using Iterative Quantum Amplitude Estimation (IQAE) to estimate loss probabilities more efficiently. IQAE provides a quadratic speedup over classical Monte Carlo methods by estimating expected values with fewer samples, without requiring deep quantum circuits. This makes it particularly suitable for near-term quantum hardware and enables faster, more accurate VaR calculations for high-dimensional and non-linear financial portfolios.Modeling the Value at Risk Problem
As a first step, we have to model the problem mathematically. We will use a simple yet powerful model, which captures the essence of portfolio optimization: First, we will import the Python libraries required for this implementation. Classiq, of course, and Numpy.Output:
Output:
Output:

The Binary Search Approach To Calculate Value At Risk
We can solve the Value at Risk use-case also with a binary search approach. This approach will benefit us from a complexity perspective once we will integrate the quantum function that calculates alpha given an index.Output:
Value at Risk using Iterative Quantum Amplitude Estimation (IQAE)
Iterative Quantum Amplitude Estimation (IQAE) is a key algorithm in the quantum computing toolbox. It is useful for quantum-enhanced Monte Carlo methods, which are in use for several important quantum finance applications like Value at Risk (VaR) estimation. The goal of Quantum Amplitude Estimation (QAE) is to estimate the probability (or amplitude) of a certain outcome from a quantum circuit. Compared to other classical methods, some has been presented above in this notebook - it is potentially quadratically faster. IQAE is a NISQ-friendly version of the traditional Quantum Amplitude Estimation (QAE), and includes the following stages:- State preparation encoding the desired probabilty, in this case - for not losing more than $X for an asset or a portfolio of asset.
- Use controlled applications of the Grover operator (unlike QAE, which utilises Fourier Transform)
- Measure and update the estimate using classical methods.
Defining The State Preparation for the IQAE Algorithm
In order to use IQAE, we need to define the state preparation function, which includes two main parts:- Loading the distribution of the asset values into a quantum state.
- Defining the payoff function, which marks the states where the asset value is below a certain threshold (the index in this case).
Output: