diff --git a/openbb_terminal/forecast/expo_model.py b/openbb_terminal/forecast/expo_model.py index 4c117a90f78..223ea088ae3 100644 --- a/openbb_terminal/forecast/expo_model.py +++ b/openbb_terminal/forecast/expo_model.py @@ -8,7 +8,7 @@ from typing import List, Optional, Tuple, Union import pandas as pd from darts import TimeSeries -from darts.metrics import mape +from darts.metrics import mape, rmse, mse from darts.models import ExponentialSmoothing from darts.utils.utils import ModelMode, SeasonalityMode from numpy import ndarray @@ -40,6 +40,7 @@ def get_expo_data( n_predict: int = 5, start_window: float = 0.85, forecast_horizon: int = 5, + metric: str = "mape", ) -> Tuple[ List[TimeSeries], List[TimeSeries], @@ -76,6 +77,8 @@ def get_expo_data( Size of sliding window from start of timeseries and onwards forecast_horizon: int Number of days to forecast when backtesting and retraining historical + metric: str + Metric to use for backtesting. Defaults to MAPE. Returns ------- @@ -149,8 +152,17 @@ def get_expo_data( # we have the historical fcast, now lets train on entire set and predict. best_model.fit(ticker_series) probabilistic_forecast = best_model.predict(int(n_predict), num_samples=500) - precision = mape(actual_series=ticker_series, pred_series=historical_fcast_es) - console.print(f"Exponential smoothing obtains MAPE: {precision:.2f}% \n") + + if metric == "rmse": + precision = rmse(actual_series=ticker_series, pred_series=historical_fcast_es) + elif metric == "mse": + precision = mse(actual_series=ticker_series, pred_series=historical_fcast_es) + elif metric == "mape": + precision = mape(actual_series=ticker_series, pred_series=historical_fcast_es) + + console.print( + f"Exponential smoothing obtains {metric.upper()}: {precision:.2f}% \n" + ) return ( ticker_series, diff --git a/openbb_terminal/forecast/expo_view.py b/openbb_terminal/forecast/expo_view.py index de41d84f49c..79771b537c7 100644 --- a/openbb_terminal/forecast/expo_view.py +++ b/openbb_terminal/forecast/expo_view.py @@ -36,6 +36,7 @@ def display_expo_forecast( end_date: Optional[datetime] = None, naive: bool = False, export_pred_raw: bool = False, + metric: str = "mape", external_axes: Optional[List[plt.axes]] = None, ): """Display Probabilistic Exponential Smoothing forecast @@ -80,6 +81,10 @@ def display_expo_forecast( naive: bool Whether to show the naive baseline. This just assumes the closing price will be the same as the previous day's closing price. Defaults to False. + export_pred_raw: bool + Whether to export the raw predicted values. Defaults to False. + metric: str + The metric to use when backtesting. Defaults to "mape". external_axes: Optional[List[plt.axes]] External axes to plot on """ @@ -103,6 +108,7 @@ def display_expo_forecast( n_predict=n_predict, start_window=start_window, forecast_horizon=forecast_horizon, + metric=metric, ) if ticker_series == []: @@ -127,6 +133,7 @@ def display_expo_forecast( forecast_only=forecast_only, naive=naive, export_pred_raw=export_pred_raw, + metric=metric, external_axes=external_axes, ) if residuals: