Quant Memo
Advanced

The REINFORCE Algorithm

Instead of estimating how good each action is and picking the best one, REINFORCE directly adjusts a policy's action probabilities — pushing up the odds of actions that led to good outcomes and down the odds of ones that led to bad outcomes — using nothing more than the total reward and ordinary calculus.

Prerequisites: Q-Learning

Q-learning learns values: an estimate of how good each action is in each state, and it acts by picking whichever action currently has the highest estimated value. REINFORCE takes a different route entirely. It skips value estimation and directly learns a policy — a function that outputs a probability of taking each action — and adjusts that policy's parameters using nothing more than one simple, powerful fact: after playing out a full episode and observing its total reward, you can nudge every action you took, in proportion to how good the episode turned out, without ever needing a separate value function at all.

The core trick, in words before symbols

Run the current policy for a full episode — a full trading day, say, taking a sequence of actions and eventually observing a total reward RR for the episode. REINFORCE's update rule says: for every action taken along the way, increase the probability of that action if RR was good, and decrease it if RR was bad, and scale the size of that push by how surprising the action was under the current policy (rarely-taken actions get bigger pushes when they pay off, since the policy has more room to update its belief about them).

θJ(θ)tθlogπθ(atst)R\nabla_\theta J(\theta) \approx \sum_{t} \nabla_\theta \log \pi_\theta(a_t \mid s_t) \cdot R

In words: to improve the policy's parameters θ\theta, for each action ata_t taken at each timestep tt, compute how much increasing that action's log-probability under the current policy πθ\pi_\theta would move the parameters, and scale that direction by the episode's total reward RR. Summed over the whole episode, this gives a direction to adjust θ\theta: nudge parameters to make good-reward episodes' actions more likely and bad-reward episodes' actions less likely, purely from the reward signal, no separate value estimate required.

Worked sketch: one good episode, one bad one

Suppose a simple policy chooses between "buy" and "hold," and two episodes are played out. Episode 1: the policy chose buy three times in a row, and the total reward was R=+6R = +6 (good). Episode 2: it chose buy twice and hold once, and the total reward was R=4R = -4 (bad). REINFORCE's update, applied to episode 1, pushes the parameters to make "buy" more likely in the states where it was chosen, scaled by +6+6. Applied to episode 2, it pushes the chosen actions to be less likely, scaled by 4-4. Averaged across many such episodes, actions that reliably precede good total rewards get systematically reinforced, and actions preceding bad ones get systematically discouraged — hence the algorithm's name.

Gradient descent
parameter →
position -0.623loss -0.141gradient -0.930converging

REINFORCE's parameter update is, mechanically, one more step of gradient ascent on expected reward, following the same "take a step in the direction that improves things" logic shown above — the difference from ordinary supervised gradient descent is that the "loss" here is an entire episode's total reward, known only after the fact, not a per-example label known upfront.

REINFORCE skips value estimation entirely and instead directly nudges a policy's action probabilities up or down in proportion to how good the resulting episode's total reward turned out to be — a policy-gradient method, not a value-based one.

What this means in practice

REINFORCE's biggest practical drawback is that it uses the entire episode's total reward to scale every single action's update, even actions taken early in the episode that had little to do with a late, decisive outcome — this makes the learning signal extremely noisy (high variance), since one lucky or unlucky late event drags the credit or blame back onto every earlier action indiscriminately. In a multi-step trading strategy, an early entry decision and a late, unrelated market-wide shock both get blamed or credited by the same total RR, which is exactly the problem actor-critic methods were built to fix by learning a value estimate specifically to reduce this variance.

Because REINFORCE only updates after a complete episode and scales by the total reward, it needs a large number of full episodes to converge reliably, and its updates can be dominated by a handful of unusually lucky or unlucky episodes rather than the typical case. Do not read a single episode's outcome, however dramatic, as strong evidence about which specific action within it was actually responsible.

Related concepts

Practice in interviews

Further reading

  • Williams, Simple Statistical Gradient-Following Algorithms for Connectionist RL (1992)
ShareTwitterLinkedIn