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

feat(sec): add fiscal period filter for SEC company concepts #6685

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions openbb_platform/providers/sec/openbb_sec/utils/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Loading