santoshlite / Empyrial

An Open Source Portfolio Backtesting Engine for Everyone | 面向所有人的开源投资组合回测引擎
https://empyrial.gitbook.io/empyrial/
MIT License
902 stars 123 forks source link

Error with stocks data #115

Open sebvalton67116 opened 9 months ago

sebvalton67116 commented 9 months ago

First and foremost, I wanted to let you know how much I adore your work and how big of a fan I am of your Empyrial library on Python! I use it quite often for my analyses.

I'm reaching out today because I've been facing an issue when running the code, regardless of the date I choose: it indicates there's a data problem. The specific issue is as follows:

ValueError Traceback (most recent call last) in <cell line: 27>() 25 ) 26 benchmark=["SPY"] ---> 27 empyrial(portfolio) 28 29

1 frames /usr/local/lib/python3.10/dist-packages/empyrial/main.py in get_returns(stocks, wts, start_date, end_date) 148 initial_alloc = wts/assets.iloc[0] 149 if initial_alloc.isna().any(): --> 150 raise ValueError("Some stock is not available at initial state!") 151 portfolio_value = (assets * initial_alloc).sum(axis=1) 152 returns = portfolio_value.pct_change()[1:]

ValueError: Some stock is not available at initial state!

I've tried to resolve it by using more recent dates to download titles, but it still doesn't work.

santoshlite commented 9 months ago

Could you give a minimal reproducible example, please?

dvolosh commented 1 month ago

Make sure the tickers are NYSE/NASDAQ and not international. Was getting the same error

santoshlite commented 1 month ago

Actually if they are tickers that can be found on yfinance in general they should work. You can also use custom data if needed (check the doc!)