• Members 9 posts
    Nov. 9, 2021, 10:45 a.m.

    Can anyone help explain how to formulate a portfolio optimization problem into a quantum algorithm?

    Problem setup: Similar to the simple financial case, assume that we have a list of investment options, and know the corresponding covariance matrix $\Sigma$ and expected return $\mu$. I have budget $B$ and I can accept risks quantified by a risk factor $q$. I need to decide which options to buy within my budget, such that I can maximize the returns but minimize the risks.

    Questions:
    1. How can I use quantum algorithms to find the optimal portfolio?
    2. What is the advantage of this quantum algorithm compared to classical algorithms?

    Thank you very much!

  • Members 19 posts
    Nov. 22, 2021, 8:27 a.m.

    Let me try to answer the first question about how to use quantum algorithms to optimize the portfolio.

    Step 1. Formulate the problem in a quadratic form
    Step 2. Find the Hamiltonian corresponds to the quadratic problem
    Step 3. Choose a method to search for the ground state of the Hamiltonian, which would be the optimal solution

    Step 1

    Let x be the vector that record the asset allocation. The optimal portfolio maximize the return and minimize the risk, which is equivalent to minimizing
    $$
    q x^T \Sigma x - \mu^T x,
    $$
    which is subject to
    $$
    \mathbb{1}^T x = B
    $$

    This is a typical quadratic optimization problem. In Qiskit, you can code it simple by calling the PortfolioOptimization package

    from qiskit_finance.applications.optimization import PortfolioOptimization
    
    # Define the portfolio
    portfolio = PortfolioOptimization(expected_returns = mu, covariances = sigma, risk_factor = q, budget = B, bounds = None)
    
    # Translate the portfolio into a quadratic program
    qp = portfolio.to_quadratic_program()
    

    Step 2 and 3

    In quantum computation, a quadratic optimization problem can be solved as a ground state search of a Hamiltonian. Especially, in simple cases where elements of $x$ can only take 1 or 0 (in other words, you only decide whether to allocate investment in a certain asset), the corresponding quantum model is called Ising model, where every element in $x$ is mapped to a particle with spin up or spin down.

    Qiskit has very well written package to help you do this mapping from quadratic problem to Hamiltonian. You only need to choose a method to search for the ground state, such as VQE.

    from qiskit import Aer
    from qiskit.algorithms import VQE
    from qiskit.algorithms.optimizers import *
    
    optimizer = SLSQP(maxiter=1000)  
    algorithm_globals.random_seed = 1234
    backend = Aer.get_backend('statevector_simulator')
    
    vqe = VQE(optimizer=optimizer, quantum_instance=backend)
    
    vqe_meo = MinimumEigenOptimizer(vqe)  
    
    result = vqe_meo.solve(qp)