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] Add PCE (Personal Consumption Expenditures) reports to Economy #6578

Merged
merged 4 commits into from
Jul 11, 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,31 @@
"""Personal Consumption Expenditures Standard Model."""

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

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 PersonalConsumptionExpendituresQueryParams(QueryParams):
"""Personal Consumption Expenditures Query."""

date: Optional[Union[dateType, str]] = Field(
default=None,
description=QUERY_DESCRIPTIONS.get("date", "")
+ " Default is the latest report.",
)


class PersonalConsumptionExpendituresData(Data):
"""Personal Consumption Expenditures Data."""

date: dateType = Field(description=DATA_DESCRIPTIONS.get("date", ""))
symbol: str = Field(description=DATA_DESCRIPTIONS.get("symbol", ""))
value: float = Field(description=DATA_DESCRIPTIONS.get("value", ""))
24 changes: 24 additions & 0 deletions openbb_platform/extensions/economy/integration/test_economy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,3 +973,27 @@ def test_economy_survey_nonfarm_payrolls(params, headers):
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@parametrize(
"params",
[
(
{
"provider": "fred",
"date": "2024-05-01,2024-04-01,2023-05-01",
"category": "pce_price_index",
}
),
],
)
@pytest.mark.integration
def test_economy_pce(params, headers):
"""Test the economy pce 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/economy/pce?{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 @@ -921,3 +921,26 @@ def test_economy_survey_nonfarm_payrolls(params, obb):
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@parametrize(
"params",
[
(
{
"provider": "fred",
"date": "2024-05-01,2024-04-01,2023-05-01",
"category": "pce_price_index",
}
),
],
)
@pytest.mark.integration
def test_economy_pce(params, obb):
"""Test the economy pce endpoint"""
params = {p: v for p, v in params.items() if v}

result = obb.economy.pce(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
Original file line number Diff line number Diff line change
Expand Up @@ -539,3 +539,27 @@ async def primary_dealer_positioning(
) -> OBBject:
"""Get Primary dealer positioning statistics."""
return await OBBject.from_query(Query(**locals()))


@router.command(
model="PersonalConsumptionExpenditures",
examples=[
APIEx(parameters={"provider": "fred"}),
APIEx(
description="Get reports for multiple dates, entered as a comma-separated string.",
parameters={
"provider": "fred",
"date": "2024-05-01,2024-04-01,2023-05-01",
"category": "pce_price_index",
},
),
],
)
async def pce(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Get Personal Consumption Expenditures (PCE) reports."""
return await OBBject.from_query(Query(**locals()))
154 changes: 154 additions & 0 deletions openbb_platform/openbb/assets/reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -7955,6 +7955,160 @@
},
"model": "PrimaryDealerPositioning"
},
"/economy/pce": {
"deprecated": {
"flag": null,
"message": null
},
"description": "Get Personal Consumption Expenditures (PCE) reports.",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.economy.pce(provider='fred')\n# Get reports for multiple dates, entered as a comma-separated string.\nobb.economy.pce(provider='fred', date='2024-05-01,2024-04-01,2023-05-01', category=pce_price_index)\n```\n\n",
"parameters": {
"standard": [
{
"name": "date",
"type": "Union[Union[Union[str, date], str], List[Union[Union[str, date], str]]]",
"description": "A specific date to get data for. Default is the latest report. Multiple items allowed for provider(s): fred.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "provider",
"type": "Literal['fred']",
"description": "The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: fred.",
"default": null,
"optional": true
}
],
"fred": [
{
"name": "category",
"type": "Literal['personal_income', 'wages_by_industry', 'real_pce_percent_change', 'real_pce_quantity_index', 'pce_price_index', 'pce_dollars', 'real_pce_chained_dollars', 'pce_price_percent_change']",
"description": "The category to query.",
"default": "personal_income",
"optional": true,
"choices": [
"personal_income",
"wages_by_industry",
"real_pce_percent_change",
"real_pce_quantity_index",
"pce_price_index",
"pce_dollars",
"real_pce_chained_dollars",
"pce_price_percent_change"
]
}
]
},
"returns": {
"OBBject": [
{
"name": "results",
"type": "List[PersonalConsumptionExpenditures]",
"description": "Serializable results."
},
{
"name": "provider",
"type": "Optional[Literal['fred']]",
"description": "Provider name."
},
{
"name": "warnings",
"type": "Optional[List[Warning_]]",
"description": "List of warnings."
},
{
"name": "chart",
"type": "Optional[Chart]",
"description": "Chart object."
},
{
"name": "extra",
"type": "Dict[str, Any]",
"description": "Extra info."
}
]
},
"data": {
"standard": [
{
"name": "date",
"type": "date",
"description": "The date of the data.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "symbol",
"type": "str",
"description": "Symbol representing the entity requested in the data.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "value",
"type": "float",
"description": "",
"default": "",
"optional": false,
"choices": null
}
],
"fred": [
{
"name": "name",
"type": "str",
"description": "The name of the series.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "element_id",
"type": "str",
"description": "The element id in the parent/child relationship.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "parent_id",
"type": "str",
"description": "The parent id in the parent/child relationship.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "children",
"type": "str",
"description": "The element_id of each child, as a comma-separated string.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "level",
"type": "int",
"description": "The indentation level of the element.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "line",
"type": "int",
"description": "The line number of the series in the table.",
"default": "",
"optional": false,
"choices": null
}
]
},
"model": "PersonalConsumptionExpenditures"
},
"/equity/calendar/ipo": {
"deprecated": {
"flag": null,
Expand Down
91 changes: 91 additions & 0 deletions openbb_platform/openbb/package/economy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ROUTER_economy(Container):
indicators
long_term_interest_rate
money_measures
pce
primary_dealer_positioning
retail_prices
risk_premium
Expand Down Expand Up @@ -1806,6 +1807,96 @@ def money_measures(
)
)

@exception_handler
@validate
def pce(
self,
date: Annotated[
Union[str, datetime.date, None, List[Union[str, datetime.date, None]]],
OpenBBField(
description="A specific date to get data for. Default is the latest report. Multiple comma separated items allowed for provider(s): fred."
),
] = None,
provider: Annotated[
Optional[Literal["fred"]],
OpenBBField(
description="The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: fred."
),
] = None,
**kwargs
) -> OBBject:
"""Get Personal Consumption Expenditures (PCE) reports.

Parameters
----------
date : Union[str, datetime.date, None, List[Union[str, datetime.d...
A specific date to get data for. Default is the latest report. Multiple comma separated items allowed for provider(s): fred.
provider : Optional[Literal['fred']]
The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: fred.
category : Literal['personal_income', 'wages_by_industry', 'real_pce_percent_change', 'real_pce_quantity_index', 'pce_price_index', 'pce_dollars', 'real_pce_chained_dollars', 'pce_price_percent_change']
The category to query. (provider: fred)

Returns
-------
OBBject
results : List[PersonalConsumptionExpenditures]
Serializable results.
provider : Optional[Literal['fred']]
Provider name.
warnings : Optional[List[Warning_]]
List of warnings.
chart : Optional[Chart]
Chart object.
extra : Dict[str, Any]
Extra info.

PersonalConsumptionExpenditures
-------------------------------
date : date
The date of the data.
symbol : str
Symbol representing the entity requested in the data.
value : float

name : Optional[str]
The name of the series. (provider: fred)
element_id : Optional[str]
The element id in the parent/child relationship. (provider: fred)
parent_id : Optional[str]
The parent id in the parent/child relationship. (provider: fred)
children : Optional[str]
The element_id of each child, as a comma-separated string. (provider: fred)
level : Optional[int]
The indentation level of the element. (provider: fred)
line : Optional[int]
The line number of the series in the table. (provider: fred)

Examples
--------
>>> from openbb import obb
>>> obb.economy.pce(provider='fred')
>>> # Get reports for multiple dates, entered as a comma-separated string.
>>> obb.economy.pce(provider='fred', date='2024-05-01,2024-04-01,2023-05-01', category='pce_price_index')
""" # noqa: E501

return self._run(
"/economy/pce",
**filter_inputs(
provider_choices={
"provider": self._get_provider(
provider,
"economy.pce",
("fred",),
)
},
standard_params={
"date": date,
},
extra_params=kwargs,
info={"date": {"fred": {"multiple_items_allowed": True}}},
)
)

@exception_handler
@validate
def primary_dealer_positioning(
Expand Down
4 changes: 4 additions & 0 deletions openbb_platform/providers/fred/openbb_fred/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
from openbb_fred.models.overnight_bank_funding_rate import (
FredOvernightBankFundingRateFetcher,
)
from openbb_fred.models.personal_consumption_expenditures import (
FredPersonalConsumptionExpendituresFetcher,
)
from openbb_fred.models.regional import FredRegionalDataFetcher
from openbb_fred.models.retail_prices import FredRetailPricesFetcher
from openbb_fred.models.search import (
Expand Down Expand Up @@ -78,6 +81,7 @@
"MortgageIndices": FredMortgageIndicesFetcher,
"NonFarmPayrolls": FredNonFarmPayrollsFetcher,
"OvernightBankFundingRate": FredOvernightBankFundingRateFetcher,
"PersonalConsumptionExpenditures": FredPersonalConsumptionExpendituresFetcher,
"CommercialPaper": FREDCommercialPaperFetcher,
"FredSearch": FredSearchFetcher,
"FredSeries": FredSeriesFetcher,
Expand Down
Loading
Loading