TL;DR
Instead of relying on complex reinforcement learning (RL) frameworks or separate forecasting heuristics, this paper introduces four novel profit-guided loss functions that allow standard deep learning time-series models to directly learn optimal stock trading strategies. By optimizing directly for financial returns and introducing a smooth mathematical proxy to fix gradient discontinuities, their approach significantly outperforms state-of-the-art RL baselines, particularly during volatile bear markets.
What Problem Does This Paper Address?
Automated portfolio management typically follows one of two paradigms: time-series forecasting (predicting future prices and applying a trading heuristic) or reinforcement learning (training an agent to maximize rewards through trial and error). Both have major drawbacks. Traditional forecasting models don't directly optimize for trading profit, while RL methods can be notoriously unstable, computationally expensive, and difficult to train.
The authors address this gap by asking a compelling question: Can we skip the complexity of RL and train a standard neural network to directly output optimal trading actions simply by changing its loss function? To do this, they design loss functions that penalize missed profits and reward correct buy/short decisions, allowing any standard neural network architecture to directly learn portfolio allocation strategies.
Methods
The authors modify the final layer of standard time-series forecasting architectures to output $N+1$ neurons, where $N$ is the number of stocks in the portfolio, and the extra neuron represents a "Hold" action to mitigate risk. They apply a tanh activation function to bound the outputs between $-1$ and $1$, where positive values represent a "buy" allocation and negative values represent a "short" position.
They introduce four distinct loss functions designed to maximize profit margins:
- StockLoss: A baseline profit-guided loss that negates the sum of weighted expected returns.
- StockLoss-Max: Normalizes returns by the maximum difference across all stocks to stabilize training.
- StockLoss-L2: Uses an L2-norm approach (squaring individual stock expressions) to reduce policy volatility.
- StockLoss-Norm: Normalizes the combined product of allocation weights and returns.
The Smoothing Trick
A major mathematical hurdle arose during training: the loss functions originally relied on the sign() function to determine buy (+1) or short (-1) actions. Because the derivative of sign(x) is zero everywhere except at $x=0$ (where it is undefined), the network suffered from severe gradient discontinuities and couldn't learn effectively. To resolve this, the authors replaced sign(x) with a smooth sigmoidal proxy: tanh(γx), setting $\gamma = 10$ to closely mimic the step function while maintaining clean gradients for backpropagation.
Datasets
The models were evaluated using daily stock data spanning 30 years for 50 S&P 500 companies, extracted from the Center for Research in Security Prices (CRSP). Each stock included 8 economic features: stock price, return, bid-ask spread, turnover, volume change, illiquidity, shares outstanding, and market capitalization. The models were tested across three distinct one-year periods: 2021, 2022, and 2023. To test robustness, they also evaluated a separate mid-cap portfolio consisting of 30 companies with market capitalizations between $2 billion and $10 billion.
Key Insights and Ideas
- Direct Policy Learning via Loss Functions: Standard time-series models (like Transformers or MLPs) can be seamlessly converted into direct trading policy generators without changing their core architectures.
- Price vs. Return Paradox: Counterintuitively, substituting raw price differences ($PRC_{t+1} - PRC_t$) for percentage returns ($Ret_{t+1} - Ret_t$) in the loss functions yielded significantly better profit margins. The authors suggest that because stock prices are non-stationary, neural networks are better at capturing their complex, non-linear dynamics than stationary returns.
- Redundancy of the "Hold" Node: For the top-performing models, incorporating a dedicated "Hold" node to mitigate risk did not provide a statistically significant performance boost. The networks predicted market directions accurately enough that keeping cash on the sidelines was unnecessary.
Key Results
The authors evaluated their loss functions across several state-of-the-art time-series models (including Crossformer, DeformTime, and DLinear) against five established RL baselines (A2C, PPO, DDPG, TD3, SAC) and a standard Buy & Hold baseline.
- Crushing the Bear Market (2022): During the 2022 market downturn, the Buy & Hold baseline lost -20.64%, and the best RL baseline (PPO) only managed a meager 2.81% return. In stark contrast, the DLinear model trained with the proposed StockLoss-L2 (Loss III) function achieved an astonishing 53.91% profit, closely followed by DeformTime at 53.18%.
- Consistency Across Years: The Crossformer model adapted with Loss III proved to be the most consistent performer, delivering returns of 51.42% in 2023, 51.04% in 2022, and 48.62% in 2021.
Limitations and Future Work
The primary limitation of the current work is its evaluation setup: the models were trained to forecast and trade over an entire year block. In a real-world production environment, these models would need to be dynamically retrained on a weekly or monthly basis to adapt to shifting market regimes.
Moving forward, the authors plan to combine these profit-guided loss functions with Neural Architecture Search (NAS) to automatically discover custom neural network backbones optimized specifically for identifying complex inter-stock dependencies.
Summary updated