Simple Algorithm
Reinforcement Learning · Fixed Point · 28 min

Risk-Sensitive RL

CVaR, exponential utility and acting under risk preferences.

Expected return treats a sure 1.9 and a lottery paying 0.9 or 10.9 (mean 1.9) as equally good. Risk-sensitive RL optimizes something else: a variance penalty, an exponential utility, or the average of the worst outcomes. Each choice changes the mathematics. Exponential utility keeps a Bellman equation; CVaR is time-inconsistent and needs an augmented state; mean–variance optimization is NP-hard. This lesson develops all three with their theorems and conditions, and shows what a distributional agent does, and does not, optimize when it acts on risk.

What you’ll learn

  • Define the variance-penalized, exponential-utility, VaR and CVaR criteria, check which axioms of coherent risk measures each satisfies, and compute them on small examples.
  • Derive the multiplicative Bellman equation of exponential utility for finite-horizon total reward, its dual as KL-penalized robustness, and why discounting makes the optimal policy nonstationary.
  • Prove the Rockafellar–Uryasev formula for CVaR, exhibit its time inconsistency, and describe the state augmentations proposed to restore dynamic programming, and which of them is exact.
  • Derive the CVaR policy gradient, and explain why acting greedily on the CVaR of a learned return distribution at every step does not optimize the CVaR of the return.

Risk measures and their axioms

Artzner, Delbaen, Eber and Heath (1999) asked which properties a sensible risk measure should have. In the reward convention used here, a criterion ρ\rho is coherent if it is monotone (G≤G′G\le G' always implies ρ(G)≤ρ(G′)\rho(G)\le\rho(G')), translation-equivariant (ρ(G+c)=ρ(G)+c\rho(G+c)=\rho(G)+c), positively homogeneous (ρ(λG)=λρ(G)\rho(\lambda G)=\lambda\rho(G) for λ≥0\lambda\ge0) and superadditive (ρ(G+G′)≥ρ(G)+ρ(G′)\rho(G+G')\ge\rho(G)+\rho(G'): combining positions never looks riskier than the parts).

CriterionMonotoneTranslationHomogeneousSuperadditive
Mean✓✓✓✓
Mean–variance✗✓✗✗
Entropic UβU_\beta✓✓✗✗ (concave instead)
VaR✓✓✓✗
CVaR✓✓✓✓
CVaR is coherent; VaR fails superadditivity; mean–variance is not even monotone. Example: G=0G=0 for sure versus G′∈{0,10}G'\in\{0,10\} with equal probabilities. G′≥GG'\ge G in every outcome, yet with λ=1\lambda=1 it scores 5−25=−20<05-25=-20<0. The entropic measure is concave, which makes it a convex risk measure but, lacking homogeneity, not a coherent one.

VaR's failure is not academic. Take two independent bets, each losing 100 with probability 0.04 and paying 0 otherwise. Each has VaR⁡0.05=0\operatorname{VaR}_{0.05}=0, since its loss lies beyond the worst 5%. Their sum loses at least 100 with probability 1−0.962=0.07841-0.96^2=0.0784, so its VaR⁡0.05\operatorname{VaR}_{0.05} is −100-100: by VaR, two harmless bets combine into a dangerous one, and a VaR-optimizer can hide risk by splitting it. CVaR counts the whole tail.

Predict before you look

For one of these bets (lose 100 with probability 0.04, else 0), what is CVaR⁡0.05\operatorname{CVaR}_{0.05}?

Show the answer

-80

The worst 5% consists of the 4% at −100-100 and 1% at 0, so CVaR⁡0.05=(0.04⋅(−100)+0.01⋅0)/0.05=−80\operatorname{CVaR}_{0.05}=(0.04\cdot(-100)+0.01\cdot0)/0.05=-80. For the sum of two independent bets, the worst 5% holds 0.16% at −200-200 and 4.84% at −100-100: CVaR⁡0.05=(−0.32−4.84)/0.05=−103.2\operatorname{CVaR}_{0.05}=(-0.32-4.84)/0.05=-103.2, which is at least −80−80=−160-80-80=-160, as superadditivity requires.

Exponential utility: a multiplicative Bellman equation

Why it works. The exponential turns a sum into a product, e−βGh=e−βRh+1 e−βGh+1e^{-\beta G_h}=e^{-\beta R_{h+1}}\,e^{-\beta G_{h+1}}. Given Sh+1S_{h+1}, the factor e−βRh+1e^{-\beta R_{h+1}} is a fixed positive number, so minimizing the product over the continuation policy is the same problem as minimizing E[e−βGh+1∣Sh+1]\E[e^{-\beta G_{h+1}}\mid S_{h+1}], whatever rewards came before; by induction its value is Wh+1(Sh+1)W_{h+1}(S_{h+1}). Among utility functions, only the linear and the exponential ones make preferences over the future independent of what has been collected (constant absolute risk aversion). The certainty equivalent is not the mean minus a variance penalty except approximately: on the lottery, U0.05=1.703U_{0.05}=1.703 against the approximation 1.9−0.025⋅9=1.6751.9-0.025\cdot9=1.675, while at β=0.5\beta=0.5 the exact value is 1.1091.109 and the approximation, −0.35-0.35, is meaningless.

Discounting breaks stationarity. With G=∑tγtRt+1G=\sum_t\gamma^tR_{t+1}, the same factorization gives e−βG=e−βR1exp⁡(−(βγ)∑t≥1γt−1Rt+1)e^{-\beta G}=e^{-\beta R_1}\exp\big(-(\beta\gamma)\sum_{t\ge1}\gamma^{t-1}R_{t+1}\big): the continuation is an exponential-utility problem with risk parameter βγ\beta\gamma. Risk aversion effectively decays by γ\gamma per step, so optimal policies generally depend on time even in infinite-horizon discounted problems; carrying the current risk parameter in the state restores a recursion.

DerivationExponential utility is KL-penalized robustness
  1. −1βlog⁡EP[e−βG]=min⁡Q{EQ[G]+1β DKL(Q ∥ P)}-\frac1\beta\log\E_P\big[e^{-\beta G}\big]=\min_{Q}\Big\{\E_Q[G]+\frac1\beta\,\KL(Q\,\|\,P)\Big\}

    For any distribution QQ of outcomes absolutely continuous with respect to the model PP, with density q=dQ/dPq=dQ/dP, the Gibbs variational principle states

  2. q⋆=e−βGEP[e−βG]q^\star=\frac{e^{-\beta G}}{\E_P[e^{-\beta G}]}

    To check it, minimize EP[qG]+1βEP[qlog⁡q]\E_P[qG]+\frac1\beta\E_P[q\log q] over densities with EP[q]=1\E_P[q]=1. Setting the derivative in qq to a constant gives G+1β(log⁡q+1)=constG+\frac1\beta(\log q+1)=\text{const}, so q⋆∝e−βGq^\star\propto e^{-\beta G}, and substituting back gives the left side.

  3. So a risk-averse exponential-utility agent behaves as if an adversary may tilt the model toward bad outcomes, paying 1β\frac1\beta per nat of KL divergence: the larger β\beta, the cheaper the distortion. This links risk sensitivity to robust MDPs (Robust MDPs & Sim-to-Real Transfer).

CVaR: dual forms and time inconsistency

DerivationProof (continuous distribution)
  1. f′(b)=1−FG(b)α=0⟺b=VaR⁡α(G)f'(b)=1-\frac{F_G(b)}{\alpha}=0\quad\Longleftrightarrow\quad b=\operatorname{VaR}_\alpha(G)

    f(b)=b−1αE[(b−G)+]f(b)=b-\frac1\alpha\E[(b-G)^+] is concave in bb, as (b−G)+(b-G)^+ is convex. Its derivative is 1−1αPr⁡(G<b)1-\frac1\alpha\Pr(G<b), which vanishes where FG(b)=αF_G(b)=\alpha:

  2. f(VaR⁡α)=1α E[G 1{G≤VaR⁡α}]=E[G∣G≤VaR⁡α(G)]=CVaR⁡α(G)f\big(\operatorname{VaR}_\alpha\big)=\frac1\alpha\,\E\big[G\,\mathbf 1\{G\le\operatorname{VaR}_\alpha\}\big]=\E\big[G\mid G\le\operatorname{VaR}_\alpha(G)\big]=\operatorname{CVaR}_\alpha(G)

    At that point E[(b−G)+]=αb−E[G 1{G≤b}]\E[(b-G)^+]=\alpha b-\E[G\,\mathbf 1\{G\le b\}], so

  3. For the dual, the minimizing ξ\xi puts the maximal weight 1/α1/\alpha on the lowest outcomes until E[ξ]=1\E[\xi]=1 is used up, which is exactly the lowest α\alpha of the distribution. ■\blacksquare Chow et al. (2015, Prop. 1) extend the dual to MDPs: the CVaR of a policy's cost equals its worst expected cost over adversarial perturbations of the transition probabilities whose product along any trajectory stays within a budget of 1/α1/\alpha, so a CVaR-optimal policy is also robust to such model errors.

CVaR's tail is a property of the whole return, and that makes it time-inconsistent. A two-stage example with α=12\alpha=\tfrac12: a coin first pays R1=0R_1=0 or 22; then the agent chooses Safe, paying 1, or Risky, paying 0 or 3 with equal probability. A plan says what to do after each outcome of the coin:

After R1=0R_1=0After R1=2R_1=2Total return GGCVaR⁡1/2(G)\operatorname{CVaR}_{1/2}(G)E[G]\E[G]
SafeSafe1 or 3, each ½12
SafeRisky1 (½), 2 (¼), 5 (¼)12.25
RiskySafe0 (¼), 3 (¾)1.52.25
RiskyRisky0, 3, 2, 5, each ¼12.5
The best plan for the static CVaR gambles only after the bad first outcome: the worst half of outcomes then consists of 0 and 3, averaging 1.5.
Check your understanding

The agent adopts the CVaR-optimal plan (Risky after R1=0R_1=0), the coin shows 0, and the agent now re-optimizes the CVaR⁡1/2\operatorname{CVaR}_{1/2} of its remaining reward. What does it do?

  1. Risky, as planned, since the plan was optimal
  2. Safe: for the remaining reward alone, Safe has CVaR⁡1/2=1\operatorname{CVaR}_{1/2}=1 and Risky has 0, so the agent abandons its own plan
  3. It is indifferent between the two
  4. Risky, because Risky has the higher mean
Show the answer

B. Safe: for the remaining reward alone, Safe has CVaR⁡1/2=1\operatorname{CVaR}_{1/2}=1 and Risky has 0, so the agent abandons its own plan

Judged from time 0, Risky in this branch improves the tail of the total; judged from time 1, the same gamble is a bad bet for the remaining reward. That is time inconsistency: the optimal plan for static CVaR depends on the reward already collected, so it cannot be implemented by an agent that re-optimizes the same criterion from its current state, and it is history-dependent in the original state space.

Learning risk-sensitive policies

Derivation. Write CVaR in Rockafellar–Uryasev form, max⁡b{b−1αEθ[(b−G)+]}\max_b\{b-\frac1\alpha\E_{\boldsymbol\theta}[(b-G)^+]\}. By the envelope theorem the gradient is that of the objective at the fixed maximizer b⋆=VaR⁡αb^\star=\operatorname{VaR}_\alpha, and the likelihood-ratio trick gives −1αE[(b⋆−G)+∇log⁡pθ(τ)]=1αE[(G−b⋆)1{G≤b⋆}∇log⁡pθ(τ)]-\frac1\alpha\E[(b^\star-G)^+\nabla\log p_{\boldsymbol\theta}(\tau)]=\frac1\alpha\E[(G-b^\star)\mathbf 1\{G\le b^\star\}\nabla\log p_{\boldsymbol\theta}(\tau)]; dividing out Pr⁡(G≤b⋆)=α\Pr(G\le b^\star)=\alpha gives the conditional form. Only tail trajectories count, each weighted by how far it falls below the VaR, so the update makes the worst trajectories less likely, the more so the worse they are.

python
import numpy as np

def cvar_policy_gradient(returns, scores, alpha=0.05):
    """returns: (N,) episode returns; scores: (N, d), each row the sum of grad log pi over one episode."""
    var = np.quantile(returns, alpha, method="inverted_cdf")  # empirical VaR_alpha
    tail = returns <= var                          # about alpha * N worst episodes
    weights = (returns - var) * tail               # <= 0 inside the tail, 0 outside
    return weights @ scores / (alpha * len(returns))   # ascend this direction to raise CVaR

Tamar et al.'s estimator. The empirical quantile makes it biased; they show it is consistent and prove that stochastic gradient ascent with it converges to a local CVaR optimum. With α=0.05\alpha=0.05, 95% of the episodes contribute nothing, which is the method's practical cost: variance grows as α\alpha shrinks.

What do distributional agents optimize when they act on risk? An agent like IQN with a CVaR distortion picks, at every step, the action whose learned Z(s,a)Z(s,a) has the best CVaR, and uses the same rule in its targets. In the two-stage example, the stage-2 state is the same after either coin outcome, so such an agent picks Safe both times and ends with CVaR⁡1/2=1\operatorname{CVaR}_{1/2}=1, where 1.5 was achievable. Step-by-step CVaR-greedy control optimizes neither the static CVaR of the return nor, in general, a simple dynamic criterion. Two principled routes exist: optimize the static criterion on an augmented state (step 3), or adopt a nested (Markov) risk measure that applies a one-step coherent risk mapping, such as CVaR, at every step (Ruszczyński, 2010), time-consistent by construction but harder to interpret as a property of the return distribution.

Mean–variance looks easiest, since the variance has its own Bellman equation (Sobel, 1982). But optimizing it is hard: Mannor and Tsitsiklis (2011) show that in finite-horizon MDPs, finding a policy that maximizes the mean subject to a variance constraint is NP-hard in some cases and strongly NP-hard in others, and that randomized or history-dependent policies can be strictly better than deterministic Markov ones.

Risk-sensitive criteria are used where tails matter. In finance, deep hedging (Buehler, Gonon, Teichmann & Wood, 2019) trains hedging strategies for derivative portfolios with convex risk measures as objectives, under transaction costs and other frictions. In safety-critical control, CVaR appears as an objective and as a constraint (Constrained MDPs & Lagrangian Methods), and through its dual form it connects to robustness against model error.

Key takeaways

  • Of the common criteria only CVaR (and the mean) is coherent: VaR can hide risk by splitting it, mean–variance can prefer a return that is worse in every outcome, and the entropic measure is concave but not positively homogeneous.
  • Exponential utility of the finite-horizon total reward obeys the multiplicative Bellman equation Wh(s)=min⁡aE[e−βRWh+1(S′)]W_h(s)=\min_a\E[e^{-\beta R}W_{h+1}(S')], because the exponential factorizes; with discounting the risk parameter decays as βγt\beta\gamma^t, and its certainty equivalent equals a KL-penalized worst-case expectation.
  • CVaR⁡α(G)=max⁡b{b−1αE[(b−G)+]}\operatorname{CVaR}_\alpha(G)=\max_b\{b-\frac1\alpha\E[(b-G)^+]\}, attained at the VaR, and equals a worst-case reweighted expectation. Static CVaR is time-inconsistent: its optimal plan depends on the reward already collected, and exact dynamic programming needs a state augmented with the running total (the risk-level augmentation is exact only for evaluating a fixed policy).
  • The CVaR policy gradient uses only tail episodes, weighted by their shortfall below the VaR; step-by-step CVaR-greedy distributional agents optimize neither static CVaR nor, in general, a simple dynamic criterion; and exact mean–variance optimization is NP-hard.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Which of these criteria is a coherent risk measure?

  1. Value at risk, VaR⁡α\operatorname{VaR}_\alpha
  2. Mean minus variance, E[G]−λVar⁡(G)\E[G]-\lambda\Var(G)
  3. CVaR⁡α\operatorname{CVaR}_\alpha
  4. The entropic certainty equivalent UβU_\beta
Show the answer

C. CVaR⁡α\operatorname{CVaR}_\alpha

CVaR is monotone, translation-equivariant, positively homogeneous and superadditive. VaR fails superadditivity (two harmless bets can combine into a dangerous one), mean–variance fails monotonicity and homogeneity, and the entropic measure is concave but not positively homogeneous.

Question 2

Why does exponential utility of the total reward admit a Bellman equation, when the CVaR of the total reward does not?

  1. Because exponential utility is risk-neutral for small β\beta
  2. Because e−β(R+G′)=e−βRe−βG′e^{-\beta(R+G')}=e^{-\beta R}e^{-\beta G'}: past rewards only multiply the future's criterion by a positive constant, so the best continuation does not depend on them
  3. Because exponential utility is coherent
  4. Because CVaR cannot be estimated from samples
Show the answer

B. Because e−β(R+G′)=e−βRe−βG′e^{-\beta(R+G')}=e^{-\beta R}e^{-\beta G'}: past rewards only multiply the future's criterion by a positive constant, so the best continuation does not depend on them

Multiplicative separability means the continuation problem is the same whatever reward has been collected. For CVaR, whether the future's risk falls inside the worst α\alpha of the total depends on what has been collected so far, so the optimal continuation depends on the past.

Question 3

For a discounted exponential-utility objective E[e−β∑tγtRt+1]\E[e^{-\beta\sum_t\gamma^tR_{t+1}}], why is the optimal policy generally nonstationary?

  1. Because the continuation after one step is an exponential-utility problem with risk parameter βγ\beta\gamma: the effective risk aversion shrinks with time
  2. Because discounted problems never have stationary optimal policies
  3. Because the exponential is not monotone
  4. It is not: discounted exponential utility always has a stationary optimal policy
Show the answer

A. Because the continuation after one step is an exponential-utility problem with risk parameter βγ\beta\gamma: the effective risk aversion shrinks with time

Factor out the first reward: what remains is exp⁡(−(βγ)∑t≥1γt−1Rt+1)\exp(-(\beta\gamma)\sum_{t\ge1}\gamma^{t-1}R_{t+1}). The same state faced at a later time is faced with less risk aversion, so the best action can change with time. Including the current risk parameter in the state makes the problem Markov again.

Question 4

In the CVaR policy gradient, which sampled episodes contribute to the update, and with what weight?

  1. All episodes, weighted by their return, as in REINFORCE
  2. Only the best α\alpha fraction, weighted by how far they exceed the mean
  3. Only episodes at or below the estimated VaR, weighted by G−VaR⁡α≤0G-\operatorname{VaR}_\alpha\le0, so the update makes the worst episodes less likely, the more so the worse they are
  4. Only the single worst episode
Show the answer

C. Only episodes at or below the estimated VaR, weighted by G−VaR⁡α≤0G-\operatorname{VaR}_\alpha\le0, so the update makes the worst episodes less likely, the more so the worse they are

The gradient is E[(G−VaR⁡α)∇log⁡pθ(τ)∣G≤VaR⁡α]\E[(G-\operatorname{VaR}_\alpha)\nabla\log p_{\boldsymbol\theta}(\tau)\mid G\le\operatorname{VaR}_\alpha]: episodes above the VaR have weight zero, and tail episodes push their own probability down in proportion to their shortfall. Discarding 1−α1-\alpha of the data is why the estimator's variance grows as α\alpha shrinks.

Further reading

  • R. A. Howard & J. E. Matheson, "Risk-sensitive Markov decision processes", Management Science 18(7), 356–369 (1972).
  • P. Artzner, F. Delbaen, J.-M. Eber & D. Heath, "Coherent measures of risk", Mathematical Finance 9(3), 203–228 (1999).
  • R. T. Rockafellar & S. Uryasev, "Optimization of conditional value-at-risk", Journal of Risk 2(3), 21–41 (2000).
  • Y. Chow, A. Tamar, S. Mannor & M. Pavone, "Risk-sensitive and robust decision-making: a CVaR optimization approach", NeurIPS (2015).
  • A. Tamar, Y. Glassner & S. Mannor, "Optimizing the CVaR via sampling", AAAI (2015).