This project is archived
Qiskit Finance is no longer maintained and this documentation is no longer updated. It is kept online for reference only, and the code it describes may not work with current versions of Qiskit. See the project repository for more information.
PortfolioOptimization#
- class PortfolioOptimization(expected_returns, covariances, risk_factor, budget, bounds=None)[source]#
Bases:
OptimizationApplicationOptimization application for the “portfolio optimization” [1] problem.
References
[1]: “Portfolio optimization”, https://en.wikipedia.org/wiki/Portfolio_optimization
- Parameters:
expected_returns (ndarray) – The expected returns for the assets.
covariances (ndarray) – The covariances between the assets.
risk_factor (float) – The risk appetite of the decision maker.
budget (int) – The budget, i.e. the number of assets to be selected.
bounds (List[Tuple[int, int]] | None) – The list of tuples for the lower bounds and the upper bounds of each variable. e.g. [(lower bound1, upper bound1), (lower bound2, upper bound2), …]. Default is None which means all the variables are binary variables.
Attributes
- bounds#
Getter of the lower bounds and upper bounds of each selectable assets.
- Returns:
The lower bounds and upper bounds of each assets selectable
- budget#
Getter of budget
- Returns:
The budget, i.e. the number of assets to be selected.
- covariances#
Getter of covariances
- Returns:
The covariances between the assets.
- expected_returns#
Getter of expected_returns
- Returns:
The expected returns for the assets.
- risk_factor#
Getter of risk_factor
- Returns:
The risk appetite of the decision maker.
Methods
- interpret(result)[source]#
Interpret a result as a list of asset indices
- Parameters:
result (OptimizationResult | ndarray) – The calculated result of the problem
- Returns:
The list of asset indices whose corresponding variable is 1
- Return type:
- portfolio_expected_value(result)[source]#
Returns the portfolio expected value based on the result.
- Parameters:
result (OptimizationResult | ndarray) – The calculated result of the problem
- Returns:
The portfolio expected value
- Return type:
- portfolio_variance(result)[source]#
Returns the portfolio variance based on the result
- Parameters:
result (OptimizationResult | ndarray) – The calculated result of the problem
- Returns:
The portfolio variance
- Return type:
- static sample_most_likely(state_vector)#
Compute the most likely binary string from state vector.
- Parameters:
state_vector (QuasiDistribution | Statevector | ndarray | Dict) – state vector or counts or quasi-probabilities.
- Returns:
binary string as numpy.ndarray of ints.
- Raises:
ValueError – if state_vector is not QuasiDistribution, Statevector, np.ndarray, or dict.
- Return type:
- to_quadratic_program()[source]#
Convert a portfolio optimization problem instance into a
QuadraticProgram.- Returns:
The
QuadraticProgramcreated from the portfolio optimization problem instance.- Return type: