quantlab.model.predefined.rnn.LSTMRegressor#
- class quantlab.model.predefined.rnn.LSTMRegressor(config)[source]#
Bases:
_QlibRNNHeadQlib’s LSTM benchmark model on
(bar, symbol)samples.RNNNetwith an LSTM, trained by Qlib’s time-series regimen (QlibSequenceHead:CSRankNormtarget, MSE, Adam, gradient values clipped at 3, the best validation epoch kept). Hyperparameters, with Qlib’s Alpha158 benchmark values (workflow_config_lstm_Alpha158.yaml) as defaults:window_bars(20),hidden_size(64),num_layers(2),dropout(0.0),batch_size(800),lr(1e-3),weight_decay(0.0),epochs(200) andearly_stop(10).Known differences from Qlib’s implementation:
the features are the model’s factors, not Qlib’s 20 selected Alpha158 columns, and no
RobustZScoreNormis fitted on the training span: the default_transform_featureclips to ±3 and fills NaN with 0, where Qlib forward- and back-fills gaps inside a window;the validation loss is averaged per bar, where Qlib averages it per batch, and the training set’s loss is not evaluated after each epoch;
the output has one column per label instead of one.
- Parameters:
- configModelConfig
Factors, labels, dates and hyperparameters.
Examples
>>> head = LSTMRegressor(ModelConfig( ... factors=[factor], labels=[label], model_save_dir="checkpoints", ... factor_data_strategy="read", label_data_strategy="read", ... train_start="2024-01-01", train_end="2024-05-31", ... test_start="2024-06-01", test_end="2024-07-18", ... hyperparameters={"window_bars": 5, "epochs": 20, "early_stop": 5}, ... )).collect() >>> head.train().name 'LSTMRegressor_total.pth'
- DEFAULTS = {'batch_size': 800, 'dropout': 0.0, 'early_stop': 10, 'epochs': 200, 'hidden_size': 64, 'lr': 0.001, 'num_layers': 2, 'weight_decay': 0.0, 'window_bars': 20}#
Every unset hyperparameter’s value; a head gives Qlib’s benchmark values.