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] Government Yield Curves + Chart #6417

Merged
merged 43 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
cc6cbe2
stashing
deeleeramone May 3, 2024
1b1e976
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
deeleeramone May 13, 2024
86afaee
ecb yield curve
deeleeramone May 13, 2024
78fdedc
field_description
deeleeramone May 13, 2024
197a6c0
federal reserve yield curve
deeleeramone May 13, 2024
c91b6bc
econdb yield curve
deeleeramone May 14, 2024
99f9ef4
countries literal for python 3.9
deeleeramone May 14, 2024
98fd75a
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
deeleeramone May 14, 2024
b711bd8
list date
deeleeramone May 14, 2024
887204b
fmp yield curve
deeleeramone May 15, 2024
1988ad5
fred yield curve
deeleeramone May 15, 2024
a5ec56e
integration tests
deeleeramone May 15, 2024
893fe91
chart integration tests
deeleeramone May 15, 2024
12b6125
static assets
deeleeramone May 15, 2024
2d078f0
black
deeleeramone May 15, 2024
09aebf8
ruff
deeleeramone May 15, 2024
b37955c
pylint
deeleeramone May 15, 2024
bfa4cce
more pylint
deeleeramone May 15, 2024
86284da
more pylint
deeleeramone May 15, 2024
d80f84b
now black
deeleeramone May 15, 2024
20069e1
country not a standard param
deeleeramone May 15, 2024
c514112
mypy
deeleeramone May 15, 2024
65f0479
Merge branch 'develop' into feature/yield-curve
IgorWounds May 15, 2024
15c33f1
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
deeleeramone May 15, 2024
7a751c7
merge branch develop
deeleeramone May 15, 2024
b9a42f7
Merge branch 'feature/yield-curve' of https://github.com/OpenBB-finan…
deeleeramone May 15, 2024
ef42545
merge branch develop
deeleeramone May 15, 2024
cd54a51
add more countries
deeleeramone May 15, 2024
8f476b8
econdb date filter
deeleeramone May 16, 2024
ed0f6bd
mypy
deeleeramone May 16, 2024
c063ac0
future linting
deeleeramone May 16, 2024
f02957d
make to_chart work
deeleeramone May 16, 2024
d7f6722
plot_bgcolor should be 'rbga(255,255,255,0)'
deeleeramone May 16, 2024
cdcc839
Merge branch 'develop' into feature/yield-curve
deeleeramone May 16, 2024
aaa9f76
Merge branch 'develop' into feature/yield-curve
deeleeramone May 17, 2024
520db70
merge branch develop
deeleeramone May 20, 2024
2f92755
Merge branch 'develop' into feature/yield-curve
deeleeramone May 20, 2024
e32e70a
merge branch develop
deeleeramone May 20, 2024
fc327fd
Merge branch 'develop' into feature/yield-curve
IgorWounds May 21, 2024
900c9ee
push deprecation
hjoaquim May 21, 2024
271021b
Merge remote-tracking branch 'OpenBB-finance/develop' into feature/yi…
hjoaquim May 21, 2024
95e8f45
push deprecation
hjoaquim May 21, 2024
b63475a
Merge branch 'develop' into feature/yield-curve
hjoaquim May 21, 2024
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,37 @@
"""Yield Curve 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 YieldCurveQueryParams(QueryParams):
"""Yield Curve Query."""

date: Optional[str] = Field(
default=None,
description=QUERY_DESCRIPTIONS.get("date", "")
+ " By default is the current data.",
)


class YieldCurveData(Data):
"""Yield Curve Data."""

date: Optional[dateType] = Field(
default=None,
description=DATA_DESCRIPTIONS.get("date", ""),
)
maturity: str = Field(description="Maturity length of the security.")
rate: float = Field(
description="The yield as a normalized percent (0.05 is 5%)",
json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100},
)
Original file line number Diff line number Diff line change
Expand Up @@ -623,3 +623,46 @@ def test_fixedincome_corporate_bond_prices(params, headers):
result = requests.get(url, headers=headers, timeout=40)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@parametrize(
"params",
[
({"date": "2023-05-01,2024-05-01", "provider": "fmp"}),
(
{
"date": "2023-05-01",
"country": "united_kingdom",
"provider": "econdb",
"use_cache": True,
}
),
(
{
"provider": "ecb",
"yield_curve_type": "par_yield",
"date": None,
"rating": "aaa",
"use_cache": True,
}
),
(
{
"provider": "fred",
"yield_curve_type": "nominal",
"date": "2023-05-01,2024-05-01",
}
),
({"provider": "federal_reserve", "date": "2023-05-01,2024-05-01"}),
],
)
@pytest.mark.integration
def test_fixedincome_government_yield_curve(params, headers):
"""Test the treasury rates 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/yield_curve?{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 @@ -578,3 +578,45 @@ def test_fixedincome_corporate_bond_prices(params, obb):
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@parametrize(
"params",
[
({"date": "2023-05-01,2024-05-01", "provider": "fmp"}),
(
{
"date": "2023-05-01",
"country": "united_kingdom",
"provider": "econdb",
"use_cache": True,
}
),
(
{
"provider": "ecb",
"yield_curve_type": "par_yield",
"date": None,
"rating": "aaa",
"use_cache": True,
}
),
(
{
"provider": "fred",
"yield_curve_type": "nominal",
"date": "2023-05-01,2024-05-01",
}
),
({"provider": "federal_reserve", "date": "2023-05-01,2024-05-01"}),
],
)
@pytest.mark.integration
def test_fixedincome_government_yield_curve(params, obb):
"""Test the government yield curve endpoint."""
params = {p: v for p, v in params.items() if v}

result = obb.fixedincome.government.yield_curve(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Fixed Income Government Router."""

from openbb_core.app.deprecation import OpenBBDeprecationWarning
from openbb_core.app.model.command_context import CommandContext
from openbb_core.app.model.example import APIEx
from openbb_core.app.model.obbject import OBBject
Expand All @@ -16,8 +17,46 @@
# pylint: disable=unused-argument


@router.command(
model="YieldCurve",
examples=[
APIEx(parameters={"provider": "federal_reserve"}),
APIEx(parameters={"date": "2023-05-01,2024-05-01", "provider": "fmp"}),
APIEx(
parameters={
"date": "2023-05-01",
"country": "united_kingdom",
"provider": "econdb",
}
),
APIEx(parameters={"provider": "ecb", "yield_curve_type": "par_yield"}),
APIEx(
parameters={
"provider": "fred",
"yield_curve_type": "real",
"date": "2023-05-01,2024-05-01",
}
),
],
)
async def yield_curve(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject: # type: ignore
"""Get yield curve data by country and date."""
return await OBBject.from_query(Query(**locals()))


@router.command(
model="USYieldCurve",
deprecated=True,
deprecation=OpenBBDeprecationWarning(
message="This endpoint will be removed in a future version. Use, `/fixedincome/government/yield_curve`, instead.",
since=(4, 1),
expected_removal=(4, 3),
hjoaquim marked this conversation as resolved.
Show resolved Hide resolved
),
examples=[
APIEx(parameters={"provider": "fred"}),
APIEx(parameters={"inflation_adjusted": True, "provider": "fred"}),
Expand All @@ -35,6 +74,12 @@ async def us_yield_curve(

@router.command(
model="EUYieldCurve",
deprecated=True,
deprecation=OpenBBDeprecationWarning(
message="This endpoint will be removed in a future version. Use, `/fixedincome/government/yield_curve`, instead.",
since=(4, 1),
expected_removal=(4, 3),
),
examples=[
APIEx(parameters={"provider": "ecb"}),
APIEx(parameters={"yield_curve_type": "spot_rate", "provider": "ecb"}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,3 +719,42 @@ def test_charting_etf_holdings(params, headers):
assert chart
assert not fig
assert list(chart.keys()) == ["content", "format"]


@parametrize(
"params",
[
(
{
"provider": "econdb",
"country": "united_kingdom",
"date": None,
"chart": True,
}
),
(
{
"provider": "fred",
"date": "2023-05-10,2024-05-10",
"chart": True,
}
),
],
)
@pytest.mark.integration
def test_charting_fixedincome_government_yield_curve(params, headers):
"""Test chart fixedincome government yield curve."""
params = {p: v for p, v in params.items() if v}
body = (json.dumps({"extra_params": {"chart_params": {"title": "test chart"}}}),)
query_str = get_querystring(params, [])
url = f"http://0.0.0.0:8000/api/v1/fixedincome/government/yield_curve?{query_str}"
result = requests.get(url, headers=headers, timeout=10, json=body)
assert isinstance(result, requests.Response)
assert result.status_code == 200

chart = result.json()["chart"]
fig = chart.pop("fig", {})

assert chart
assert not fig
assert list(chart.keys()) == ["content", "format"]
Original file line number Diff line number Diff line change
Expand Up @@ -590,3 +590,34 @@ def test_charting_etf_holdings(params, obb):
assert len(result.results) > 0
assert result.chart.content
assert isinstance(result.chart.fig, OpenBBFigure)


@parametrize(
"params",
[
(
{
"provider": "econdb",
"country": "united_kingdom",
"date": None,
"chart": True,
}
),
(
{
"provider": "fred",
"date": "2023-05-10,2024-05-10",
"chart": True,
}
),
],
)
@pytest.mark.integration
def test_charting_fixedincome_government_yield_curve(params, obb):
"""Test chart fixedincome government yield curve."""
result = obb.fixedincome.government.yield_curve(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
assert result.chart.content
assert isinstance(result.chart.fig, OpenBBFigure)
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,9 @@ def to_chart(
)
kwargs["provider"] = self._obbject.provider # pylint: disable=protected-access
kwargs["extra"] = self._obbject.extra # pylint: disable=protected-access
kwargs["extra_params"] = kwargs["extra"]["metadata"].arguments.get(
"extra_params"
)
if "kwargs" in kwargs:
_kwargs = kwargs.pop("kwargs")
kwargs.update(_kwargs.get("chart_params", {}))
Expand Down
Loading
Loading