NVIDIA has introduced Megatron-LM, a powerful tool for AI-driven forecasting of stock market returns and trading volumes. This new system converts continuous financial market data into sequences suitable for model training, which involves handling price and volume observations without creating forward-looking biases or data leaks.

Read More

Financial market data consists of continuous streams of trades, each timestamped accurately. To forecast market dynamics, the data needs to be preprocessed into consistent formats. A common approach aggregates trades into market bars that summarize price, volume, and other statistics for specific time intervals, enabling neural networks to detect patterns across various financial instruments.

Megatron Core, a foundational aspect of NVIDIA's offering, is an open-source library that optimizes training of transformer models on GPUs. The GitHub repository for Megatron-LM combines this library with ready-to-use training scripts tailored for financial time-series analysis.

This framework facilitates the transformation of raw intraday market data into model-ready sequences, retaining numerical features in a continuous format. It leverages a learned patch embedding to convert groups of market observations into usable model inputs, without converting them into text.

To ensure robust forecasting, the dataset preprocessor maintains a clear separation of chronological datasets while enabling specific configurations for training. This includes defining trading-session boundaries to mitigate the risk of data leakage.

During preprocessing, intraday market bars are converted into tensors to be utilized in Megatron's distributed training processes, which allow simultaneous forecasting of returns and trading volumes over multiple time horizons. A standardized interface enables researchers to train models on historical data from various financial instruments, ensuring uniformity while allowing for instrument-specific analysis.

Megatron-LM's architecture supports ongoing research by producing forecasts that can be used to study short-term price behaviors and trading activity. The data remains reusable, allowing modifications to model parameters without the need for extensive reprocessing.

Data from various vendors is accommodated within the same framework, allowing for flexibility in sampling methods, whether one-minute or sub-minute aggregates are used. The preprocessing script ensures that data is organized chronologically and that observations are assessed independently.

To prevent bias, the dataset is meticulously divided into training, validation, and testing segments. Context windows for training retain all relevant future observations while ensuring that data meant for validation and testing does not contaminate the training set. The system applies a stringent embargo to maintain the integrity of the training dataset.

Furthermore, researchers can configure trading sessions and forecast horizons according to the specific needs of their analyses. For instance, input sequences may be restricted to a single trading day for certain methodologies, ensuring that all observations are derived from the same session. The dataset loader also adapts to these configurations, efficiently managing the availability of targets for model training.