---
title: 'FLAG-Trader: LLM-RL Fusion for Trading'
url: https://www.emergentmind.com/topics/flag-trader
type: topic
---

# FLAG-Trader: LLM-RL Fusion for Trading

FLAG-Trader is a unified architecture designed to integrate the linguistic processing and reasoning capabilities of large language models (LLMs) with gradient-based reinforcement learning (RL) policy optimization for financial trading. The approach addresses the limitations of LLMs in complex, sequential, goal-oriented financial environments by enabling a partially fine-tuned LLM to act as the trading policy network. This design leverages pre-trained linguistic knowledge while achieving financial-domain adaptation through parameter-efficient techniques. FLAG-Trader introduces an RL objective with trading-specific rewards—most notably, increment in Sharpe ratio—and demonstrates competitive empirical results with a relatively small model size, outperforming significantly larger baselines in algorithmic trading settings [2502.11433].

## 1. Architecture and Multimodal Fusion

FLAG-Trader employs a pre-trained LLM whose parameter set is divided into a frozen portion (θ_frozen), comprising the lower N transformer layers, and a trainable portion (θ_train), consisting of the top M layers. On top of these, two small feed-forward heads are added: a policy head (θ_P) and a value head (θ_V). The Policy_Net and Value_Net share θ_train but each maintains its own head for respective outputs.

At each decision time step $t$, the market state $s_t$—composed of numerical prices, technical indicators, sentiment features, and account balance—is formatted into a structured text prompt via a fixed template, denoted as $\text{lang}(s_t)$. This prompt is tokenized and embedded by the frozen LLM layers, producing hidden representations $h^{(1)}$, which are further processed by the trainable layers to produce $h^{(2)}$. The final outputs are:

- $\pi_\theta(a_t \mid s_t)$: the policy distribution over actions, generated via a softmax policy head (with action masking as appropriate).
- $V_\theta(s_t)$: state-value estimation, from the value head.

The agent interacts with the environment by sampling actions from $\pi_\theta$, receiving rewards, and triggering RL-based updates.

## 2. Mathematical Formalization

The trading environment is formalized as a Markov decision process (MDP) with the following elements:

- **State space:** $S = X \times Y$, where $s_t = (m_t, b_t)$ combines market observations $m_t = (P_t, N_t)$ (price vector $P_t$ and indicators $N_t$) and account features $b_t = (C_t, H_t)$ (cash $C_t$, holdings $H_t$).
- **Action space:** $A = \{\text{Sell}(-1), \text{Hold}(0), \text{Buy}(+1)\}$.
- **Transitions:** Portfolio transitions update cash and holdings based on the action.
- **Reward:** Defined as the increment in Sharpe ratio,
  \[
    pnl_t = (C_t - C_{t-1}) + (H_t P_t - H_{t-1} P_{t-1}),
  \]
  \[
    SR_t = \frac{\mathbb{E}[pnl_{1:t}] - r_f}{\sigma[pnl_{1:t}]}, \quad r(s_t, a_t) = SR_t - SR_{t-1}.
  \]

The optimization seeks $\theta$ maximizing expected discounted returns:
\[
  J(\theta) = \mathbb{E}_{\tau \sim p_\theta} \left[\sum_{t=0}^T \gamma^t r(s_t, a_t)\right],
\]
with the policy gradient update:
\[
  \nabla_\theta J(\theta)  = \mathbb{E}_{\tau \sim p_\theta} \left[\sum_{t=0}^T \gamma^t r(s_t, a_t) \nabla_\theta \log \pi_\theta(a_t \mid s_t)\right].
\]

Training employs Proximal Policy Optimization (PPO) with value and entropy regularization:
\[
  \mathcal{L}_{\rm PPO}(\theta) = -\mathbb{E}_t\left[\min(r_t(\theta) A_t, \operatorname{clip}(r_t(\theta), 1-\varepsilon, 1+\varepsilon) A_t)\right],
\]
\[
  \mathcal{L}_V(\theta) = \mathbb{E}_t[(V_\theta(s_t)-R_t)^2],
\]
\[
  \mathcal{H}(\pi_\theta) = -\mathbb{E}_t \sum_a \pi_\theta(a \mid s_t) \log \pi_\theta(a \mid s_t).
\]
The total loss:
\[
  \mathcal{L}_{\rm total}(\theta) = \mathcal{L}_{\rm PPO}(\theta) + c_1 \mathcal{L}_V(\theta) - c_2 \mathcal{H}(\pi_\theta).
\]
An optional cross-entropy language-modeling loss may be included for stability.

## 3. Parameter-Efficient Fine-Tuning

FLAG-Trader adopts a LoRA-style parameter-efficient fine-tuning strategy in which approximately 90% of the LLM parameters (θ_frozen) are kept fixed. Only the top M transformer layers (θ_train) and the two policy/value heads (θ_P, θ_V)—altogether about 5–10% of the full model—are updated during RL-driven training. The main training objective is the PPO RL loss; a small ($\lambda \ll 1$) language-modeling (MLE) loss on trainable layers may optionally be incorporated to preserve language alignment.

This split reduces GPU memory and compute requirements while allowing effective adaptation to the financial domain. Ablation experiments show that updating only a small subset of parameters is sufficient for trading-specific generalization and robust policy learning, while maintaining the LLM’s linguistic generality.

## 4. Training Methodology

The training procedure is structured as follows:

1. Initialize $\theta_\text{frozen}$ using LLM pre-training; randomly initialize $\theta_\text{train}$, $\theta_P$, and $\theta_V$.
2. For each time step $t$:
    - Observe market state $s_t$; generate prompt $\text{lang}(s_t)$.
    - Forward pass: frozen layers $\to$ trainable layers $\to$ heads, yielding $\pi_\theta(a_t \mid s_t)$, $V_\theta(s_t)$.
    - Sample and execute action $a_t$; observe reward $r_t$ and next state $s_{t+1}$.
    - Store transition $(s_t, a_t, r_t, s_{t+1})$ in the replay buffer.
    - Every $\tau$ steps, compute advantages $A_t$ (e.g., via GAE), and perform $K$ PPO epochs:
        - Update $\theta_P$ using $\nabla_{\theta_P} \mathcal{L}_{\rm PPO}$,
        - Update $\theta_V$ using $\nabla_{\theta_V} \mathcal{L}_V$,
        - Update $\theta_\text{train}$ using $\nabla_{\theta_\text{train}} \mathcal{L}_{\rm total}$.
3. Repeat until convergence or resource budgets are exhausted.

A plausible implication is that this decoupled and memory-efficient training enables rapid iteration on financial tasks with limited compute.

## 5. Empirical Evaluation and Performance

The empirical evaluation includes five U.S. equities (MSFT, JNJ, UVV, HON, TSLA) and a cryptocurrency (BTC), with the following baselines:

- Buy-and-hold passive strategy.
- INVESTORBENCH LLM-agentic framework with 13 proprietary/open models.

Primary evaluation metrics are Cumulative Return (CR) and Sharpe Ratio (SR), with Annualized Volatility (AV) and Max Drawdown (MDD) as secondary metrics.

Key results using a 135M-parameter SmolLM2 model with FLAG-Trader:

- Average SR improvement of 20–50% across assets (e.g., SR ≈ 1.37 vs. 1.04 on MSFT).
- CR improved by 10–30% on most tickers.
- The 135M-parameter FLAG-Trader configuration outperforms baseline models with up to 70B parameters.

Ablation findings:

- Freezing lower LLM layers preserves pre-trained language skills; domain adaptation occurs with minimal parameter updates.
- Pure RL fine-tuning (without MLE regularization) produces stable trading policies that become less sensitive to prompt details.

## 6. Insights and Implications

FLAG-Trader demonstrates that fusing LLM reasoning for multimodal time-series and text with RL-based policy optimization can yield domain-specialized agents effective at sequential financial decision-making. The framework’s parameter-efficient adaptation achieves robust results at low computational cost.

Empirical outcomes show that "intelligence + rewards"—interpreted as effective RL optimization of a capable LLM backbone—can yield superior financial performance compared to mere scale, with small open-source models surpassing much larger commercial baselines in trading tasks. The modular approach, leveraging LLMs for structured prompt engineering and efficient RL updates, supports extensibility to other financial-domain objectives and agentic settings [2502.11433].

Source: https://www.emergentmind.com/topics/flag-trader