diff --git a/README.md b/README.md index edc668d13..305cbc067 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,8 @@ msft.capital_gains # only for mutual funds & etfs msft.get_shares_full(start="2022-01-01", end=None) # show financials: +msft.calendar +msft.sec_filings # - income statement msft.income_stmt msft.quarterly_income_stmt diff --git a/yfinance/base.py b/yfinance/base.py index bf258a3f8..14f58f513 100644 --- a/yfinance/base.py +++ b/yfinance/base.py @@ -171,6 +171,10 @@ def get_calendar(self, proxy=None) -> dict: self._quote.proxy = proxy or self.proxy return self._quote.calendar + def get_sec_filings(self, proxy=None) -> dict: + self._quote.proxy = proxy or self.proxy + return self._quote.sec_filings + def get_major_holders(self, proxy=None, as_dict=False): self._holders.proxy = proxy or self.proxy data = self._holders.major diff --git a/yfinance/scrapers/quote.py b/yfinance/scrapers/quote.py index d25c77696..a155c6209 100644 --- a/yfinance/scrapers/quote.py +++ b/yfinance/scrapers/quote.py @@ -496,6 +496,7 @@ def __init__(self, data: YfData, symbol: str, proxy=None): self._recommendations = None self._upgrades_downgrades = None self._calendar = None + self._sec_filings = None self._already_scraped = False self._already_fetched = False @@ -563,6 +564,13 @@ def calendar(self) -> dict: self._fetch_calendar() return self._calendar + @property + def sec_filings(self) -> dict: + if self._sec_filings is None: + f = self._fetch_sec_filings() + self._sec_filings = {} if f is None else f + return self._sec_filings + @staticmethod def valid_modules(): return quote_summary_valid_modules @@ -710,3 +718,35 @@ def _fetch_calendar(self): self._calendar['Revenue Average'] = earnings.get('revenueAverage', None) except (KeyError, IndexError): raise YFDataException(f"Failed to parse json response from Yahoo Finance: {result}") + + + def _fetch_sec_filings(self): + result = self._fetch(self.proxy, modules=['secFilings']) + if result is None: + return None + + filings = result["quoteSummary"]["result"][0]["secFilings"]["filings"] + + # Improve structure + for f in filings: + if 'exhibits' in f: + f['exhibits'] = {e['type']:e['url'] for e in f['exhibits']} + f['date'] = datetime.datetime.strptime(f['date'], '%Y-%m-%d').date() + + # Experimental: convert to pandas + # for i in range(len(filings)): + # f = filings[i] + # if 'exhibits' in f: + # for e in f['exhibits']: + # f[e['type']] = e['url'] + # del f['exhibits'] + # filings[i] = f + # filings = pd.DataFrame(filings) + # for c in filings.columns: + # if c.startswith('EX-'): + # filings[c] = filings[c].astype(str) + # filings.loc[filings[c]=='nan', c] = '' + # filings = filings.drop('epochDate', axis=1) + # filings = filings.set_index('date') + + return filings diff --git a/yfinance/ticker.py b/yfinance/ticker.py index d5824bf8c..73f14dece 100644 --- a/yfinance/ticker.py +++ b/yfinance/ticker.py @@ -168,6 +168,10 @@ def calendar(self) -> dict: """ return self.get_calendar() + @property + def sec_filings(self) -> dict: + return self.get_sec_filings() + @property def recommendations(self): return self.get_recommendations()