Topic 4: Probability Trees and Conditional Expectations

Learning Objectives

By the end of this topic, you should be able to:

  1. Calculate expected values, variances, and standard deviations and demonstrate their application to investment problems
  2. Formulate an investment problem as a probability tree and explain the use of conditional expectations in investment application
  3. Calculate and interpret an updated probability in an investment setting using Bayes’ formula

Core Concepts: The Foundation

Probability and Decision Analysis

Probability theory forms the backbone of quantitative finance, enabling us to model uncertainty and make informed decisions under risk. Building on the statistical measures from Topic 3, this topic focuses on three critical tools:

  • Probability Trees: Visual representations of sequential events and their probabilities
  • Conditional Expectations: Expected values updated with new information
  • Bayes’ Theorem: A framework for updating beliefs based on evidence

These concepts are essential for portfolio management, risk assessment, and valuation in both traditional finance and decentralized finance (DeFi) applications.


Learning Objective 1: Expected Values, Variances, and Standard Deviations

Core Concept: Statistical Measures of Risk and Return

Expected Value (E[X]) represents the average outcome of a random variable over many trials. In finance, it’s the mean return we anticipate from an investment.

Variance (Var(X) or σ²) measures the dispersion of outcomes around the expected value, indicating the level of uncertainty or risk.

Standard Deviation (σ) is the square root of variance, expressed in the same units as the original data, making it more intuitive for risk assessment.

Formulas & Calculations

For Discrete Random Variables:

Expected Value: formula

E[X] = Σ P(xi) × xi

Where P(xi) is the probability of outcome xi

Variance: formula

Var(X) = E[X²] - [E(X)]²
or
Var(X) = Σ P(xi) × [xi - E(X)]²

Standard Deviation: formula

σ = √Var(X)

For Continuous Random Variables:

Expected Value:

E[X] = ∫ x × f(x) dx

Variance:

Var(X) = ∫ [x - E(X)]² × f(x) dx

HP 12C Calculator Steps

Calculating Expected Value and Standard Deviation:

  1. Clear calculator: f CLX
  2. Enter data points and probabilities:
    • Enter return: 20 ENTER
    • Enter probability: 0.3 Σ+
    • Enter return: 10 ENTER
    • Enter probability: 0.5 Σ+
    • Enter return: -5 ENTER
    • Enter probability: 0.2 Σ+
  3. Calculate mean: g x̄ (displays expected return)
  4. Calculate standard deviation: g s (displays standard deviation)

Practical Examples

Example 1: Stock Return Analysis

A technology stock has the following return scenarios:

  • Bull market: 25% return, probability 0.3
  • Normal market: 12% return, probability 0.5
  • Bear market: -8% return, probability 0.2

Calculations:

E[R] = (0.3 × 25%) + (0.5 × 12%) + (0.2 × -8%)
E[R] = 7.5% + 6% - 1.6% = 11.9%

Var(R) = 0.3(25-11.9)² + 0.5(12-11.9)² + 0.2(-8-11.9)²
Var(R) = 0.3(171.61) + 0.5(0.01) + 0.2(396.01)
Var(R) = 51.48 + 0.005 + 79.20 = 130.69

σ = √130.69 = 11.43%

Example 2: Bond Portfolio Analysis

A corporate bond portfolio with credit risk scenarios:

  • No default: 6% return, probability 0.85
  • Partial default: -15% return, probability 0.12
  • Total default: -80% return, probability 0.03

Expected Return: 6%(0.85) + (-15%)(0.12) + (-80%)(0.03) = 5.1% - 1.8% - 2.4% = 0.9%

Risk Assessment: High standard deviation due to tail risk from default scenarios.

DeFi Application: Liquidity Pool Returns

Automated Market Maker (AMM) Expected Returns

Expected value calculations are essential for evaluating DeFi strategies where outcomes depend on volatile market conditions. Consider providing liquidity to an ETH/USDC pool on Uniswap with the following scenarios: defi-application

Scenario Analysis:

  • High volatility (50% price movement): -5% return due to impermanent loss, probability 0.2
  • Medium volatility (20% price movement): +8% return from fees minus impermanent loss, probability 0.6
  • Low volatility (5% price movement): +12% return primarily from fees, probability 0.2

Calculations:

E[R] = 0.2(-5%) + 0.6(8%) + 0.2(12%) = -1% + 4.8% + 2.4% = 6.2%

Variance calculation:
Var(R) = 0.2(-5-6.2)² + 0.6(8-6.2)² + 0.2(12-6.2)²
Var(R) = 0.2(125.44) + 0.6(3.24) + 0.2(33.64)
Var(R) = 25.09 + 1.94 + 6.73 = 33.76

σ = √33.76 = 5.81%

Smart Contract Risk Analysis

Protocol Security Scenarios:

  • No exploit: 15% APY, probability 0.92
  • Minor exploit (partial loss): -20% return, probability 0.06
  • Major exploit (total loss): -100% return, probability 0.02

Expected Return:

E[R] = 0.92(15%) + 0.06(-20%) + 0.02(-100%)
E[R] = 13.8% - 1.2% - 2% = 10.6%

This analysis helps DeFi users understand the risk-adjusted returns of yield farming strategies.


Learning Objective 2: Probability Trees and Conditional Expectations

Core Concept: Sequential Decision Analysis

Probability Trees are graphical tools that map out all possible outcomes of a series of events, showing:

  • The sequence of events
  • The probability of each outcome
  • The final payoffs or results

Conditional Expectations represent the expected value of a random variable given that specific information or events have occurred.

Formulas & Calculations

Conditional Expectation Formula:

E[X|A] = Σ P(xi|A) × xi

Where P(xi|A) is the conditional probability of outcome xi given event A.

Joint Probability:

P(A ∩ B) = P(A|B) × P(B) = P(B|A) × P(A)

Total Probability Rule:

P(B) = Σ P(B|Ai) × P(Ai)

Practical Examples

Example 1: Multi-Stage Investment Decision

An investor is considering a two-stage venture capital investment:

Stage 1 - Economic Conditions:

  • Expansion (probability 0.6)
  • Recession (probability 0.4)

Stage 2 - Company Performance (conditional on economic conditions):

Given Expansion:

  • High growth: 200% return, probability 0.4
  • Moderate growth: 50% return, probability 0.5
  • Decline: -30% return, probability 0.1

Given Recession:

  • Survival: 20% return, probability 0.3
  • Struggle: -20% return, probability 0.5
  • Failure: -80% return, probability 0.2

Probability Tree Calculation:

Path Probabilities:
P(Expansion ∩ High) = 0.6 × 0.4 = 0.24
P(Expansion ∩ Moderate) = 0.6 × 0.5 = 0.30
P(Expansion ∩ Decline) = 0.6 × 0.1 = 0.06
P(Recession ∩ Survival) = 0.4 × 0.3 = 0.12
P(Recession ∩ Struggle) = 0.4 × 0.5 = 0.20
P(Recession ∩ Failure) = 0.4 × 0.2 = 0.08

Overall Expected Return:
E[R] = 0.24(200%) + 0.30(50%) + 0.06(-30%) + 0.12(20%) + 0.20(-20%) + 0.08(-80%)
E[R] = 48% + 15% - 1.8% + 2.4% - 4% - 6.4% = 53.2%

Conditional Expected Returns:
E[R|Expansion] = 0.4(200%) + 0.5(50%) + 0.1(-30%) = 80% + 25% - 3% = 102%
E[R|Recession] = 0.3(20%) + 0.5(-20%) + 0.2(-80%) = 6% - 10% - 16% = -20%

Example 2: Credit Rating Transition Analysis

A bond portfolio manager analyzes credit migration over one year:

Initial Credit Rating: BBB

  • Upgrade to A: probability 0.15, bond price +8%
  • Remain BBB: probability 0.70, bond price +3%
  • Downgrade to BB: probability 0.12, bond price -15%
  • Default: probability 0.03, bond price -60%

Expected Return:

E[R] = 0.15(8%) + 0.70(3%) + 0.12(-15%) + 0.03(-60%)
E[R] = 1.2% + 2.1% - 1.8% - 1.8% = -0.3%

DeFi Application: Yield Farming Strategy

Multi-Protocol Yield Strategy

Consider a yield farming strategy across multiple DeFi protocols:

Protocol Selection Tree:

Stage 1 - Market Conditions:

  • Bull market (probability 0.4)
  • Sideways market (probability 0.4)
  • Bear market (probability 0.2)

Stage 2 - Protocol Choice (conditional on market):

Bull Market Strategy:

  • High-risk protocol: 300% APY, probability 0.6
  • Medium-risk protocol: 80% APY, probability 0.4

Sideways Market Strategy:

  • Medium-risk protocol: 60% APY, probability 0.7
  • Low-risk protocol: 25% APY, probability 0.3

Bear Market Strategy:

  • Low-risk protocol: 15% APY, probability 0.8
  • Stablecoin farming: 8% APY, probability 0.2

Stage 3 - Protocol Risk Outcomes:

High-risk protocol outcomes:

  • Success: Achieve target APY, probability 0.7
  • Partial exploit: -30% of investment, probability 0.2
  • Total exploit: -100% of investment, probability 0.1

Medium-risk protocol outcomes:

  • Success: Achieve target APY, probability 0.85
  • Partial exploit: -20% of investment, probability 0.12
  • Total exploit: -100% of investment, probability 0.03

Low-risk protocol outcomes:

  • Success: Achieve target APY, probability 0.95
  • Minor issue: -5% of investment, probability 0.04
  • Major issue: -50% of investment, probability 0.01

Expected Return Calculation:

Bull Market Expected Return:
High-risk path: 0.4 × 0.6 × [0.7(300%) + 0.2(-30%) + 0.1(-100%)]
              = 0.24 × [210% - 6% - 10%] = 0.24 × 194% = 46.56%

Medium-risk path: 0.4 × 0.4 × [0.85(80%) + 0.12(-20%) + 0.03(-100%)]
                = 0.16 × [68% - 2.4% - 3%] = 0.16 × 62.6% = 10.02%

Bull Market Total: 46.56% + 10.02% = 56.58%

Overall Strategy Expected Return:
Bull: 56.58% (weight 0.4)
Sideways: [calculation similar] = 32.15% (weight 0.4)
Bear: [calculation similar] = 8.94% (weight 0.2)

Total E[R] = 0.4(56.58%) + 0.4(32.15%) + 0.2(8.94%) = 37.27%

Conditional Expectations in DeFi

Given Bull Market: E[R|Bull] = 56.58% / 0.4 = 141.45% Given Bear Market: E[R|Bear] = 8.94% / 0.2 = 44.7%

This analysis shows how expected returns vary dramatically based on market conditions, helping DeFi investors adjust their strategies accordingly.


Learning Objective 3: Bayes’ Formula and Updated Probabilities

Core Concept: Bayesian Updating

Bayes’ Theorem provides a mathematical framework for updating beliefs when new information becomes available. This is one of the most frequently tested probability concepts on the finance exam and has direct applications in credit analysis, market regime detection, and DeFi security monitoring. exam-focus

It is fundamental to:

  • Credit risk assessment
  • Market anomaly detection
  • Algorithm refinement
  • Risk management

Formulas & Calculations

Bayes’ Theorem: formula exam-focus

P(A|B) = [P(B|A) × P(A)] / P(B)

Where:

  • P(A|B) = Posterior probability (updated belief)
  • P(B|A) = Likelihood (probability of evidence given hypothesis)
  • P(A) = Prior probability (initial belief)
  • P(B) = Total probability of evidence

Extended Form with Multiple Hypotheses:

P(Ai|B) = [P(B|Ai) × P(Ai)] / [Σ P(B|Aj) × P(Aj)]

HP 12C Implementation

Since HP 12C doesn’t have direct Bayesian functions, we calculate step by step:

  1. Calculate numerator: P(B|A) × P(A)
  2. Calculate denominator: Total probability using the law of total probability
  3. Divide: Numerator ÷ Denominator

Practical Examples

Example 1: Credit Default Prediction

A bank uses a credit scoring model to assess default probability:

Prior Information:

  • P(Default) = 0.05 (5% historical default rate)
  • P(No Default) = 0.95

New Information: Credit score drops significantly

  • P(Score Drop|Default) = 0.80 (likelihood of score drop given default)
  • P(Score Drop|No Default) = 0.15 (likelihood of score drop given no default)

Question: What’s the updated probability of default given the score drop?

Solution using Bayes’ Theorem:

Step 1: Calculate total probability of score drop
P(Score Drop) = P(Score Drop|Default) × P(Default) + P(Score Drop|No Default) × P(No Default)
P(Score Drop) = 0.80 × 0.05 + 0.15 × 0.95 = 0.04 + 0.1425 = 0.1825

Step 2: Apply Bayes' theorem
P(Default|Score Drop) = [P(Score Drop|Default) × P(Default)] / P(Score Drop)
P(Default|Score Drop) = [0.80 × 0.05] / 0.1825 = 0.04 / 0.1825 = 0.219

Updated default probability: 21.9% (up from 5%)

Example 2: Market Regime Detection

An investment manager wants to determine if the market is in a bear regime based on recent performance.

Prior Beliefs:

  • P(Bear Market) = 0.20
  • P(Bull Market) = 0.80

Observed Evidence: Market declined 10% in one month

  • P(10% Decline|Bear) = 0.60
  • P(10% Decline|Bull) = 0.05

Updated Probability:

P(10% Decline) = 0.60 × 0.20 + 0.05 × 0.80 = 0.12 + 0.04 = 0.16

P(Bear|10% Decline) = [0.60 × 0.20] / 0.16 = 0.12 / 0.16 = 0.75

P(Bull|10% Decline) = [0.05 × 0.80] / 0.16 = 0.04 / 0.16 = 0.25

The probability of being in a bear market increased from 20% to 75%.

DeFi Application: Smart Contract Security Assessment

Bayesian reasoning is particularly powerful in DeFi security, where monitoring systems must continuously update the probability of an exploit based on incoming on-chain evidence. defi-application

Example 1: Protocol Exploit Detection

A DeFi security firm monitors protocols for potential exploits:

Prior Assessment:

  • P(Vulnerable) = 0.10 (10% of protocols have critical vulnerabilities)
  • P(Secure) = 0.90

New Evidence: Unusual transaction pattern detected

  • P(Unusual Pattern|Vulnerable) = 0.85
  • P(Unusual Pattern|Secure) = 0.03

Bayesian Update:

P(Unusual Pattern) = 0.85 × 0.10 + 0.03 × 0.90 = 0.085 + 0.027 = 0.112

P(Vulnerable|Unusual Pattern) = [0.85 × 0.10] / 0.112 = 0.085 / 0.112 = 0.759

Updated vulnerability probability: 75.9% (up from 10%)

This significant increase warrants immediate investigation and potential user warnings.

Example 2: Yield Farming Strategy Optimization

A yield farmer uses Bayesian updating to assess protocol reliability:

Initial Assessment:

  • P(High Yield Sustainable) = 0.30
  • P(Yield Will Drop) = 0.70

New Information: Protocol announces token buyback program

  • P(Buyback|Sustainable) = 0.80
  • P(Buyback|Will Drop) = 0.20

Updated Assessment:

P(Buyback) = 0.80 × 0.30 + 0.20 × 0.70 = 0.24 + 0.14 = 0.38

P(Sustainable|Buyback) = [0.80 × 0.30] / 0.38 = 0.24 / 0.38 = 0.632

Updated sustainability probability: 63.2% (up from 30%)

Example 3: MEV Bot Profitability Analysis

An MEV (Maximal Extractable Value) bot operator assesses transaction success probability:

Prior Belief:

  • P(Profitable Transaction) = 0.25
  • P(Unprofitable Transaction) = 0.75

New Evidence: Gas price spike detected

  • P(Gas Spike|Profitable) = 0.90 (high gas usually means profitable opportunities)
  • P(Gas Spike|Unprofitable) = 0.30

Bayesian Update:

P(Gas Spike) = 0.90 × 0.25 + 0.30 × 0.75 = 0.225 + 0.225 = 0.45

P(Profitable|Gas Spike) = [0.90 × 0.25] / 0.45 = 0.225 / 0.45 = 0.50

Updated profitability probability: 50% (up from 25%)

This analysis helps MEV bots decide whether to execute trades during high gas periods.


Advanced DeFi Applications

1. Liquidation Cascade Probability Analysis

DeFi lending protocols like Aave and Compound face cascade liquidation risks during market volatility. Using probability trees and Bayesian updating: defi-application

Scenario Tree:

  1. Market Shock (probability 0.15)
    • Triggers initial liquidations
  2. Cascade Effects (conditional on market shock)
    • Limited cascade: probability 0.60
    • Moderate cascade: probability 0.30
    • Severe cascade: probability 0.10

Bayesian Updating with New Information: If we observe unusual on-chain activity (large transactions, MEV activity), we can update cascade probabilities using Bayes’ theorem.

2. Oracle Manipulation Risk Assessment

Prior Probabilities:

  • P(Oracle Attack) = 0.02
  • P(Normal Operation) = 0.98

Evidence Indicators:

  • Unusual price deviations
  • Volume spikes in specific venues
  • Coordinated large transactions

Using Bayes’ theorem to update attack probabilities based on multiple evidence sources.

3. Governance Attack Probability

Multi-stage Analysis:

  1. Token Accumulation Phase
    • Attacker accumulates governance tokens
    • Probability assessment based on voting power concentration
  2. Proposal Submission
    • Malicious proposal detection
    • Community response analysis
  3. Voting Execution
    • Success probability based on historical voting patterns

Key Formulas Summary

Expected Value and Variance

E[X] = Σ P(xi) × xi
Var(X) = E[X²] - [E(X)]²
σ = √Var(X)

Conditional Probability

P(A|B) = P(A ∩ B) / P(B)
E[X|A] = Σ P(xi|A) × xi

Bayes’ Theorem

P(A|B) = [P(B|A) × P(A)] / P(B)

Total Probability Rule

P(B) = Σ P(B|Ai) × P(Ai)

Practice Problems

Problem 1: DeFi Yield Strategy practice-problem

A DeFi investor allocates funds across three protocols with the following expected returns and probabilities:

  • Protocol A: 150% APY, 30% probability
  • Protocol B: 80% APY, 50% probability
  • Protocol C: 25% APY, 20% probability

Calculate the expected return and standard deviation.

Problem 2: Smart Contract Audit Results practice-problem

A protocol has a 5% prior probability of having a critical vulnerability. An audit finds a medium-risk issue. Given that:

  • P(Medium Issue|Critical Vulnerability) = 0.70
  • P(Medium Issue|No Critical Vulnerability) = 0.15

What’s the updated probability of a critical vulnerability?

Problem 3: Liquidation Risk Tree practice-problem

Build a probability tree for a leveraged DeFi position with:

  • 70% chance of stable markets (±5% price movement)
  • 25% chance of moderate volatility (±20% price movement)
  • 5% chance of high volatility (±50% price movement)

Given different leverage ratios, calculate liquidation probabilities.


Visual Representation Guidelines

Probability Tree Structure

                    Initial Event
                   /             \
            Outcome 1           Outcome 2
           (prob p1)           (prob p2)
              /   \               /   \
         Final 1.1 Final 1.2  Final 2.1 Final 2.2
        (prob q1) (prob q2)  (prob r1) (prob r2)

Bayesian Update Process

Prior Belief → New Evidence → Likelihood Assessment → Posterior Belief
     ↓              ↓                ↓                    ↓
   P(H)         Observe E         P(E|H)              P(H|E)

Summary and Key Takeaways

  1. Expected Value and Risk Measures provide the foundation for quantifying investment returns and uncertainties in both traditional and DeFi contexts.

  2. Probability Trees enable systematic analysis of complex, multi-stage investment scenarios, particularly valuable for DeFi strategies with multiple risk factors.

  3. Bayes’ Theorem offers a principled approach to updating beliefs based on new information, crucial for dynamic risk management in fast-moving DeFi markets.

  4. DeFi Applications demonstrate how these concepts apply to emerging financial technologies, from yield farming optimization to smart contract security assessment.

  5. Integration of these tools provides a comprehensive framework for decision-making under uncertainty, essential for success in both traditional finance and the evolving DeFi ecosystem.

The combination of probability trees, conditional expectations, and Bayesian updating creates a powerful toolkit for navigating the complex, uncertain landscape of modern finance, where rapid adaptation to new information often determines investment success.