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

Implement fetch sec-filings #2009

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions yfinance/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions yfinance/scrapers/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions yfinance/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading