Skip to main content


Perform RNN forecasting

Source Code: [link]

openbb.forecast.rnn(data: Union[pd.Series, pd.DataFrame], target_column: str = "close", n_predict: int = 5, train_split: float = 0.85, forecast_horizon: int = 5, model_type: str = "LSTM", hidden_dim: int = 20, dropout: float = 0.0, batch_size: int = 16, n_epochs: int = 100, learning_rate: float = 0.001, model_save_name: str = "rnn_model", training_length: int = 20, input_chunk_size: int = 14, force_reset: bool = True, save_checkpoints: bool = True)


dataUnion[pd.Series, pd.DataFrame]Input DataNoneFalse
n_predictintDays to predict. Defaults to 5.5True
target_columnstrTarget column to forecast. Defaults to "close".closeTrue
train_splitfloatTrain/val split. Defaults to
forecast_horizonintForecast horizon when performing historical forecasting. Defaults to 5.5True
model_typestrEither a string specifying the RNN module type ("RNN", "LSTM" or "GRU"). Defaults to "LSTM".LSTMTrue
hidden_dimintSize for feature maps for each hidden RNN layer.. Defaults to 20.20True
dropoutfloatFraction of neurons affected by Dropout. Defaults to
batch_sizeintNumber of time series (input and output sequences) used in each training pass. Defaults to 32.16True
n_epochsintNumber of epochs over which to train the model. Defaults to 100.100True
learning_ratefloatDefaults to 1e-3.0.001True
model_save_namestrName for model. Defaults to "brnn_model".rnn_modelTrue
force_resetboolIf set to True, any previously-existing model with the same name will be reset
(all checkpoints will be discarded). Defaults to True.
save_checkpointsboolWhether or not to automatically save the untrained model and checkpoints from training.
Defaults to True.


Tuple[List[TimeSeries], List[TimeSeries], List[TimeSeries], Optional[float], type[RNNModel]]Adjusted Data series,
Historical forecast by best RNN model,
list of Predictions,
Mean average precision error,
Best RNN Model