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] Remove Deprecated Fields From Equity Historical #6598

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -1134,8 +1134,6 @@ def test_equity_compare_groups(params, headers):
"start_date": "2023-06-01",
"end_date": "2023-06-03",
"interval": "1h",
"adjusted": False,
"prepost": False,
}
),
(
Expand All @@ -1148,8 +1146,6 @@ def test_equity_compare_groups(params, headers):
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"interval": "1d",
"adjusted": False,
"prepost": False,
}
),
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1083,8 +1083,6 @@ def test_equity_compare_groups(params, obb):
"start_date": "2023-06-01",
"end_date": "2023-06-03",
"interval": "1h",
"adjusted": True,
"prepost": False,
}
),
(
Expand All @@ -1097,8 +1095,6 @@ def test_equity_compare_groups(params, obb):
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"interval": "1d",
"adjusted": False,
"prepost": False,
}
),
(
Expand Down
4 changes: 0 additions & 4 deletions openbb_platform/extensions/etf/integration/test_etf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ def test_etf_search(params, headers):
"start_date": "2023-06-01",
"end_date": "2023-06-03",
"interval": "1h",
"adjusted": True,
"prepost": False,
}
),
(
Expand All @@ -175,8 +173,6 @@ def test_etf_search(params, headers):
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"interval": "1d",
"adjusted": False,
"prepost": False,
}
),
(
Expand Down
4 changes: 0 additions & 4 deletions openbb_platform/extensions/etf/integration/test_etf_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ def test_etf_search(params, obb):
"start_date": "2023-06-01",
"end_date": "2023-06-03",
"interval": "1h",
"adjusted": True,
"prepost": False,
}
),
(
Expand All @@ -170,8 +168,6 @@ def test_etf_search(params, obb):
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"interval": "1d",
"adjusted": False,
"prepost": False,
}
),
(
Expand Down
34 changes: 1 addition & 33 deletions openbb_platform/openbb/assets/reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -5871,7 +5871,7 @@
{
"name": "symbol",
"type": "str",
"description": "The date of the data.",
"description": "Symbol representing the entity requested in the data.",
"default": null,
"optional": true,
"choices": null
Expand Down Expand Up @@ -25677,22 +25677,6 @@
"default": "splits_only",
"optional": true,
"choices": null
},
{
"name": "adjusted",
"type": "bool",
"description": "This field is deprecated (4.1.5) and will be removed in a future version. Use 'adjustment' set as 'splits_and_dividends' instead.",
"default": false,
"optional": true,
"choices": null
},
{
"name": "prepost",
"type": "bool",
"description": "This field is deprecated (4.1.5) and will be removed in a future version. Use 'extended_hours' as True instead.",
"default": false,
"optional": true,
"choices": null
}
]
},
Expand Down Expand Up @@ -28335,22 +28319,6 @@
"default": "splits_only",
"optional": true,
"choices": null
},
{
"name": "adjusted",
"type": "bool",
"description": "This field is deprecated (4.1.5) and will be removed in a future version. Use 'adjustment' set as 'splits_and_dividends' instead.",
"default": false,
"optional": true,
"choices": null
},
{
"name": "prepost",
"type": "bool",
"description": "This field is deprecated (4.1.5) and will be removed in a future version. Use 'extended_hours' as True instead.",
"default": false,
"optional": true,
"choices": null
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion openbb_platform/openbb/package/economy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ def fred_release_table(
children : Optional[str]
The element_id of each child, as a comma-separated string.
symbol : Optional[str]
The date of the data.
Symbol representing the entity requested in the data.
name : Optional[str]
The name of the series.
value : Optional[float]
Expand Down
8 changes: 1 addition & 7 deletions openbb_platform/openbb/package/equity_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ def historical(
The number of data entries to return. (provider: polygon)
include_actions : bool
Include dividends and stock splits in results. (provider: yfinance)
adjusted : bool
This field is deprecated (4.1.5) and will be removed in a future version. Use 'adjustment' set as 'splits_and_dividends' instead. (provider: yfinance)
prepost : bool
This field is deprecated (4.1.5) and will be removed in a future version. Use 'extended_hours' as True instead. (provider: yfinance)

Returns
-------
Expand Down Expand Up @@ -188,9 +184,7 @@ def historical(
"polygon": {"multiple_items_allowed": True},
"tiingo": {"multiple_items_allowed": True},
"yfinance": {"multiple_items_allowed": True},
},
"adjusted": {"deprecated": True},
"prepost": {"deprecated": True},
}
},
)
)
Expand Down
8 changes: 1 addition & 7 deletions openbb_platform/openbb/package/etf.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,6 @@ def historical(
The number of data entries to return. (provider: polygon)
include_actions : bool
Include dividends and stock splits in results. (provider: yfinance)
adjusted : bool
This field is deprecated (4.1.5) and will be removed in a future version. Use 'adjustment' set as 'splits_and_dividends' instead. (provider: yfinance)
prepost : bool
This field is deprecated (4.1.5) and will be removed in a future version. Use 'extended_hours' as True instead. (provider: yfinance)

Returns
-------
Expand Down Expand Up @@ -345,9 +341,7 @@ def historical(
"polygon": {"multiple_items_allowed": True},
"tiingo": {"multiple_items_allowed": True},
"yfinance": {"multiple_items_allowed": True},
},
"adjusted": {"deprecated": True},
"prepost": {"deprecated": True},
}
},
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
Field,
NonNegativeFloat,
PositiveFloat,
model_validator,
)


Expand All @@ -39,29 +38,10 @@ class AVEquityHistoricalQueryParams(EquityHistoricalQueryParams):
description="The adjustment factor to apply. 'splits_only' is not supported for intraday data.",
default="splits_only",
)
extended_hours: Optional[bool] = Field(
extended_hours: bool = Field(
description="Include Pre and Post market data.",
default=False,
)
adjusted: bool = Field(
default=False,
exclude=True,
description="This field is deprecated (4.1.5) and will be removed in a future version."
+ " Use 'adjustment' set as 'splits_and_dividends' instead.",
json_schema_extra={"deprecated": True},
)

@model_validator(mode="before")
@classmethod
def validate_deprecated_params(cls, values):
"""Validate the deprecated parameters."""
for k, v in values.copy().items():
if k in ["adjusted"] and v is True:
warn(
f"The '{k}' parameter is deprecated and will be removed in a future version."
)
values["adjustment"] = "splits_and_dividends"
return values


class AVEquityHistoricalData(EquityHistoricalData):
Expand Down Expand Up @@ -287,7 +267,11 @@ async def get_one(symbol, intraday: bool = False):
if len(query.symbol.split(",")) > 1:
data.loc[:, "symbol"] = symbol

results.extend(data.reset_index().to_dict("records"))
data = data.reset_index()
if intraday is False:
data["date"] = data["date"].dt.date

results.extend(data.to_dict("records"))

return results

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,20 @@ def calculate_adjusted_prices(
# Reverse the DataFrame order, sorting by date in descending order
df.sort_index(ascending=False, inplace=True)

price_col = df[column].values
split_col = df["volume_factor"] if column == "volume" else df["split_factor"].values
dividend_col = df["dividend"].values if dividends else zeros(len(price_col))
price_col = df[column]
split_col = df["volume_factor"] if column == "volume" else df["split_factor"]
dividend_col = df["dividend"] if dividends else zeros(len(price_col))
adj_price_col = zeros(len(df.index))
adj_price_col[0] = price_col[0]
adj_price_col[0] = price_col.iloc[0]

for i in range(1, len(price_col)):
adj_price_col[i] = adj_price_col[i - 1] + adj_price_col[i - 1] * (
((price_col[i] * split_col[i - 1]) - price_col[i - 1] - dividend_col[i - 1])
/ price_col[i - 1]
(
(price_col.iloc[i] * split_col.iloc[i - 1])
- price_col.iloc[i - 1]
- dividend_col[i - 1]
)
/ price_col.iloc[i - 1]
)
df[adj_column] = adj_price_col

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from openbb_core.provider.utils.descriptions import QUERY_DESCRIPTIONS
from openbb_core.provider.utils.errors import EmptyDataError
from openbb_yfinance.utils.references import INTERVALS_DICT, PERIODS
from pydantic import Field, PrivateAttr, model_validator
from pydantic import Field, PrivateAttr

if TYPE_CHECKING:
from pandas import DataFrame
Expand Down Expand Up @@ -58,20 +58,6 @@ class YFinanceEquityHistoricalQueryParams(EquityHistoricalQueryParams):
default="splits_only",
description="The adjustment factor to apply. Default is splits only.",
)
adjusted: bool = Field(
default=False,
exclude=True,
description="This field is deprecated (4.1.5) and will be removed in a future version."
+ " Use 'adjustment' set as 'splits_and_dividends' instead.",
json_schema_extra={"deprecated": True},
)
prepost: bool = Field(
default=False,
exclude=True,
description="This field is deprecated (4.1.5) and will be removed in a future version."
+ " Use 'extended_hours' as True instead.",
json_schema_extra={"deprecated": True},
)

_ignore_tz: bool = PrivateAttr(default=True)
_progress: bool = PrivateAttr(default=False)
Expand All @@ -81,23 +67,6 @@ class YFinanceEquityHistoricalQueryParams(EquityHistoricalQueryParams):
_repair: bool = PrivateAttr(default=False)
_group_by: Literal["ticker", "column"] = PrivateAttr(default="ticker")

@model_validator(mode="before")
@classmethod
def validate_deprecated_params(cls, values):
"""Validate the deprecated parameters."""
for k, v in values.copy().items():
if k in ["adjusted"] and v is True:
warn(
f"The '{k}' parameter is deprecated and will be removed in a future version."
)
values["adjustment"] = "splits_and_dividends"
if k in ["prepost"] and v is True:
warn(
f"The '{k}' parameter is deprecated and will be removed in a future version."
)
values["extended_hours"] = True
return values


class YFinanceEquityHistoricalData(EquityHistoricalData):
"""Yahoo Finance Equity Historical Price Data."""
Expand Down Expand Up @@ -191,6 +160,14 @@ def transform_data(
if query.include_actions is False
else data
)
query_symbols = query.symbol.upper().split(",")

if len(query_symbols) > 1:
symbols = data.symbol.unique().tolist()
for symbol in query_symbols:
if symbol not in symbols:
warn(f"Data for '{symbol}' was not found.")

return [
YFinanceEquityHistoricalData.model_validate(d)
for d in data.to_dict("records")
Expand Down
Loading