Skip to content

Commit

Permalink
[BugFix] Fix gdp.forecast (#6585)
Browse files Browse the repository at this point in the history
* fix gdp.forecast

* docstring

* remove invalid country
  • Loading branch information
deeleeramone committed Jul 16, 2024
1 parent 9be525d commit 869d917
Show file tree
Hide file tree
Showing 14 changed files with 450 additions and 317 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Forecast GDP Standard Model."""

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

from pydantic import Field, field_validator
from pydantic import Field

from openbb_core.provider.abstract.data import Data
from openbb_core.provider.abstract.query_params import QueryParams
Expand All @@ -16,35 +16,19 @@
class GdpForecastQueryParams(QueryParams):
"""Forecast GDP Query."""

period: Literal["quarter", "annual"] = Field(
default="annual",
description=QUERY_DESCRIPTIONS.get("period", "")
+ " Units for nominal GDP period. Either quarter or annual.",
)
start_date: Optional[dateType] = Field(
default=None, description=QUERY_DESCRIPTIONS.get("start_date")
)
end_date: Optional[dateType] = Field(
default=None, description=QUERY_DESCRIPTIONS.get("end_date")
)
type: Literal["nominal", "real"] = Field(
default="real",
description="Type of GDP to get forecast of. Either nominal or real.",
)

@field_validator("period", "type", mode="before", check_fields=False)
@classmethod
def to_lower(cls, v: Optional[str]) -> Optional[str]:
"""Convert field to lowercase."""
return v.lower() if v else v


class GdpForecastData(Data):
"""Forecast GDP Data."""

date: Optional[dateType] = Field(
default=None, description=DATA_DESCRIPTIONS.get("date")
)
value: Optional[float] = Field(
default=None, description="Nominal GDP value on the date."
date: dateType = Field(description=DATA_DESCRIPTIONS.get("date"))
country: str = Field(description=DATA_DESCRIPTIONS.get("country"))
value: Union[int, float] = Field(
description="Forecasted GDP value for the country and date."
)
17 changes: 4 additions & 13 deletions openbb_platform/extensions/economy/integration/test_economy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,14 @@ def test_economy_risk_premium(params, headers):
@parametrize(
"params",
[
(
{
"period": "annual",
"start_date": "2023-01-01",
"end_date": "2025-06-06",
"type": "real",
"provider": "oecd",
}
),
(
{
"country": "united_states",
"provider": "oecd",
"period": "annual",
"start_date": "2023-01-01",
"end_date": "2025-06-06",
"type": "real",
"frequency": "annual",
"start_date": None,
"end_date": None,
"units": "volume",
}
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,14 @@ def test_economy_risk_premium(params, obb):
@parametrize(
"params",
[
(
{
"period": "annual",
"start_date": "2023-01-01",
"end_date": "2025-06-06",
"type": "real",
}
),
(
{
"country": "united_states",
"provider": "oecd",
"period": "annual",
"start_date": "2023-01-01",
"end_date": "2025-06-06",
"type": "real",
"frequency": "annual",
"start_date": None,
"end_date": None,
"units": "volume",
}
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@
model="GdpForecast",
examples=[
APIEx(parameters={"provider": "oecd"}),
APIEx(parameters={"period": "annual", "type": "real", "provider": "oecd"}),
APIEx(
parameters={
"country": "united_states,germany,france",
"frequency": "annual",
"units": "capita",
"provider": "oecd",
}
),
],
)
async def forecast(
Expand All @@ -37,7 +44,14 @@ async def forecast(
model="GdpNominal",
examples=[
APIEx(parameters={"provider": "oecd"}),
APIEx(parameters={"units": "usd", "provider": "oecd"}),
APIEx(
parameters={
"units": "capita",
"country": "all",
"frequency": "annual",
"provider": "oecd",
}
),
],
)
async def nominal(
Expand Down
123 changes: 96 additions & 27 deletions openbb_platform/openbb/assets/reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -2525,17 +2525,9 @@
"message": null
},
"description": "Get Forecasted GDP Data.",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.economy.gdp.forecast(provider='oecd')\nobb.economy.gdp.forecast(period='annual', type='real', provider='oecd')\n```\n\n",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.economy.gdp.forecast(provider='oecd')\nobb.economy.gdp.forecast(country=united_states,germany,france, frequency=annual, units=capita, provider='oecd')\n```\n\n",
"parameters": {
"standard": [
{
"name": "period",
"type": "Literal['quarter', 'annual']",
"description": "Time period of the data to return. Units for nominal GDP period. Either quarter or annual.",
"default": "annual",
"optional": true,
"choices": null
},
{
"name": "start_date",
"type": "Union[date, str]",
Expand All @@ -2552,14 +2544,6 @@
"optional": true,
"choices": null
},
{
"name": "type",
"type": "Literal['nominal', 'real']",
"description": "Type of GDP to get forecast of. Either nominal or real.",
"default": "real",
"optional": true,
"choices": null
},
{
"name": "provider",
"type": "Literal['oecd']",
Expand All @@ -2571,11 +2555,88 @@
"oecd": [
{
"name": "country",
"type": "Literal['argentina', 'asia', 'australia', 'austria', 'belgium', 'brazil', 'bulgaria', 'canada', 'chile', 'china', 'colombia', 'costa_rica', 'croatia', 'czech_republic', 'denmark', 'estonia', 'euro_area_17', 'finland', 'france', 'germany', 'greece', 'hungary', 'iceland', 'india', 'indonesia', 'ireland', 'israel', 'italy', 'japan', 'korea', 'latvia', 'lithuania', 'luxembourg', 'mexico', 'netherlands', 'new_zealand', 'non-oecd', 'norway', 'oecd_total', 'peru', 'poland', 'portugal', 'romania', 'russia', 'slovak_republic', 'slovenia', 'south_africa', 'spain', 'sweden', 'switzerland', 'turkey', 'united_kingdom', 'united_states', 'world']",
"description": "Country to get GDP for.",
"default": "united_states",
"type": "Union[str, List[str]]",
"description": "Country, or countries, to get forward GDP projections for. Default is all. Multiple items allowed for provider(s): oecd.",
"default": "all",
"optional": true,
"choices": [
"argentina",
"asia",
"australia",
"austria",
"belgium",
"brazil",
"bulgaria",
"canada",
"chile",
"china",
"colombia",
"costa_rica",
"croatia",
"czech_republic",
"denmark",
"estonia",
"finland",
"france",
"germany",
"greece",
"hungary",
"iceland",
"india",
"indonesia",
"ireland",
"israel",
"italy",
"japan",
"korea",
"latvia",
"lithuania",
"luxembourg",
"mexico",
"netherlands",
"new_zealand",
"norway",
"peru",
"poland",
"portugal",
"romania",
"russia",
"slovak_republic",
"slovenia",
"south_africa",
"spain",
"sweden",
"switzerland",
"turkey",
"united_kingdom",
"united_states",
"other_major_oil_producers",
"rest_of_the_world",
"world",
"all"
]
},
{
"name": "frequency",
"type": "Literal['annual', 'quarter']",
"description": "Frequency of the data, default is annual.",
"default": "annual",
"optional": true,
"choices": null
},
{
"name": "units",
"type": "Literal['current_prices', 'volume', 'capita', 'growth', 'deflator']",
"description": "Units of the data, default is volume (chain linked volume, 2015). 'current_prices', 'volume', and 'capita' are expressed in USD; 'growth' as a percent; 'deflator' as an index.",
"default": "volume",
"optional": true,
"choices": [
"current_prices",
"volume",
"capita",
"growth",
"deflator"
]
}
]
},
Expand Down Expand Up @@ -2614,16 +2675,24 @@
"name": "date",
"type": "date",
"description": "The date of the data.",
"default": null,
"optional": true,
"default": "",
"optional": false,
"choices": null
},
{
"name": "country",
"type": "str",
"description": "None",
"default": "",
"optional": false,
"choices": null
},
{
"name": "value",
"type": "float",
"description": "Nominal GDP value on the date.",
"default": null,
"optional": true,
"type": "Union[int, float]",
"description": "Forecasted GDP value for the country and date.",
"default": "",
"optional": false,
"choices": null
}
],
Expand All @@ -2637,7 +2706,7 @@
"message": null
},
"description": "Get Nominal GDP Data.",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.economy.gdp.nominal(provider='oecd')\nobb.economy.gdp.nominal(units=usd, provider='oecd')\n```\n\n",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.economy.gdp.nominal(provider='oecd')\nobb.economy.gdp.nominal(units=capita, country=all, frequency=annual, provider='oecd')\n```\n\n",
"parameters": {
"standard": [
{
Expand Down
Loading

0 comments on commit 869d917

Please sign in to comment.