From eb31f5672686fe1d282bc3bbc3fcc148e83671aa Mon Sep 17 00:00:00 2001 From: "JC (Jonathan Chen)" <11434205+dijonkitchen@users.noreply.github.com> Date: Sun, 22 Sep 2024 15:20:52 -0400 Subject: [PATCH] feat(sec): add fiscal period filter for SEC company concepts --- .../openbb_sec/models/compare_company_facts.py | 5 +---- .../providers/sec/openbb_sec/utils/frames.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/openbb_platform/providers/sec/openbb_sec/models/compare_company_facts.py b/openbb_platform/providers/sec/openbb_sec/models/compare_company_facts.py index 80ce0f5972bf..fd60df192ae1 100644 --- a/openbb_platform/providers/sec/openbb_sec/models/compare_company_facts.py +++ b/openbb_platform/providers/sec/openbb_sec/models/compare_company_facts.py @@ -158,14 +158,11 @@ async def aextract_data( warn( "The 'instantaneous' parameter is ignored when a symbol is supplied." ) - if query.fiscal_period is not None: - warn( - "The 'fiscal_period' parameter is ignored when a symbol is supplied." - ) results = await get_concept( symbol=query.symbol, fact=query.fact, year=query.year, + fiscal_period=query.fiscal_period, use_cache=query.use_cache, ) if not results: diff --git a/openbb_platform/providers/sec/openbb_sec/utils/frames.py b/openbb_platform/providers/sec/openbb_sec/utils/frames.py index 210fdbea85a3..25c3d114f157 100644 --- a/openbb_platform/providers/sec/openbb_sec/utils/frames.py +++ b/openbb_platform/providers/sec/openbb_sec/utils/frames.py @@ -187,6 +187,7 @@ async def get_concept( symbol: str, fact: str = "Revenues", year: Optional[int] = None, + fiscal_period: Optional[FISCAL_PERIODS] = None, taxonomy: Optional[TAXONOMIES] = "us-gaap", use_cache: bool = True, ) -> Dict: @@ -206,6 +207,8 @@ async def get_concept( In previous years, they may have reported as "Revenues". year : int, optional The year to retrieve the data for. If not provided, all reported values will be returned. + fiscal_period: Literal["fy", "q1", "q2", "q3", "q4"], optional + The fiscal period to retrieve the data for. If not provided, all reported values will be returned. taxonomy : Literal["us-gaap", "dei", "ifrs-full", "srt"], optional The taxonomy to use. Defaults to "us-gaap". use_cache: bool @@ -268,6 +271,18 @@ async def get_one(ticker): if not results: raise EmptyDataError(f"{messages}") + if fiscal_period is not None: + filtered_results = [ + d for d in results if str(fiscal_period) == str(d.get("fp")) + ] + if len(filtered_results) > 0: + results = filtered_results + if len(filtered_results) == 0: + warn( + f"No results were found for {fact} in the fiscal period, {fiscal_period}." + " Returning all entries instead. Concept and fact names may differ by company and year." + ) + if year is not None: filtered_results = [d for d in results if str(year) == str(d.get("fy"))] if len(filtered_results) > 0: