mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
Fixing Forecast SDK with data from other menus (#3554)
* minor check incase using sdk * fixes combine * datetime formating * Update forecast.md * fix testing
This commit is contained in:
@@ -42,6 +42,18 @@ def get_default_files() -> Dict[str, Path]:
|
||||
return default_files
|
||||
|
||||
|
||||
def sdk_dt_format(x) -> str:
|
||||
"""Convert any Timestamp to YYYY-MM-DD when using SDK
|
||||
Args:
|
||||
x: Pandas Timestamp of any length
|
||||
Returns:
|
||||
x: formatted string
|
||||
"""
|
||||
x = pd.to_datetime(x)
|
||||
x = x.strftime("%Y-%m-%d")
|
||||
return x
|
||||
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def get_options(
|
||||
datasets: Dict[str, pd.DataFrame], dataset_name: str = None
|
||||
@@ -415,6 +427,18 @@ def combine_dfs(
|
||||
data: pd.DataFrame
|
||||
The new dataframe
|
||||
"""
|
||||
|
||||
# for use with SDK
|
||||
# check if date is index, if true, reset index
|
||||
if df1.index.name == "date":
|
||||
df1 = df1.reset_index()
|
||||
# remove 00:00:00 from 2019-11-19 00:00:00
|
||||
df1["date"] = df1["date"].apply(lambda x: sdk_dt_format(x))
|
||||
if df2.index.name == "date":
|
||||
df2 = df2.reset_index()
|
||||
# remove 00:00:00 from 2019-11-19 00:00:00
|
||||
df2["date"] = df2["date"].apply(lambda x: sdk_dt_format(x))
|
||||
|
||||
if column not in df2:
|
||||
console.print(
|
||||
f"Not able to find the column {column}. Please choose one of "
|
||||
|
||||
@@ -635,6 +635,13 @@ def get_series(
|
||||
fill_missing_dates=True,
|
||||
)
|
||||
try:
|
||||
# for the sdk, we must check if date is a column not an index
|
||||
# check if date is in the index, if true, reset the index
|
||||
if time_col in data.index.names:
|
||||
data.reset_index(inplace=True)
|
||||
# remove 00:00:00 from 2019-11-19 00:00:00
|
||||
data[time_col] = data[time_col].apply(lambda x: dt_format(x))
|
||||
|
||||
ticker_series = TimeSeries.from_dataframe(**filler_kwargs)
|
||||
except ValueError:
|
||||
# remove business days to allow base lib to assume freq
|
||||
|
||||
22
website/content/sdk/guides/intros/forecast.md
vendored
22
website/content/sdk/guides/intros/forecast.md
vendored
@@ -64,12 +64,28 @@ help(openbb.forecast)
|
||||
|
||||
## Examples
|
||||
|
||||
### combine
|
||||
|
||||
Combine columns from different datasets
|
||||
|
||||
```python
|
||||
spy = openbb.stocks.load("spy")
|
||||
aapl = openbb.stocks.load("aapl")
|
||||
|
||||
# merge the data
|
||||
combined_df = openbb.forecast.combine(spy,aapl, dataset="aapl", column= "Close")
|
||||
openbb.forecast.show(combined_df)
|
||||
```
|
||||
<img width="507" alt="image" src="https://user-images.githubusercontent.com/105685594/203791078-181431cb-99bf-4d26-bfff-b4cf34b5dee2.png">
|
||||

|
||||
|
||||
|
||||
### corr
|
||||
|
||||
Shows a correlation matrix between columns in dataset
|
||||
|
||||
```python
|
||||
df = pd.read_csv(ANDREW_REPLACE)
|
||||
df = openbb.stocks.load("aapl")
|
||||
openbb.forecast.corr_chart(df)
|
||||
```
|
||||

|
||||
@@ -80,7 +96,7 @@ openbb.forecast.corr_chart(df)
|
||||
This command allows you to see seasonality patterns in your data
|
||||
|
||||
```python
|
||||
df = pd.read_csv(ANDREW_REPLACE)
|
||||
df = openbb.stocks.load("aapl")
|
||||
openbb.forecast.season_chart(df)
|
||||
```
|
||||
|
||||
@@ -92,7 +108,7 @@ openbb.forecast.season_chart(df)
|
||||
Predicts the future value of time series data using exponential smoothing
|
||||
|
||||
```python
|
||||
df = pd.read_csv(ANDREW_REPLACE)
|
||||
df = openbb.stocks.load("aapl")
|
||||
openbb.forecast.expo_chart(df)
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user