def test_portfolio(self):
     """ portfolio test """
     algo = NumPyMinimumEigensolver(self.qubit_op)
     result = algo.run()
     selection = sample_most_likely(result.eigenstate)
     value = portfolio.portfolio_value(selection, self.muu, self.sigma,
                                       self.risk, self.budget, self.penalty)
     np.testing.assert_array_equal(selection, [0, 1, 1, 0])
     self.assertAlmostEqual(value, -0.00679917)
    def test_portfolio_qaoa(self):
        """ portfolio test with QAOA """
        qaoa = QAOA(self.qubit_op, COBYLA(maxiter=500), initial_point=[0., 0.])

        backend = BasicAer.get_backend('statevector_simulator')
        quantum_instance = QuantumInstance(backend=backend,
                                           seed_simulator=self.seed,
                                           seed_transpiler=self.seed)
        result = qaoa.run(quantum_instance)
        selection = sample_most_likely(result.eigenstate)
        value = portfolio.portfolio_value(selection, self.muu, self.sigma,
                                          self.risk, self.budget, self.penalty)
        np.testing.assert_array_equal(selection, [0, 1, 1, 0])
        self.assertAlmostEqual(value, -0.00679917)