quantlab.model.predefined.rnn.RNNNet#

class quantlab.model.predefined.rnn.RNNNet(num_features, num_labels, hidden_size=64, num_layers=2, dropout=0.0, rnn_type='LSTM')[source]#

Bases: Module

Qlib’s LSTMModel / GRUModel with an output of any width.

Each sample’s window [N, F] goes through the recurrent network, and Linear(H, L) maps the hidden state of the last bar to the output. The parameter names are Qlib’s (rnn, fc_out), so a Qlib state dict loads into a one-label net.

Parameters:
num_featuresint

Features per bar, F.

num_labelsint

Outputs per sample, L; Qlib’s model has one.

hidden_sizeint, default 64

H.

num_layersint, default 2

Recurrent layers.

dropoutfloat, default 0.0

Dropout between recurrent layers.

rnn_type{“LSTM”, “GRU”}, default “LSTM”

The recurrent network.

Raises:
ValueError

If rnn_type is neither "LSTM" nor "GRU".

Examples

>>> net = RNNNet(num_features=4, num_labels=2, hidden_size=8)
>>> net(torch.randn(5, 3, 4)).shape
torch.Size([5, 2])
forward(x)[source]#

Map [B, N, F] windows to [B, L] outputs.

Examples

>>> net.forward(torch.randn(2, 6, 4)).shape
torch.Size([2, 2])