quantlab.model.torch_data#

The data a TorchModel head is fed: the training panel, batches and datasets.

The base class builds one TrainingPanel per fit, or per prediction, and hands it to the head’s _dataset hook, which returns a PyTorch Dataset. The head’s _dataloader hook batches it with a standard DataLoader. Every item is a Batch whose where holds the timestamp and symbol index of each sample, so the base puts predictions back into the [T, S, L] panel the same way for any sample shape.

Two datasets ship:

  • CrossSectionDataset, the default: one item per bar, holding every symbol present at that bar with its last window_bars bars.

  • SymbolSequenceDataset, Qlib style: one item per (bar, symbol) cell, the symbol’s last window_bars bars as [N, F], batched by the default collation to [B, N, F], or gathered a whole batch at a time by batch_loader.

prefetch readies a loader’s next batches on the model’s device in a background thread, so gathering and copying the next batch overlaps the current step.

Classes

Batch

What every step hook, _loss and _forward receive.

CrossSectionDataset

One item per bar: the bar's whole cross-section with its windows.

IndexBatches

Batches of dataset positions, each an int64 tensor, for a dataset that gathers a batch at once.

SymbolSequenceDataset

One item per (bar, symbol) cell: the symbol's last window_bars bars.

TrainingPanel

The collected panel as torch tensors, shared by every dataset of a fit.

Functions

batch_loader

A DataLoader that hands each batch of positions to dataset[positions] whole.

prefetch

Yield batches on device, each readied ahead by a background thread.