summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanglewood <85772166+deeleeramone@users.noreply.github.com>2024-06-06 14:24:46 -0700
committerDanglewood <85772166+deeleeramone@users.noreply.github.com>2024-06-06 14:24:46 -0700
commitbef7003b1d63fc3dacf5c76f62dd33d8654ebc4b (patch)
tree67e3fcb1c103ad72211743e17f88b96fd3e23c62
parenta52b24c16b3c59048ad94574cc2ff8d0b0784fce (diff)
improve effr and move sofr to fixedincome.rate
-rw-r--r--openbb_platform/core/openbb_core/provider/standard_models/fed_rates.py33
-rw-r--r--openbb_platform/core/openbb_core/provider/standard_models/federal_funds_rate.py75
-rw-r--r--openbb_platform/extensions/fixedincome/integration/test_fixedincome_api.py31
-rw-r--r--openbb_platform/extensions/fixedincome/integration/test_fixedincome_python.py30
-rw-r--r--openbb_platform/extensions/fixedincome/openbb_fixedincome/fixedincome_router.py7
-rw-r--r--openbb_platform/extensions/fixedincome/openbb_fixedincome/rate/rate_router.py28
-rw-r--r--openbb_platform/openbb/assets/reference.json260
-rw-r--r--openbb_platform/openbb/package/fixedincome.py15
-rw-r--r--openbb_platform/openbb/package/fixedincome_rate.py162
-rw-r--r--openbb_platform/providers/federal_reserve/openbb_federal_reserve/__init__.py6
-rw-r--r--openbb_platform/providers/federal_reserve/openbb_federal_reserve/models/fed_rates.py83
-rw-r--r--openbb_platform/providers/federal_reserve/openbb_federal_reserve/models/federal_funds_rate.py139
-rw-r--r--openbb_platform/providers/federal_reserve/openbb_federal_reserve/utils/ny_fed_api.py1
-rw-r--r--openbb_platform/providers/federal_reserve/tests/record/http/test_federal_reserve_fetchers/test_federal_reserve_fed_fetcher.yaml53
-rw-r--r--openbb_platform/providers/federal_reserve/tests/record/http/test_federal_reserve_fetchers/test_federal_reserve_federal_funds_rate_fetcher.yaml92
-rw-r--r--openbb_platform/providers/federal_reserve/tests/test_federal_reserve_fetchers.py10
-rw-r--r--openbb_platform/providers/fred/openbb_fred/__init__.py4
-rw-r--r--openbb_platform/providers/fred/openbb_fred/models/fed_rates.py80
-rw-r--r--openbb_platform/providers/fred/openbb_fred/models/federal_funds_rate.py199
-rw-r--r--openbb_platform/providers/fred/tests/record/http/test_fred_fetchers/test_fred_federal_funds_rate_fetcher.yaml2820
-rw-r--r--openbb_platform/providers/fred/tests/record/http/test_fred_fetchers/test_fredfed_fetcher.yaml597
-rw-r--r--openbb_platform/providers/fred/tests/test_fred_fetchers.py8
22 files changed, 3845 insertions, 888 deletions
diff --git a/openbb_platform/core/openbb_core/provider/standard_models/fed_rates.py b/openbb_platform/core/openbb_core/provider/standard_models/fed_rates.py
deleted file mode 100644
index 8ad438b12b2..00000000000
--- a/openbb_platform/core/openbb_core/provider/standard_models/fed_rates.py
+++ /dev/null
@@ -1,33 +0,0 @@
-"""FED 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 FEDQueryParams(QueryParams):
- """FED 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 FEDData(Data):
- """FED Data."""
-
- date: dateType = Field(description=DATA_DESCRIPTIONS.get("date", ""))
- rate: Optional[float] = Field(description="FED rate.")
diff --git a/openbb_platform/core/openbb_core/provider/standard_models/federal_funds_rate.py b/openbb_platform/core/openbb_core/provider/standard_models/federal_funds_rate.py
new file mode 100644
index 00000000000..960f9fe624b
--- /dev/null
+++ b/openbb_platform/core/openbb_core/provider/standard_models/federal_funds_rate.py
@@ -0,0 +1,75 @@
+"""Federal Funds Rate 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 FederalFundsRateQueryParams(QueryParams):
+ """Federal Funds Rate 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 FederalFundsRateData(Data):
+ """Federal Funds Rate Data."""
+
+ date: dateType = Field(description=DATA_DESCRIPTIONS.get("date", ""))
+ rate: float = Field(
+ description="Effective federal funds rate.",
+ json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100},
+ )
+ target_range_upper: Optional[float] = Field(
+ default=None,
+ description="Upper bound of the target range.",
+ json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100},
+ )
+ target_range_lower: Optional[float] = Field(
+ default=None,
+ description="Lower bound of the target range.",
+ json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100},
+ )
+ percentile_1: Optional[float] = Field(
+ default=None,
+ description="1st percentile of the distribution.",
+ json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100},
+ )
+ percentile_25: Optional[float] = Field(
+ default=None,
+ description="25th percentile of the distribution.",
+ json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100},
+ )
+ percentile_75: Optional[float] = Field(
+ default=None,
+ description="75th percentile of the distribution.",
+ json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100},
+ )
+ percentile_99: Optional[float] = Field(
+ default=None,
+ description="99th percentile of the distribution.",
+ json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100},
+ )
+ volume: Optional[float] = Field(
+ default=None,
+ description=DATA_DESCRIPTIONS.get("volume", "")
+ + "The notional volume of transactions (Billions of $).",
+ json_schema_extra={
+ "x-unit_measurement": "currency",
+ "x-frontend_multiply": 1e9,
+ },
+ )
diff --git a/openbb_platform/extensions/fixedincome/integration/test_fixedincome_api.py b/openbb_platform/extensions/fixedincome/integration/test_fixedincome_api.py
index 45e7c86a685..424246cf0cf 100644
--- a/openbb_platform/extensions/fixedincome/integration/test_fixedincome_api.py
+++ b/openbb_platform/extensions/fixedincome/integration/test_fixedincome_api.py
@@ -89,6 +89,32 @@ def test_fixedincome_sofr(params, headers):
({"start_date": "2023-01-01", "end_date": "2023-06-06"}),
(
{
+ "period": "overnight",
+ "provider": "fred",
+ "start_date": "2023-01-01",
+ "end_date": "2023-06-06",
+ }
+ ),
+ ],
+)
+@pytest.mark.integration
+def test_fixedincome_rate_sofr(params, headers):
+ """Test the SOFR 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/rate/sofr?{query_str}"
+ result = requests.get(url, headers=headers, timeout=10)
+ assert isinstance(result, requests.Response)
+ assert result.status_code == 200
+
+
+@parametrize(
+ "params",
+ [
+ ({"start_date": "2023-01-01", "end_date": "2023-06-06"}),
+ (
+ {
"parameter": "volume_weighted_trimmed_mean_rate",
"provider": "fred",
"start_date": "2023-01-01",
@@ -166,7 +192,10 @@ def test_fixedincome_rate_ameribor(params, headers):
[
(
{
- "parameter": "weekly",
+ "frequency": "w",
+ "transform": None,
+ "aggregation_method": "avg",
+ "effr_only": False,
"provider": "fred",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
diff --git a/openbb_platform/extensions/fixedincome/integration/test_fixedincome_python.py b/openbb_platform/extensions/fixedincome/integration/test_fixedincome_python.py
index 3efa8727269..ebdf738cb58 100644
--- a/openbb_platform/extensions/fixedincome/integration/test_fixedincome_python.py
+++ b/openbb_platform/extensions/fixedincome/integration/test_fixedincome_python.py
@@ -77,6 +77,29 @@ def test_fixedincome_sofr(params, obb):
({"start_date": "2023-01-01", "end_date": "2023-06-06"}),
(
{
+ "period": "overnight",
+ "provider": "fred",
+ "start_date": "2023-01-01",
+ "end_date": "2023-06-06",
+ }
+ ),
+ ],
+)
+@pytest.mark.integration
+def test_fixedincome_rate_sofr(params, obb):
+ """Test the fixedincome rate sofr endpoint."""
+ result = obb.fixedincome.rate.sofr(**params)
+ assert result
+ assert isinstance(result, OBBject)
+ assert len(result.results) > 0
+
+
+@parametrize(
+ "params",
+ [
+ ({"start_date": "2023-01-01", "end_date": "2023-06-06"}),
+ (
+ {
"parameter": "volume_weighted_trimmed_mean_rate",
"provider": "fred",
"start_date": "2023-01-01",
@@ -145,7 +168,10 @@ def test_fixedincome_rate_ameribor(params, obb):
[
(
{
- "parameter": "weekly",
+ "frequency": "w",
+ "transform": None,
+ "aggregation_method": "avg",
+ "effr_only": False,
"provider": "fred",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
@@ -153,9 +179,9 @@ def test_fixedincome_rate_ameribor(params, obb):
),
(
{
- "provider": "federal_reserve",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
+ "provider": "federal_reserve",
}
),
],
diff --git a/openbb_platform/extensions/fixedincome/openbb_fixedincome/fixedincome_router.py b/openbb_platform/extensions/fixedincome/openbb_fixedincome/fixedincome_router.py
index 0e232cb1cdb..a25c9eb2a1e 100644
--- a/openbb_platform/extensions/fixedincome/openbb_fixedincome/fixedincome_router.py
+++ b/openbb_platform/extensions/fixedincome/openbb_fixedincome/fixedincome_router.py
@@ -2,6 +2,7 @@
# pylint: disable=W0613:unused-argument
+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
@@ -31,6 +32,12 @@ router.include_router(corporate_router)
APIEx(parameters={"provider": "fred"}),
APIEx(parameters={"period": "overnight", "provider": "fred"}),
],
+ deprecated=True,
+ deprecation=OpenBBDeprecationWarning(
+ message="This endpoint is deprecated; use `/fixedincome/rate/sofr` instead.",
+ since=(4, 2),
+ expected_removal=(4, 5),
+ ),
)
async def sofr(
cc: CommandContext,
diff --git a/openbb_platform/extensions/fixedincome/openbb_fixedincome/rate/rate_router.py b/openbb_platform/extensions/fixedincome/openbb_fixedincome/rate/rate_router.py
index 709b9c27904..ad43d8ccb7c 100644
--- a/openbb_platform/extensions/fixedincome/openbb_fixedincome/rate/rate_router.py
+++ b/openbb_platform/extensions/fixedincome/openbb_fixedincome/rate/rate_router.py
@@ -61,6 +61,27 @@ async def sonia(
@router.command(
+ model="SOFR",
+ examples=[
+ APIEx(parameters={"provider": "fred"}),
+ APIEx(parameters={"period": "overnight", "provider": "fred"}),
+ ],
+)
+async def sofr(
+ cc: CommandContext,
+ provider_choices: ProviderChoices,
+ standard_params: StandardParams,
+ extra_params: ExtraParams,
+) -> OBBject: # type: ignore
+ """Secured Overnight Financing Rate.
+
+ The Secured Overnight Financing Rate (SOFR) is a broad measure of the cost of
+ borrowing cash overnight collateralizing by Treasury securities.
+ """
+ return await OBBject.from_query(Query(**locals()))
+
+
+@router.command(
model="IORB",
examples=[APIEx(parameters={"provider": "fred"})],
)
@@ -80,10 +101,10 @@ async def iorb(
@router.command(
- model="FEDFUNDS",
+ model="FederalFundsRate",
examples=[
APIEx(parameters={"provider": "fred"}),
- APIEx(parameters={"parameter": "daily", "provider": "fred"}),
+ APIEx(parameters={"effr_only": True, "provider": "fred"}),
],
)
async def effr(
@@ -95,8 +116,7 @@ async def effr(
"""Fed Funds Rate.
Get Effective Federal Funds Rate data. A bank rate is the interest rate a nation's central bank charges to its
- domestic banks to borrow money. The rates central banks charge are set to stabilize the economy. In the
- United States, the Federal Reserve System's Board of Governors set the bank rate, also known as the discount rate.
+ domestic banks to borrow money. The rates central banks charge are set to stabilize the economy.
"""
return await OBBject.from_query(Query(**locals()))
diff --git a/openbb_platform/openbb/assets/reference.json b/openbb_platform/openbb/assets/reference.json
index bb5ee238f37..ee30c1f65d4 100644
--- a/openbb_platform/openbb/assets/reference.json
+++ b/openbb_platform/openbb/assets/reference.json
@@ -30065,6 +30065,102 @@
},
"model": "SONIA"
},
+ "/fixedincome/rate/sofr": {
+ "deprecated": {
+ "flag": null,
+ "message": null
+ },
+ "description": "Secured Overnight Financing Rate.\n\nThe Secured Overnight Financing Rate (SOFR) is a broad measure of the cost of\nborrowing cash overnight collateralizing by Treasury securities.",
+ "examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.fixedincome.rate.sofr(provider='fred')\nobb.fixedincome.rate.sofr(period=overnight, 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: f, r, e, d.",
+ "default": null,
+ "optional": true
+ }
+ ],
+ "fred": [
+ {
+ "name": "period",
+ "type": "Literal['overnight', '30_day', '90_day', '180_day', 'index']",
+ "description": "Period of SOFR rate.",
+ "default": "overnight",
+ "optional": true,
+ "choices": null
+ }
+ ]
+ },
+ "returns": {
+ "OBBject": [
+ {
+ "name": "results",
+ "type": "List[SOFR]",
+ "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": "rate",
+ "type": "float",
+ "description": "SOFR rate.",
+ "default": "",
+ "optional": false,
+ "choices": null
+ }
+ ],
+ "fred": []
+ },
+ "model": "SOFR"
+ },
"/fixedincome/rate/iorb": {
"deprecated": {
"flag": null,
@@ -30157,8 +30253,8 @@
"flag": null,
"message": null
},
- "description": "Fed Funds Rate.\n\nGet Effective Federal Funds Rate data. A bank rate is the interest rate a nation's central bank charges to its\ndomestic banks to borrow money. The rates central banks charge are set to stabilize the economy. In the\nUnited States, the Federal Reserve System's Board of Governors set the bank rate, also known as the discount rate.",
- "examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.fixedincome.rate.effr(provider='fred')\nobb.fixedincome.rate.effr(parameter=daily, provider='fred')\n```\n\n",
+ "description": "Fed Funds Rate.\n\nGet Effective Federal Funds Rate data. A bank rate is the interest rate a nation's central bank charges to its\ndomestic banks to borrow money. The rates central banks charge are set to stabilize the economy.",
+ "examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.fixedincome.rate.effr(provider='fred')\nobb.fixedincome.rate.effr(effr_only=True, provider='fred')\n```\n\n",
"parameters": {
"standard": [
{
@@ -30188,10 +30284,61 @@
"federal_reserve": [],
"fred": [
{
- "name": "parameter",
- "type": "Literal['monthly', 'daily', 'weekly', 'daily_excl_weekend', 'annual', 'biweekly', 'volume']",
- "description": "Period of FED rate.",
- "default": "weekly",
+ "name": "frequency",
+ "type": "Literal['a', 'q', 'm', 'w', 'wef', 'weth', 'wew', 'wetu', 'wem', 'wesu', 'wesa', 'bwew', 'bwem']",
+ "description": "Frequency aggregation to convert daily data to lower frequency. a = Annual q = Quarterly m = Monthly w = Weekly 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",
+ "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', 'log']",
+ "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 log = Natural Log",
+ "default": null,
+ "optional": true,
+ "choices": [
+ "chg",
+ "ch1",
+ "pch",
+ "pc1",
+ "pca",
+ "cch",
+ "cca",
+ "log"
+ ]
+ },
+ {
+ "name": "effr_only",
+ "type": "bool",
+ "description": "Return data without quantiles, target ranges, and volume.",
+ "default": false,
"optional": true,
"choices": null
}
@@ -30201,7 +30348,7 @@
"OBBject": [
{
"name": "results",
- "type": "List[FEDFUNDS]",
+ "type": "List[FederalFundsRate]",
"description": "Serializable results."
},
{
@@ -30239,16 +30386,105 @@
{
"name": "rate",
"type": "float",
- "description": "FED rate.",
+ "description": "Effective federal funds rate.",
"default": "",
"optional": false,
"choices": null
+ },
+ {
+ "name": "target_range_upper",
+ "type": "float",
+ "description": "Upper bound of the target range.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "target_range_lower",
+ "type": "float",
+ "description": "Lower bound of the target range.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "percentile_1",
+ "type": "float",
+ "description": "1st percentile of the distribution.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "percentile_25",
+ "type": "float",
+ "description": "25th percentile of the distribution.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "percentile_75",
+ "type": "float",
+ "description": "75th percentile of the distribution.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },