我最近被扔进了量子计算的世界,我是编码的初学者。我被指派做 Qiskit Finance 教程的投资组合优化教程并输入真实数据。说实话,我一无所知。我的理解是,我必须替换代码的“TICKER”和“RandomDataProvider”部分才能生成真实的投资组合。
# 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()
我已经导入了 Quandl 和 WikipediaDataProvider。我想保持资产数量不变,使用微软“MSFT”、迪士尼“DIS”、耐克“NKE”和家得宝“HD”股票。我如何将 Quandl 的财务数据应用到教程中?到目前为止,我已经尝试过:
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()
但得到错误:
---------------------------------------------------------------------------
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
我为我有限的编码技能道歉 - 我对这一切都很陌生!先感谢您。