Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when running fundlens #17

Closed
karim1104 opened this issue Jun 9, 2021 · 3 comments
Closed

Error when running fundlens #17

karim1104 opened this issue Jun 9, 2021 · 3 comments

Comments

@karim1104
Copy link

All functions ran perfectly except for fundlens. I got the following error:


KeyError Traceback (most recent call last)
in
8 )
9
---> 10 fundlens(portfolio)

~/anaconda3/lib/python3.8/site-packages/empyrial.py in fundlens(my_portfolio, period)
484
485 #book value
--> 486 book_value = yahoo_financials.get_book_value()
487
488 #operating income

~/anaconda3/lib/python3.8/site-packages/yahoofinancials/init.py in get_book_value(self)
794 # Financial Statement Data Methods
795 def get_book_value(self):
--> 796 return self._financial_statement_data('balance', 'balanceSheetHistoryQuarterly',
797 'totalStockholderEquity', 'quarterly')
798

~/anaconda3/lib/python3.8/site-packages/yahoofinancials/init.py in _financial_statement_data(self, stmt_type, stmt_code, field_name, freq)
685 except (IndexError, AttributeError, TypeError):
686 date_key = list(re_data[self.ticker][0])[0]
--> 687 data = re_data[self.ticker][0][date_key][field_name]
688 else:
689 data = {}

KeyError: 'totalStockholderEquity'

@karim1104
Copy link
Author

When I use different tickers (portfolio= ["TSLA","AMZN","FB","GOOG","AAPL"]), I get a different error:


KeyError Traceback (most recent call last)
~/anaconda3/lib/python3.8/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2897 try:
-> 2898 return self._engine.get_loc(casted_key)
2899 except KeyError as err:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'inventory'

The above exception was the direct cause of the following exception:

KeyError Traceback (most recent call last)
in
8 )
9
---> 10 fundlens(portfolio)

~/anaconda3/lib/python3.8/site-packages/empyrial.py in fundlens(my_portfolio, period)
503
504 #inventory
--> 505 inventory = df.iloc[:,0]['inventory']
506
507 #total liabilities

~/anaconda3/lib/python3.8/site-packages/pandas/core/series.py in getitem(self, key)
880
881 elif key_is_scalar:
--> 882 return self._get_value(key)
883
884 if is_hashable(key):

~/anaconda3/lib/python3.8/site-packages/pandas/core/series.py in _get_value(self, label, takeable)
988
989 # Similar to Index.get_value, but we do not fall back to positional
--> 990 loc = self.index.get_loc(label)
991 return self.index._get_values_for_loc(self, loc, label)
992

~/anaconda3/lib/python3.8/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2898 return self._engine.get_loc(casted_key)
2899 except KeyError as err:
-> 2900 raise KeyError(key) from err
2901
2902 if tolerance is not None:

KeyError: 'inventory'

@ssantoshp
Copy link
Owner

Thanks for raising the issue, just fixed it in the new version =)

You can try it out here: https://colab.research.google.com/drive/1x22fJ5bnc5ZVwj05_k-cKarj9GXw5J8W?usp=sharing

If it's ok for you, we can close this issue.

@karim1104
Copy link
Author

Confirmed working with the new version.
Thank you very much!
And by the way, incredible work you're doing here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants