Skip to content

Commit

Permalink
[Feature] More OECD - House Price Index, Immediate Interest Rate (#6473)
Browse files Browse the repository at this point in the history
* add house price index

* static files

* unemployment cleanup

* EA20

* test params

* add immediate interest rates
  • Loading branch information
deeleeramone authored May 30, 2024
1 parent 919d5a6 commit d80a5ed
Show file tree
Hide file tree
Showing 19 changed files with 1,548 additions and 422 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""House Price Index Standard Model."""

from datetime import date as dateType
from typing import Literal, 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 HousePriceIndexQueryParams(QueryParams):
"""House Price Index Query."""

country: str = Field(
description=QUERY_DESCRIPTIONS.get("country", ""),
default="united_states",
)
frequency: Literal["monthly", "quarter", "annual"] = Field(
description=QUERY_DESCRIPTIONS.get("frequency", ""),
default="quarter",
json_schema_extra={"choices": ["monthly", "quarter", "annual"]},
)
transform: Literal["index", "yoy", "period"] = Field(
description="Transformation of the CPI data. Period represents the change since previous."
+ " Defaults to change from one year ago (yoy).",
default="index",
json_schema_extra={"choices": ["index", "yoy", "period"]},
)
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")
)


class HousePriceIndexData(Data):
"""House Price Index Data."""

date: Optional[dateType] = Field(
default=None, description=DATA_DESCRIPTIONS.get("date")
)
country: Optional[str] = Field(
default=None,
description=DATA_DESCRIPTIONS.get("country", ""),
)
value: Optional[float] = Field(
default=None,
description="Share price index value.",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""Immediate Interest Rates Standard 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 ImmediateInterestRateQueryParams(QueryParams):
"""Immediate (Call money, interbank rate) Rate Query."""

country: str = Field(
description=QUERY_DESCRIPTIONS.get("country", ""),
default="united_states",
)
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")
)


class ImmediateInterestRateData(Data):
"""Immediate Interest Rates Data."""

date: Optional[dateType] = Field(
default=None, description=DATA_DESCRIPTIONS.get("date")
)
country: Optional[str] = Field(
default=None,
description="Country for which interest rate is given",
)
value: Optional[float] = Field(
default=None,
description="Immediate interest rates, call money, interbank rate.",
json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100},
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Unemployment Standard Model."""

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

from pydantic import Field

Expand All @@ -16,6 +16,15 @@
class UnemploymentQueryParams(QueryParams):
"""Unemployment Query."""

country: str = Field(
description=QUERY_DESCRIPTIONS.get("country", ""),
default="united_states",
)
frequency: Literal["monthly", "quarter", "annual"] = Field(
description=QUERY_DESCRIPTIONS.get("frequency", ""),
default="monthly",
json_schema_extra={"choices": ["monthly", "quarter", "annual"]},
)
start_date: Optional[dateType] = Field(
default=None, description=QUERY_DESCRIPTIONS.get("start_date")
)
Expand All @@ -30,11 +39,12 @@ class UnemploymentData(Data):
date: Optional[dateType] = Field(
default=None, description=DATA_DESCRIPTIONS.get("date")
)
value: Optional[float] = Field(
default=None,
description="Unemployment rate (given as a whole number, i.e 10=10%)",
)
country: Optional[str] = Field(
default=None,
description="Country for which unemployment rate is given",
)
value: Optional[float] = Field(
default=None,
description="Unemployment rate, as a normalized percent.",
json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100},
)
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ def test_economy_money_measures(params, headers):
@parametrize(
"params",
[
({"start_date": "2023-01-01", "end_date": "2023-06-06", "provider": "oecd"}),
(
{
"country": "united_states",
Expand Down Expand Up @@ -734,3 +733,56 @@ def test_economy_share_price_index(params, headers):
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@parametrize(
"params",
[
(
{
"country": "united_states,united_kingdom",
"frequency": "quarter",
"provider": "oecd",
"start_date": "2022-01-01",
"end_date": "2024-04-01",
"transform": "index",
}
),
],
)
@pytest.mark.integration
def test_economy_house_price_index(params, headers):
"""Test the economy house price index."""
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/house_price_index?{query_str}"
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@parametrize(
"params",
[
(
{
"country": "united_states,united_kingdom",
"frequency": "monthly",
"provider": "oecd",
"start_date": "2022-01-01",
"end_date": "2024-04-01",
}
),
],
)
@pytest.mark.integration
def test_economy_immediate_interest_rate(params, headers):
"""Test the economy immediate_interest_rate."""
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/immediate_interest_rate?{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 @@ -400,7 +400,6 @@ def test_economy_money_measures(params, obb):
@parametrize(
"params",
[
({"start_date": "2023-01-01", "end_date": "2023-06-06"}),
(
{
"country": "united_states",
Expand Down Expand Up @@ -693,3 +692,54 @@ def test_economy_share_price_index(params, obb):
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@parametrize(
"params",
[
(
{
"country": "united_states,united_kingdom",
"frequency": "quarter",
"provider": "oecd",
"start_date": "2022-01-01",
"end_date": "2024-04-01",
"transform": "index",
}
),
],
)
@pytest.mark.integration
def test_economy_house_price_index(params, obb):
"""Test economy house price index."""
params = {p: v for p, v in params.items() if v}

result = obb.economy.house_price_index(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@parametrize(
"params",
[
(
{
"country": "united_states,united_kingdom",
"frequency": "monthly",
"provider": "oecd",
"start_date": "2022-01-01",
"end_date": "2024-04-01",
}
),
],
)
@pytest.mark.integration
def test_economy_immediate_interest_rate(params, obb):
"""Test economy immediate interest rate."""
params = {p: v for p, v in params.items() if v}

result = obb.economy.immediate_interest_rate(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ async def central_bank_holdings(
description="Multiple countries can be passed in as a list.",
parameters={
"country": "united_kingdom,germany",
"frequency": "quarterly",
"frequency": "quarter",
"provider": "oecd",
},
),
Expand All @@ -435,3 +435,51 @@ async def share_price_index(
) -> OBBject:
"""Get the Share Price Index by country from the OECD Short-Term Economics Statistics."""
return await OBBject.from_query(Query(**locals()))


@router.command(
model="HousePriceIndex",
examples=[
APIEx(parameters={"provider": "oecd"}),
APIEx(
description="Multiple countries can be passed in as a list.",
parameters={
"country": "united_kingdom,germany",
"frequency": "quarter",
"provider": "oecd",
},
),
],
)
async def house_price_index(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Get the House Price Index by country from the OECD Short-Term Economics Statistics."""
return await OBBject.from_query(Query(**locals()))


@router.command(
model="ImmediateInterestRate",
examples=[
APIEx(parameters={"provider": "oecd"}),
APIEx(
description="Multiple countries can be passed in as a list.",
parameters={
"country": "united_kingdom,germany",
"frequency": "monthly",
"provider": "oecd",
},
),
],
)
async def immediate_interest_rate(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Get immediate interest rates by country."""
return await OBBject.from_query(Query(**locals()))
Loading

0 comments on commit d80a5ed

Please sign in to comment.