3. Quantum Optimization#
Portfolio Optimization#
Adapted from:
https://qiskit-community.github.io/qiskit-finance/tutorials/01_portfolio_optimization.html
We are given a set of \(n\) assets, labeled as \(\{1, 2, ..., n\}\), each with an expected return \(\mu_i\). In this simplified model, we have a binary choice: either choose an asset of do not. We wish to find the maximum return:
where \(x_i \in \{0, 1\}\) indicates a decision:
\(x_i=1\) we pick asset \(i\)
\(x_i=0\) don’t pick asset \(i\)
However we also want to take risk into account, which can be done via the covariances between the assets \(\sigma_{ij}\). Thus we want to minimize the following cost function:
where \(q\) is the risk factor.
To understand this cost function note that:
For \(q=0\) we just pick the best assests based on expected return
For \(q>0\) we take volatility into account
For \(q >>0\) we pick the assets with low variance and negative covariance
For more on the portfolio model see here.
Create the Data#
We will use randomly generated data using RandomDataProvider
.
The number of assets num_assets
will equal the number of qubits required in the quantum computation.
Define Terms#
If \(p_i^{(t)}\) is the price at time \(t\) for asset \(i\) then define \(d_i^{(t)}\) as the return at time \(t\)
To compute \(\mu_i\) we calculate the mean return over the whole period:
and similarly for the covariance
where \(T\) is the total number of timesteps.
Classial Solution#
Here we minimize the cost function by seacrhing through all the combinations of \(\{x_i\}\). This scales as \(2^{n}\).
Quantum Solution#
To Solve on a QC, we change to \(x_i=(1-z_i)/2\)
Now we have the Quantum Hamiltonian:
Given an ansatz \(|\psi(\theta)\rangle\) we minimize \(\langle \psi(\theta)|H|\psi(\theta)\rangle\) to find our solution.
With constraint#
Suppose we have a budget \(B \in N\) we must spend, i.e.
Quantum Solution#
We can force our quantum algorithm to find such solution by introducing a penalty term in the cost function
where \(\tilde n = \frac{n - 2B}{2}.\)
Thus our Hamiltonian is now