# Qiskit Portfolio Optimization Application

I recently got flung into the world of quantum computing and I'm a beginner at coding. I was assigned to do the Portfolio Optimization tutorial of the Qiskit Finance Tutorials and input real data. Truth be told, I'm clueless. It's my understanding that I have to replace the "TICKER" and "RandomDataProvider" parts of the code in order to generate a real-life portfolio.

# Generate expected return and covariance matrix from (random) time-series
stocks = [("TICKER%s" % i) for i in range(num_assets)]
data = RandomDataProvider(tickers=stocks,
start=datetime.datetime(2016,1,1),
end=datetime.datetime(2016,1,30))
data.run()
mu = data.get_period_return_mean_vector()
sigma = data.get_period_return_covariance_matrix()


I've imported Quandl and WikipediaDataProvider. I want to keep the number of assets the same, using Microsoft "MSFT", Disney "DIS", Nike "NKE", and Home Depot "HD" stocks. How might I apply this financial from Quandl to the tutorial? I've tried this so far:

num_assets = 4

# Generate expected return and covariance matrix from (random) time-series
stocks = [("MSFT%s" , "DIS%s" , "NKE%s" , "HD%s" % i) for i in range(num_assets)]
token="xeesvko2fu6Bt9jg-B1T",
start=datetime.datetime(2016,1,1),
end=datetime.datetime(2016,1,30))
data.run()
mu = data.get_period_return_mean_vector()
sigma = data.get_period_return_covariance_matrix()


But get the error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-59-19e4d9cde1e3> in <module>
3 # Generate expected return and covariance matrix from (random) time-series
4 stocks = [("MSFT%s" , "DIS%s" , "NKE%s" , "HD%s" % i) for i in range(num_assets)]
6                  token="xeesvko2fu6Bt9jg-B1T",
7                  start=datetime.datetime(2016,1,1),

TypeError: Can't instantiate abstract class WikipediaDataProvider with abstract methods run


I apologize for my limited coding skills - I'm very new to all of this! Thank you in advance.

• Welcome to the community @Lana! Could you also link the QISKit tutorial you're referencing? At first glance, this seems to be more of a Quandl/Wikipedia problem than Qiskit question Aug 12, 2020 at 17:01
• Thank you @C.Kang! I used the link qiskit.org/documentation/tutorials/finance/… which was generated from github.com/Qiskit/qiskit-tutorials/blob/master/tutorials/… .
– Lana
Aug 12, 2020 at 18:21
• Could you update the links? Those are broken Aug 12, 2020 at 19:35
• I actually got it all amended. Thank you for your willingness to help! :)
– Lana
Aug 12, 2020 at 20:16
• Great! Could you also post your solution? A2As help for future people with similar questions :D Aug 12, 2020 at 21:13

I changed the stock parameter to a list of strings and added the line stockmarket = StockMarket.NASDAQ as such:

num_assets = 4

# Generate expected return and covariance matrix from (random) time-series
stocks = ['MSFT', 'DIS', 'NKE', 'HD']
print(sigma)$$$$
`