Skip to content

Commit

Permalink
Add properties for latest 10K and 10Q
Browse files Browse the repository at this point in the history
  • Loading branch information
dgunning committed Nov 11, 2024
1 parent 63b82eb commit ccd038a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
35 changes: 23 additions & 12 deletions edgar/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from edgar.core import (log, Result, display_size, listify, is_using_local_storage,
filter_by_date, IntString, InvalidDateException, reverse_name, get_edgar_data_directory)
from edgar.financials import Financials
from edgar.company_reports import TenK, TenQ
from edgar.httprequests import download_json, download_text, download_bulk_data
from edgar.reference import states
from edgar.reference.tickers import get_company_tickers, get_icon_from_ticker, find_cik
Expand Down Expand Up @@ -401,26 +402,36 @@ def __init__(self,
self._loaded_all_filings: bool = False

@property
def financials(self):
"""
Get the latest 10-K financials
"""
def latest_tenk(self) -> Optional[TenK]:
if self.is_company:
# Get the latest 10-K
latest_10k = self.get_filings(form='10-K', trigger_full_load=False).latest()
if latest_10k is not None:
return Financials.extract(latest_10k)
return latest_10k.obj()

@property
def quarterly_financials(self):
def latest_tenq(self) -> Optional[TenQ]:
if self.is_company:
latest_10q = self.get_filings(form='10-Q', trigger_full_load=False).latest()
if latest_10q is not None:
return latest_10q.obj()

@property
def financials(self) -> Optional[Financials]:
"""
Get the latest 10-K financials
"""
tenk_filing = self.latest_tenk
if tenk_filing is not None:
return tenk_filing.financials

@property
def quarterly_financials(self)-> Optional[Financials]:
"""
Get the latest 10-Q financials
"""
if self.is_company:
# Get the latest 10-K
latest_10k = self.get_filings(form='10-Q', trigger_full_load=False).latest()
if latest_10k is not None:
return Financials.extract(latest_10k)
tenq_filing = self.latest_tenq
if tenq_filing is not None:
return tenq_filing.financials

@property
def is_company(self) -> bool:
Expand Down
14 changes: 12 additions & 2 deletions tests/test_entity.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from edgar import get_entity
from edgar.entities import get_entity_submissions, Entity, Company

from edgar.company_reports import TenK, TenQ

def test_entity_is_company():
# TSLA
Expand Down Expand Up @@ -99,4 +99,14 @@ def test_getting_company_financials_does_not_load_additional_filings():
c = Company("KO")
f = c.financials
assert f
assert not c._loaded_all_filings
assert not c._loaded_all_filings


def test_get_latest_company_reports():
c = Company(1318605)
tenk = c.latest_tenk
assert tenk
assert isinstance(tenk, TenK)
tenq = c.latest_tenq
assert tenq
assert isinstance(tenq, TenQ)

0 comments on commit ccd038a

Please sign in to comment.