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 TIPS Yields (to maturity) #6597

Merged
merged 13 commits into from
Jul 22, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""TIPS (Treasury Inflation-Protected Securities) Yields 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 TipsYieldsQueryParams(QueryParams):
"""TIPS Yields Query."""

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 TipsYieldsData(Data):
"""TIPS Yields Data."""

date: dateType = Field(description=DATA_DESCRIPTIONS.get("date", ""))
symbol: Optional[str] = Field(
default=None,
description=DATA_DESCRIPTIONS.get("symbol", ""),
)
due: Optional[dateType] = Field(
default=None,
description="The due date (maturation date) of the security.",
)
name: Optional[str] = Field(
default=None,
description="The name of the security.",
)
value: float = Field(
default=None,
description="The yield value.",
json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100},
)
Original file line number Diff line number Diff line change
Expand Up @@ -804,3 +804,31 @@ def test_fixedincome_rate_overnight_bank_funding(params, headers):
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@parametrize(
"params",
[
(
{
"maturity": None,
"start_date": None,
"end_date": None,
"transform": None,
"aggregation_method": None,
"frequency": None,
"provider": "fred",
}
),
],
)
@pytest.mark.integration
def test_fixedincome_government_tips_yields(params, headers):
"""Test the TIPS Yields 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/fixedincome/government/tips_yields?{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,3 +750,28 @@ def test_fixedincome_rate_overnight_bank_funding(params, obb):
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@parametrize(
"params",
[
(
{
"maturity": None,
"start_date": None,
"end_date": None,
"transform": None,
"aggregation_method": None,
"frequency": None,
"provider": "fred",
}
),
],
)
@pytest.mark.integration
def test_fixedincome_government_tips_yields(params, obb):
"""Test the TIPS Yields endpoint."""
result = obb.fixedincome.government.tips_yields(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,20 @@ async def treasury_prices(
) -> OBBject:
"""Government Treasury Prices by date."""
return await OBBject.from_query(Query(**locals()))


@router.command(
model="TipsYields",
examples=[
APIEx(parameters={"provider": "fred"}),
APIEx(parameters={"maturity": 10, "provider": "fred"}),
],
)
async def tips_yields(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Get current Treasury inflation-protected securities yields."""
return await OBBject.from_query(Query(**locals()))
176 changes: 176 additions & 0 deletions openbb_platform/openbb/assets/reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -33810,6 +33810,182 @@
},
"model": "TreasuryRates"
},
"/fixedincome/government/tips_yields": {
"deprecated": {
"flag": null,
"message": null
},
"description": "Get current Treasury inflation-protected securities yields.",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.fixedincome.government.tips_yields(provider='fred')\nobb.fixedincome.government.tips_yields(maturity=10, provider='fred')\n```\n\n",
"parameters": {
"standard": [
{
"name": "start_date",
"type": "Union[date, str]",
"description": "Start date of the data, in YYYY-MM-DD format.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "end_date",
"type": "Union[date, str]",
"description": "End date of the data, in YYYY-MM-DD format.",
"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": "maturity",
"type": "Literal[5, 10, 20, 30]",
"description": "The maturity of the security in years - 5, 10, 20, 30 - defaults to all. Note that the maturity is the tenor of the security, not the time to maturity.",
"default": null,
"optional": true,
"choices": [
5,
10,
20,
30
]
},
{
"name": "frequency",
"type": "Literal['a', 'q', 'm', 'w', 'd', 'wef', 'weth', 'wew', 'wetu', 'wem', 'wesu', 'wesa', 'bwew', 'bwem']",
"description": "Frequency aggregation to convert high frequency data to lower frequency. None = No change a = Annual q = Quarterly m = Monthly w = Weekly d = Daily wef = Weekly, Ending Friday weth = Weekly, Ending Thursday wew = Weekly, Ending Wednesday wetu = Weekly, Ending Tuesday wem = Weekly, Ending Monday wesu = Weekly, Ending Sunday wesa = Weekly, Ending Saturday bwew = Biweekly, Ending Wednesday bwem = Biweekly, Ending Monday",
"default": null,
"optional": true,
"choices": [
"a",
"q",
"m",
"w",
"d",
"wef",
"weth",
"wew",
"wetu",
"wem",
"wesu",
"wesa",
"bwew",
"bwem"
]
},
{
"name": "aggregation_method",
"type": "Literal['avg', 'sum', 'eop']",
"description": "A key that indicates the aggregation method used for frequency aggregation. avg = Average sum = Sum eop = End of Period",
"default": null,
"optional": true,
"choices": [
"avg",
"sum",
"eop"
]
},
{
"name": "transform",
"type": "Literal['chg', 'ch1', 'pch', 'pc1', 'pca', 'cch', 'cca']",
"description": "Transformation type None = No transformation chg = Change ch1 = Change from Year Ago pch = Percent Change pc1 = Percent Change from Year Ago pca = Compounded Annual Rate of Change cch = Continuously Compounded Rate of Change cca = Continuously Compounded Annual Rate of Change",
"default": null,
"optional": true,
"choices": [
"chg",
"ch1",
"pch",
"pc1",
"pca",
"cch",
"cca"
]
}
]
},
"returns": {
"OBBject": [
{
"name": "results",
"type": "List[TipsYields]",
"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": null,
"optional": true,
"choices": null
},
{
"name": "due",
"type": "date",
"description": "The due date (maturation date) of the security.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "name",
"type": "str",
"description": "The name of the security.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "value",
"type": "float",
"description": "The yield value.",
"default": null,
"optional": true,
"choices": null
}
],
"fred": []
},
"model": "TipsYields"
},
"/fixedincome/corporate/ice_bofa": {
"deprecated": {
"flag": true,
Expand Down
Loading
Loading