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] Forward EBITDA #6433

Merged
merged 9 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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,75 @@
"""Forward EBITDA Estimates Standard Model."""

from datetime import date as dateType
from typing import Optional, Union

from pydantic import Field, field_validator

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


class ForwardEbitdaEstimatesQueryParams(QueryParams):
"""Forward EBITDA Estimates Query Parameters."""

symbol: Optional[str] = Field(
default=None,
description=QUERY_DESCRIPTIONS["symbol"],
)

@field_validator("symbol", mode="before", check_fields=False)
@classmethod
def to_upper(cls, v):
"""Convert field to uppercase."""
return v.upper() if v else None


class ForwardEbitdaEstimatesData(Data):
"""Forward EBITDA Estimates Data."""

symbol: str = Field(description=DATA_DESCRIPTIONS.get("symbol", ""))
name: Optional[str] = Field(default=None, description="Name of the entity.")
last_updated: Optional[dateType] = Field(
default=None,
description="The date of the last update.",
)
period_ending: Optional[dateType] = Field(
default=None,
description="The end date of the reporting period.",
)
fiscal_year: Optional[int] = Field(
default=None, description="Fiscal year for the estimate."
)
fiscal_period: Optional[str] = Field(
default=None, description="Fiscal quarter for the estimate."
)
calendar_year: Optional[int] = Field(
default=None, description="Calendar year for the estimate."
)
calendar_period: Optional[Union[int, str]] = Field(
default=None, description="Calendar quarter for the estimate."
)
low_estimate: Optional[ForceInt] = Field(
default=None, description="The EBITDA estimate low for the period."
)
high_estimate: Optional[ForceInt] = Field(
default=None, description="The EBITDA estimate high for the period."
)
mean: Optional[ForceInt] = Field(
default=None, description="The EBITDA estimate mean for the period."
)
median: Optional[ForceInt] = Field(
default=None, description="The EBITDA estimate median for the period."
)
standard_deviation: Optional[ForceInt] = Field(
default=None,
description="The EBITDA estimate standard deviation for the period.",
)
number_of_analysts: Optional[int] = Field(
default=None,
description="Number of analysts providing estimates for the period.",
)
33 changes: 33 additions & 0 deletions openbb_platform/extensions/equity/integration/test_equity_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1982,3 +1982,36 @@ def test_equity_estimates_forward_pe(params, headers):
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@parametrize(
"params",
[
(
{
"symbol": "AAPL,MSFT",
"fiscal_period": "quarter",
"provider": "intrinio",
}
),
(
{
"symbol": "AAPL,MSFT",
"fiscal_period": "annual",
"limit": None,
"include_historical": False,
"provider": "fmp",
}
),
],
)
@pytest.mark.integration
def test_equity_estimates_forward_ebitda(params, headers):
"""Test the equity estimates forward_ebitda 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/estimates/forward_ebitda?{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 @@ -750,6 +750,36 @@ def test_equity_estimates_forward_eps(params, obb):
assert len(result.results) > 0


@parametrize(
"params",
[
(
{
"symbol": "AAPL,MSFT",
"fiscal_period": "quarter",
"provider": "intrinio",
}
),
(
{
"symbol": "AAPL,MSFT",
"fiscal_period": "annual",
"limit": None,
"include_historical": False,
"provider": "fmp",
}
),
],
)
@pytest.mark.integration
def test_equity_estimates_forward_ebitda(params, obb):
"""Test the equity estimates forward EBITDA endpoint."""
result = obb.equity.estimates.forward_ebitda(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@parametrize(
"params",
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,36 @@ async def forward_sales(
return await OBBject.from_query(Query(**locals()))


@router.command(
model="ForwardEbitdaEstimates",
examples=[
APIEx(parameters={"provider": "intrinio"}),
APIEx(
parameters={
"symbol": "AAPL",
"fiscal_period": "annual",
"provider": "intrinio",
}
),
APIEx(
parameters={
"symbol": "AAPL,MSFT",
"fiscal_period": "quarter",
"provider": "fmp",
}
),
],
)
async def forward_ebitda(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Get forward EBITDA estimates."""
return await OBBject.from_query(Query(**locals()))


@router.command(
model="ForwardEpsEstimates",
examples=[
Expand Down
Loading
Loading