StockformerMultiTaskLoss<T>

Helpers & Utilities · AiDotNet.Finance.Trading.Factors

Stockformer’s multi-task objective: a masked regression loss on returns plus a classification loss on direction, summed with the paper’s task weight (default 1.0, the reference’s 1:1 sum).

For Beginners

The model is graded on two things at once — how close its predicted return is, and whether it got the up/down direction right — and both count equally. Missing data points are skipped rather than treated as zero.

How It Works

Transcribed from the reference implementation (github.com/Eric991005/Multitask-Stockformer, lib/Multitask_Stockformer_utils.py and MultiTask_Stockformer_train.py L292-308) for Ma et al., arXiv:2401.06139. Three details here are not what a reading of the paper would suggest:

Methods

Method Summary
T CrossEntropy(Vector<T> logits, Vector<T> targets, int numClasses) Softmax cross-entropy over direction classes.
T MaskedMae(Vector<T> predictions, Vector<T> labels, double missingSentinel) Mean absolute error over entries whose label differs from missingSentinel.
ValueTuple<T, T, T> Compute(Vector<T> mainRegression, Vector<T> lowRegression, Vector<T> mainReturnTarget, Vector<T> lowReturnTarget, Vector<T> mainClassLogits, Vector<T> lowClassLogits, Vector<T> directionTarget, int numClasses, double missingSentinel, double taskLossWeight) The paper’s total objective over the model’s four outputs.