Michiel Nys

ENS Challenge Data by QRT

Predicting the sign of an allocation's next-day performance with two transformers, one over the past 20 days and one across all allocations of the same day.

Python · PyTorch · scikit-learn · time series   code on GitHub

Problem

The challenge comes from QRT on the ENS Challenge Data platform. An allocation is a trading strategy. For each allocation on a given day, the task is to predict whether its return on the next day is positive or negative. It is a binary classification problem on a very noisy financial signal.

Data

Each row is one allocation on one day:

  • TS, an anonymised and shuffled timestamp. Rows with the same TS belong to the same day.
  • ALLOCATION, the label of the strategy, and GROUP, an anonymised group of strategies (for example long-short or momentum).
  • RET_1 to RET_20, the allocation’s returns over the past 20 days.
  • SIGNED_VOLUME_1 to SIGNED_VOLUME_20, its signed volumes over the same days.
  • MEDIAN_DAILY_TURNOVER over those 20 days.
  • The target is the sign of the return on day 21.

Because the timestamps are shuffled, the days carry no calendar order. What they do carry is the cross section: all allocations of one day can be looked at together. A day holds between 65 and 276 allocations.

Features

The 20 days become a tensor of shape batch × time × channels, like the colour channels of an image. Each day has 10 channels for each allocation:

  1. the return, standardised per row
  2. the signed volume, standardised per row
  3. the return on a global scale, since the per-row standardisation hides how big a move is
  4. the market return, the mean return of all allocations that day
  5. the return relative to the market
  6. the return relative to its peers, the same group on the same day
  7. a Sharpe-like ratio, the return divided by the row’s standard deviation
  8. the volume on a global scale
  9. the market volume
  10. a flag for a missing volume

Everything is clipped to [−10,10][-10, 10] because of a few extreme outliers. Next to the time series there are static features: the allocation and group as integer codes for the embeddings, and the median daily turnover plus the two standard deviations from the per-row standardisation. These three are log transformed and standardised with the mean and standard deviation of the training set.

Model

The network has three components and a small head.

Architecture: component A over time and component B on static features are concatenated per row, component C runs across the rows of one day, and a head gives one logit per row. 20 days× 10 channels allocation, groupturnover, 2 sigmas A transformer over timepooled + last day B embeddings + MLPper allocation concatenateone row vector C transformeracross the day headone logit
Figure 1. The row vector from A and B goes both into C and, as a skip connection, straight into the head.

A: a transformer over the 20 days

The 10 channels of each day are projected to a vector of size d=64d = 64 with a linear layer and layer normalisation. A learned positional embedding marks the order of the days. Two transformer encoder layers with 4 attention heads then let all 20 days attend to each other. There is no causal mask, since all 20 days are in the past.

The 20 output vectors h1,…,h20h_1, \dots, h_{20} are reduced in two ways and concatenated. Attention pooling learns a score per day and takes the weighted average

a=∑t=120wtht,wt=exp⁡(s⊤ht)∑τexp⁡(s⊤hτ),a = \sum_{t=1}^{20} w_t h_t, \qquad w_t = \frac{\exp(s^\top h_t)}{\sum_{\tau} \exp(s^\top h_\tau)},

so a quiet day gets little weight and a large move gets more. The last vector h20h_{20}, the most recent day, is added as it is.

B: embeddings for allocation and group

The allocation and group codes go through learned embeddings of size 16 and 2. They are concatenated with the three static features and passed through a two-layer MLP. Dropout on the allocation embedding stops the model from simply memorising each of the 278 allocations.

C: a transformer across the allocations of one day

The outputs of A and B give one vector per row. These rows are regrouped per day into a tensor of days × allocations × features and go through a second transformer encoder, this time across allocations instead of across time. Allocations on the same day move together a lot, so each one gets to see what the others are doing. There is no positional embedding, as the order of the allocations means nothing. Days have different numbers of allocations, so they are padded and the padding is masked in the attention.

The row vector from A and B and the output of C are concatenated and mapped to a single logit by a small MLP. The predicted sign is positive when the logit is above zero.

Training

  • The loss is binary cross-entropy on the logits (BCEWithLogitsLoss).
  • AdamW with a learning rate of 10−310^{-3} and weight decay 0.010.01, and a one-cycle learning rate schedule that warms up first and then decays to almost zero.
  • A batch is a set of 8 whole days with all their allocations, because component C needs the full cross section of a day.
  • Validation is done on whole days. The test set shares no days with the training set, so a random split over rows would be too optimistic. The folds are a KFold over the dates with 8 splits.
  • The signal is very noisy, so the final predictions average the logits of models trained with 3 different seeds on all days.

The notebook, with the full feature pipeline and training loop, is on GitHub.