quantlab.model.predefined.master#

MASTER: a market-guided transformer over one bar’s cross-section.

MASTERNet reproduces the network of SJTU-DMTai/MASTER (master.py, Li et al., “MASTER: Market-Guided Stock Transformer for Stock Price Forecasting”, AAAI 2024): a market gate that rescales the stock features, attention over time within each stock, attention across stocks at every time step, and a temporal aggregation queried by the last step. MASTERRegressor is the TorchModel head that trains it with the official settings. See docs/research/qlib-gats-master.md §2.

Classes

AttentionBlock

MASTER's pre-LayerNorm multi-head attention block with a feed-forward layer.

Gate

F · softmax(Linear(market) / beta): weights for F features that sum to F.

MASTERNet

The MASTER network with its market gate columns anywhere among the features.

MASTERRegressor

MASTER on the cross-section of every bar, gated by the gate_features factors.

PositionalEncoding

Adds the fixed sinusoidal encoding of each step's position, up to max_len steps.

TemporalAttention

Aggregates a symbol's N steps with weights softmax_t((W z_t)·(W z_N)).