0

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)] data = WikipediaDataProvider(tickers=stocks, 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)] ----> 5 data = WikipediaDataProvider(tickers=stocks, 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.

2 Answers 2

1

The stocks parameter should be a list of strings. If you try:

stocks = ['MSFT', 'DIS', 'NKE', 'HD'] 

It will work. Just make sure you have the latest Qiskit installed. I ran myself and printed mu and sigma:

mu: [ 0.00057085 -0.00379642 0.00057495 -0.00209479] sigma: [[0.00059268 0.00036507 0.00022995 0.00025648] [0.00036507 0.00041735 0.00016424 0.00027058] [0.00022995 0.00016424 0.0002836 0.00022028] [0.00025648 0.00027058 0.00022028 0.00042107]] 
Sign up to request clarification or add additional context in comments.

Comments

0

I signed up for Quandl but it wouldn't give me anything beyond 2016 for free. Yahoo seemed to work for me without any token, and with the latest data.

data = YahooDataProvider( tickers = ["AAPL", "MSFT","WORK","TEAM"], start=datetime.datetime(2020, 9, 1), end=datetime.datetime(2020, 9, 30)) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.