如何在 Python 上使用 FinQuant 访问 Quandl 网络数据?

How do I access Quandl web data with FinQuant on Python?

尝试通过 FinQuant 包访问 quandl 数据时出现错误


import pandas as pd
import datetime
import quandl
from finquant.portfolio import build_portfolio
quandl.api_config.api_key = "*************"
d = {
     0: {"Name": "BP.", "Allocation": 1000000},
     1: {"Name": "III", "Allocation": 1000000},
     2: {"Name": "GSK", "Allocation": 1000000},
     3: {"Name": "OCDO", "Allocation": 1000000},
     4: {"Name": "RBS", "Allocation": 2000000},
     5: {"Name": "SVT", "Allocation": 1000000},
     }

pf_allocation = pd.DataFrame.from_dict(d, orient="index")

#set list of names based on names
names = pf_allocation["Name"].values.tolist()

#start/end date
start = datetime.datetime(2018, 7, 1)
end = datetime.datetime(2019, 6, 30)

#building portfolio

pf = build_portfolio(
        names=names, pf_allocation=pf_allocation, start_date=start, end_date=end
)

得到这个:

wdir='C:/Users/Joe Shiafa Pierce/.spyder-py3')
Traceback (most recent call last):

  File "<ipython-input-15-*********>", line 1, in <module>
    runfile('C:/Users/Joe Shiafa Pierce/.spyder-py3/FinQuant POM project.py', wdir='C:/Users/Joe Shiafa Pierce/.spyder-py3')

  File "C:\Users\Joe Shiafa Pierce\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile
    execfile(filename, namespace)

  File "C:\Users\Joe Shiafa Pierce\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/Joe Shiafa Pierce/.spyder-py3/FinQuant POM project.py", line 27, in <module>
    names=names, pf_allocation=pf_allocation, start_date=start, end_date=end

  File "C:\Users\Joe Shiafa Pierce\Anaconda3\lib\site-packages\finquant\portfolio.py", line 1153, in build_portfolio
    pf = _build_portfolio_from_api(**kwargs)

  File "C:\Users\Joe Shiafa Pierce\Anaconda3\lib\site-packages\finquant\portfolio.py", line 930, in _build_portfolio_from_api
    data = _quandl_request(names, start_date, end_date)

  File "C:\Users\Joe Shiafa Pierce\Anaconda3\lib\site-packages\finquant\portfolio.py", line 763, in _quandl_request
    raise Exception("Error during download of stock data from Quandl.")

Exception: Error during download of stock data from Quandl.

非常感谢任何帮助。

我尝试使用

分别下载每个代码的股票价格数据
import quandl
quandl.get("WIKI/BP.")

完成后,Quandl 似乎找不到您使用的 tickers/names。例如。 BP. 在 Quandl 上不是有效的 ticker/name。您可能是指 BP。其他大部分也无效。

您可能想查看 Quandl 上的 ticker/name 列表:Quandl stock identifiers

与有效 tickers/names 一起使用时,例如III,FinQuant 应该 return 一个投资组合对象。