diff --git a/openbb_terminal/forecast/forecast_model.py b/openbb_terminal/forecast/forecast_model.py index 406547a7331..6540e53a21a 100644 --- a/openbb_terminal/forecast/forecast_model.py +++ b/openbb_terminal/forecast/forecast_model.py @@ -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 " diff --git a/openbb_terminal/forecast/helpers.py b/openbb_terminal/forecast/helpers.py index d8336d5df41..3e79bb9e027 100644 --- a/openbb_terminal/forecast/helpers.py +++ b/openbb_terminal/forecast/helpers.py @@ -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 diff --git a/website/content/sdk/guides/intros/forecast.md b/website/content/sdk/guides/intros/forecast.md index 51f6dbf9419..44272582720 100644 --- a/website/content/sdk/guides/intros/forecast.md +++ b/website/content/sdk/guides/intros/forecast.md @@ -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) +``` +image +![Combine View](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) ``` ![Corr View](https://user-images.githubusercontent.com/72827203/202424217-b549b6e7-b121-4273-a7d9-b478e89cd65a.png) @@ -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) ``` ​