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

[Feature] Compare Company Facts (SEC) #6444

Merged
merged 10 commits into from
May 21, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Compare Company Facts Model."""

from datetime import date as dateType
from typing import Optional

from pydantic import Field

from openbb_core.provider.abstract.data import Data
from openbb_core.provider.abstract.query_params import QueryParams
from openbb_core.provider.utils.descriptions import (
DATA_DESCRIPTIONS,
QUERY_DESCRIPTIONS,
)


class CompareCompanyFactsQueryParams(QueryParams):
"""Compare Company Facts Query."""

symbol: Optional[str] = Field(
default=None, description=QUERY_DESCRIPTIONS.get("symbol", "")
)
fact: str = Field(
default="",
description="The fact to lookup, typically a GAAP-reporting measure. Choices vary by provider.",
)


class CompareCompanyFactsData(Data):
"""Compare Company Facts Data."""

symbol: Optional[str] = Field(
default=None, description=DATA_DESCRIPTIONS.get("symbol", "")
)
name: Optional[str] = Field(default=None, description="Name of the entity.")
value: float = Field(
description="The reported value of the fact or concept.",
)
reported_date: Optional[dateType] = Field(
default=None, description="The date when the report was filed."
)
period_beginning: Optional[dateType] = Field(
default=None,
description="The start date of the reporting period.",
)
period_ending: Optional[dateType] = Field(
default=None,
description="The end date of the reporting period.",
)
fiscal_year: Optional[int] = Field(
default=None,
description="The fiscal year.",
)
fiscal_period: Optional[str] = Field(
default=None,
description="The fiscal period of the fiscal year.",
)
39 changes: 39 additions & 0 deletions openbb_platform/extensions/equity/integration/test_equity_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2015,3 +2015,42 @@ def test_equity_estimates_forward_ebitda(params, headers):
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@parametrize(
"params",
[
(
{
"provider": "sec",
"symbol": "NVDA,AAPL,AMZN,MSFT,GOOG,SMCI",
"fact": "RevenueFromContractWithCustomerExcludingAssessedTax",
"year": 2024,
"fiscal_period": None,
"instantaneous": False,
"use_cache": False,
}
),
(
{
"provider": "sec",
"symbol": None,
"fact": None,
"year": None,
"fiscal_period": None,
"instantaneous": False,
"use_cache": False,
}
),
],
)
@pytest.mark.integration
def test_equity_compare_company_facts(params, headers):
"""Test the equity compare company_facts endpoint."""
params = {p: v for p, v in params.items() if v}

query_str = get_querystring(params, [])
url = f"http://0.0.0.0:8000/api/v1/equity/compare/company_facts?{query_str}"
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200
Original file line number Diff line number Diff line change
Expand Up @@ -1877,3 +1877,41 @@ def test_equity_estimates_forward_pe(params, obb):
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@parametrize(
"params",
[
(
{
"provider": "sec",
"symbol": "NVDA,AAPL,AMZN,MSFT,GOOG,SMCI",
"fact": "RevenueFromContractWithCustomerExcludingAssessedTax",
"year": 2024,
"fiscal_period": None,
"instantaneous": False,
"use_cache": False,
}
),
(
{
"provider": "sec",
"symbol": None,
"fact": None,
"year": None,
"fiscal_period": None,
"instantaneous": False,
"use_cache": False,
}
),
],
)
@pytest.mark.integration
def test_equity_compare_company_facts(params, obb):
"""Test the equity compare company_facts endpoint."""
params = {p: v for p, v in params.items() if v}

result = obb.equity.compare.company_facts(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,34 @@ async def groups(
Performance metrics include the stock price change for different time periods.
"""
return await OBBject.from_query(Query(**locals()))


@router.command(
model="CompareCompanyFacts",
examples=[
APIEx(parameters={"provider": "sec"}),
APIEx(
parameters={
"provider": "sec",
"fact": "PaymentsForRepurchaseOfCommonStock",
"year": 2023,
}
),
APIEx(
parameters={
"provider": "sec",
"symbol": "NVDA,AAPL,AMZN,MSFT,GOOG,SMCI",
"fact": "RevenueFromContractWithCustomerExcludingAssessedTax",
"year": 2024,
}
),
],
)
async def company_facts(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Copmare reported company facts and fundamental data points."""
return await OBBject.from_query(Query(**locals()))
Loading
Loading