Software & open sourceForecasting

NVIDIA Walkthrough Turns Market Bars Into Model-Ready Data for Megatron-LM

A developer guide covers preprocessing intraday market data, building forecast targets, and training a model in the open-source Megatron Core stack.

anonymous developer's hands and angled laptop with illegible chart content, cluttered desk, ordinary US office, cool-neutral lightAI illustration
Illustration (AI-generated) — not a photo of the actual place or event.

Why it matters

The guide gives developers a concrete preprocessing path from raw market bars, which can come from different vendors and sampling schemes, to saved tensors, plus a defined interface for swapping in their own forecasting model. It is an engineering walkthrough, not a trading strategy.

NVIDIA published a developer blog post titled Prepare Market Data for Forecasting with NVIDIA Megatron Core. The guide runs from raw timestamped trades and quotes to model-ready tensors for Megatron-LM, the GitHub repository that pairs the open-source Megatron Core library with preconfigured training scripts. A common first step is aggregating market data into bars: one row per instrument per time unit with price, volume, and other statistics.

The preprocessor expects a directory of Parquet files with one row per bar and columns for Symbol, Date, Timestamp, Close, and Volume, plus optional numeric feature columns. Bars can come from different vendors and sampling schemes, such as one-minute or sub-minute aggregates of tick data. Each instrument’s trading day should be kept in one file, files should be in chronological order, and the script sorts each instrument’s daily observations by timestamp.

One caveat: the preprocessor treats rows as observation steps and leaves gaps unchanged. If a regular time grid matters for the model, the data has to be aligned upstream.

Price and volume remain continuous features rather than being converted into text; a learned patch embedding turns each group of observations into a model input. The script derives within-day log returns and log volumes itself, so the overnight gap never enters the inputs. It groups consecutive bars for one instrument on one trading day into patches, then slides fixed-length context windows over them; for example, eight bars per patch and 32 patches per window provide 256 observations in a sequence of 32 model positions.

The example forecasts returns and trading volume at several horizons from the same context. Each window includes future targets for every context position, so one forward pass produces forecasts throughout the context rather than only at the end. A causal forecasting model uses only the history available at each position, the post notes. Forecast horizons can be defined in observation steps or patches; for regular one-minute bars, a horizon of five observation steps corresponds to five minutes.

The pipeline separates preprocessing from data loading. Preprocessing builds features, patches, windows, and targets offline and writes them as PyTorch tensor files train.pt, val.pt, test.pt, and meta.pt; training reads the saved tensors, keeping Parquet parsing and target construction outside the training loop. Saved metadata records instrument mappings, feature names, patch and context lengths, and forecast horizons.

forward_step calls the model with patches, an instrument identifier, and patch_tod, and the loss function expects a dictionary with return and volume-share tensors. Any MegatronModule that takes those three inputs and returns that dictionary can replace the example model. The included small model shows the expected input and output formats and is meant to check that preprocessing, the data loader, target masking, and loss computation work together before a forecasting architecture is substituted; users can change the model architecture, optimizer, or training duration while reusing a prepared dataset.

Timeline

  1. NVIDIA publishes the developer blog post 'Prepare Market Data for Forecasting with NVIDIA Megatron Core'.

Sources

  1. NVIDIAPrepare Market Data for Forecasting with NVIDIA Megatron CoreOriginal source

Written with AI assistance from the sources listed above. Its facts were checked against those sources and the article was proofread before publication. How we work