Basic Statistics and Probability: Understanding Uncertainty

30 minbeginner

5. Basic Statistics and Probability: Understanding Uncertainty

Financial markets are fundamentally about uncertainty. Stock prices, interest rates, exchange rates, and returns are all uncertain. Statistics and probability provide the tools for understanding, measuring, and managing this uncertainty. Understanding basic statistics and probability is essential for making informed financial decisions.

Descriptive Statistics

Descriptive statistics summarize and describe data. They help us understand what has happened and provide context for decision-making.

Measures of Central Tendency:

Mean (Average): The sum of all values divided by the number of values. The mean is the most common measure of central tendency.

μ=∑i=1nxin\mu = \frac{\sum_{i=1}^{n} x_i}{n}

Example: If stock returns are 5%, 8%, -2%, 12%, and 7%:

  • Mean = (5 + 8 - 2 + 12 + 7) / 5 = 30 / 5 = 6%

Median: The middle value when data is sorted. Half the values are above the median, half are below. The median is less affected by outliers than the mean.

Mode: The most frequently occurring value. Less commonly used in finance.

Measures of Dispersion:

Variance: Measures how spread out values are around the mean. It's the average of squared deviations from the mean.

σ2=∑i=1n(xi−μ)2n\sigma^2 = \frac{\sum_{i=1}^{n} (x_i - \mu)^2}{n}

Standard Deviation: The square root of variance. It's in the same units as the data, making it more interpretable.

σ=σ2\sigma = \sqrt{\sigma^2}

Example: Using the stock returns above (mean = 6%):

Let's visualize statistical concepts with probability distributions:

Python exercise

#| label: statistics-probability
#| fig-cap: "Statistics and Probability: Normal Distribution and Risk Measures"
#| fig-width: 14
#| fig-height: 8
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display
from scipy import stats

# Sample stock returns data
returns = np.array([5, 8, -2, 12, 7, 10, -1, 15, 9, 6, 4, 11, 3, 8, 7, 9, 5, 6, 10, 8])
mean_return = np.mean(returns)
std_return = np.std(returns, ddof=1)  # Sample standard deviation
variance = np.var(returns, ddof=1)

# Normal distribution for comparison
x = np.linspace(mean_return - 4*std_return, mean_return + 4*std_return, 100)
normal_pdf = stats.norm.pdf(x, mean_return, std_return)

# Create figure
fig, axes = plt.subplots(2, 2, figsize=(16, 12))
fig.suptitle('Statistics and Probability: Understanding Uncertainty in Finance', fontsize=16, fontweight='bold')

# Plot 1: Histogram and Normal Distribution
ax1 = axes[0, 0]
ax1.hist(returns, bins=10, density=True, alpha=0.7, color='blue', edgecolor='black', 
         label='Observed Returns', linewidth=1.5)
ax1.plot(x, normal_pdf, 'r-', linewidth=3, label=f'Normal Distribution\n(μ={mean_return:.2f}%, σ={std_return:.2f}%)', alpha=0.8)
ax1.axvline(x=mean_return, color='green', linestyle='--', linewidth=2, alpha=0.7, label=f'Mean: {mean_return:.2f}%')
ax1.axvline(x=mean_return + std_return, color='orange', linestyle=':', linewidth=2, alpha=0.7, label=f'±1σ: {mean_return+std_return:.2f}%')
ax1.axvline(x=mean_return - std_return, color='orange', linestyle=':', linewidth=2, alpha=0.7)
ax1.fill_between(x, 0, normal_pdf, where=(x >= mean_return - std_return) & (x <= mean_return + std_return),
                 alpha=0.3, color='orange', label='68% within ±1σ')
ax1.set_xlabel('Return (%)', fontsize=12, fontweight='bold')
ax1.set_ylabel('Probability Density', fontsize=12, fontweight='bold')
ax1.set_title('Stock Returns Distribution', fontsize=13, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--')
ax1.legend(loc='upper right', fontsize=9)

# Plot 2: Cumulative Distribution Function (CDF)
ax2 = axes[0, 1]
normal_cdf = stats.norm.cdf(x, mean_return, std_return)
ax2.plot(x, normal_cdf, 'b-', linewidth=3, label='Cumulative Distribution', alpha=0.8)
ax2.axhline(y=0.5, color='red', linestyle='--', linewidth=2, alpha=0.7, label='Median (50th percentile)')
ax2.axvline(x=mean_return, color='red', linestyle='--', linewidth=2, alpha=0.7)
ax2.axhline(y=0.16, color='orange', linestyle=':', linewidth=1.5, alpha=0.7, label='16th percentile (-1σ)')
ax2.axhline(y=0.84, color='orange', linestyle=':', linewidth=1.5, alpha=0.7, label='84th percentile (+1σ)')
ax2.fill_between(x, 0, normal_cdf, alpha=0.3, color='blue')
ax2.set_xlabel('Return (%)', fontsize=12, fontweight='bold')
ax2.set_ylabel('Cumulative Probability', fontsize=12, fontweight='bold')
ax2.set_title('Cumulative Distribution Function (CDF)', fontsize=13, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.legend(loc='lower right', fontsize=9)
ax2.set_ylim(0, 1)

# Plot 3: Standard Deviation Zones
ax3 = axes[1, 0]
x_zones = np.linspace(mean_return - 3*std_return, mean_return + 3*std_return, 100)
pdf_zones = stats.norm.pdf(x_zones, mean_return, std_return)

# Different standard deviation zones
ax3.fill_between(x_zones, 0, pdf_zones, where=(x_zones >= mean_return - std_return) & (x_zones <= mean_return + std_return),
                 alpha=0.5, color='green', label='±1σ (68.3%)')
ax3.fill_between(x_zones, 0, pdf_zones, where=((x_zones >= mean_return - 2*std_return) & (x_zones < mean_return - std_return)) |
                 ((x_zones > mean_return + std_return) & (x_zones <= mean_return + 2*std_return)),
                 alpha=0.4, color='yellow', label='±2σ (27.2%)')
ax3.fill_between(x_zones, 0, pdf_zones, where=((x_zones >= mean_return - 3*std_return) & (x_zones < mean_return - 2*std_return)) |
                 ((x_zones > mean_return + 2*std_return) & (x_zones <= mean_return + 3*std_return)),
                 alpha=0.3, color='orange', label='±3σ (4.3%)')
ax3.plot(x_zones, pdf_zones, 'k-', linewidth=2, alpha=0.8)
ax3.axvline(x=mean_return, color='red', linestyle='--', linewidth=2, alpha=0.7, label=f'Mean: {mean_return:.2f}%')
ax3.set_xlabel('Return (%)', fontsize=12, fontweight='bold')
ax3.set_ylabel('Probability Density', fontsize=12, fontweight='bold')
ax3.set_title('Standard Deviation Zones: Probability of Returns', fontsize=13, fontweight='bold')
ax3.grid(True, alpha=0.3, linestyle='--')
ax3.legend(loc='upper right', fontsize=9)

# Plot 4: Risk vs Return Trade-off
ax4 = axes[1, 1]
# Simulate different investments
investments = ['Low Risk', 'Medium Risk', 'High Risk']
means = [4, 8, 12]
stds = [2, 5, 8]
colors_inv = ['green', 'orange', 'red']

for i, (inv, mean, std, color) in enumerate(zip(investments, means, stds, colors_inv)):
    x_inv = np.linspace(mean - 3*std, mean + 3*std, 100)
    pdf_inv = stats.norm.pdf(x_inv, mean, std)
    ax4.plot(x_inv, pdf_inv, linewidth=2.5, label=f'{inv} (μ={mean}%, σ={std}%)', color=color, alpha=0.8)
    ax4.fill_between(x_inv, 0, pdf_inv, alpha=0.2, color=color)

ax4.set_xlabel('Return (%)', fontsize=12, fontweight='bold')
ax4.set_ylabel('Probability Density', fontsize=12, fontweight='bold')
ax4.set_title('Risk-Return Trade-off: Different Investments', fontsize=13, fontweight='bold')
ax4.grid(True, alpha=0.3, linestyle='--')
ax4.legend(loc='upper right', fontsize=9)

plt.tight_layout()
display(fig)
plt.close(fig)

print(f"\n📊 **Statistics and Probability Analysis**")
print(f"{'='*60}")
print(f"Sample Returns Data:")
print(f"  Returns: {returns}")
print(f"{'='*60}")
print(f"Descriptive Statistics:")
print(f"  Mean (μ):          {mean_return:.2f}%")
print(f"  Median:            {np.median(returns):.2f}%")
print(f"  Standard Deviation (σ): {std_return:.2f}%")
print(f"  Variance (σ²):      {variance:.2f}")
print(f"{'='*60}")
print(f"Normal Distribution Properties:")
print(f"  • 68.3% of returns within ±1σ: [{mean_return-std_return:.2f}%, {mean_return+std_return:.2f}%]")
print(f"  • 95.4% of returns within ±2σ: [{mean_return-2*std_return:.2f}%, {mean_return+2*std_return:.2f}%]")
print(f"  • 99.7% of returns within ±3σ: [{mean_return-3*std_return:.2f}%, {mean_return+3*std_return:.2f}%]")
print(f"{'='*60}")
print(f"Risk-Return Trade-off:")
print(f"  • Higher expected return typically comes with higher risk (volatility)")
print(f"  • Standard deviation measures risk/uncertainty")
print(f"  • Understanding distributions helps assess investment risk")
print(f"{'='*60}")
print(f"✅ Key Insight: Standard deviation quantifies risk")
print(f"✅ Normal distribution is a common model for returns")
print(f"✅ Probability distributions help make informed decisions under uncertainty")
  • Variance = [(5-6)^2 + (8-6)^2 + (-2-6)^2 + (12-6)^2 + (7-6)^2] / 5
  • Variance = [1 + 4 + 64 + 36 + 1] / 5 = 106 / 5 = 21.2
  • Standard Deviation = √21.2 = 4.6%

Standard deviation is a key measure of risk in finance. Higher standard deviation means higher volatility and higher risk.

Range: The difference between the maximum and minimum values. Simple but useful for understanding the spread of data.

Coefficient of Variation: Standard deviation divided by mean. It's a relative measure of risk, useful for comparing investments with different expected returns.

CV=σμCV = \frac{\sigma}{\mu}

Probability Basics

Probability measures the likelihood of events. Understanding probability is crucial for understanding risk and making decisions under uncertainty.

Basic Concepts:

Probability: A number between 0 and 1 (or 0% and 100%) representing the likelihood of an event. P(A) = 0 means the event is impossible. P(A) = 1 means the event is certain.

Sample Space: The set of all possible outcomes. For a stock price, the sample space might be all possible prices.

Event: A subset of the sample space. For example, "stock price above $100" is an event.

Mutually Exclusive Events: Events that cannot occur simultaneously. If one happens, the others cannot.

Independent Events: Events where the occurrence of one doesn't affect the probability of the other.

Conditional Probability: The probability of an event given that another event has occurred.

P(A∣B)=P(A and B)P(B)P(A|B) = \frac{P(A \text{ and } B)}{P(B)}

Probability Distributions:

Discrete Distributions: Outcomes are countable (like number of defaults).

Continuous Distributions: Outcomes are uncountable (like stock prices or returns).

Normal Distribution: The most important distribution in finance. Many financial variables (returns, prices) are approximately normally distributed. The normal distribution is characterized by mean (μ) and standard deviation (σ).

Properties of Normal Distribution:

  • Bell-shaped and symmetric
  • 68% of values within 1 standard deviation of mean
  • 95% of values within 2 standard deviations of mean
  • 99.7% of values within 3 standard deviations of mean

Z-Score: Measures how many standard deviations a value is from the mean.

z=x−μσz = \frac{x - \mu}{\sigma}

Z-scores allow us to use standard normal distribution tables to find probabilities.

Practice Problem 5.1: Stock Return Analysis

A stock has had the following annual returns over the past 5 years: 12%, 8%, -5%, 15%, 10%. Calculate the mean return, standard deviation, and coefficient of variation. If next year's return is 20%, what is the Z-score?

Solution:

Step 1: Calculate Mean Return:

  • Mean = (12% + 8% + (-5%) + 15% + 10%) / 5
  • Mean = 40% / 5 = 8%

Step 2: Calculate Variance:

  • Variance = [(12-8)^2 + (8-8)^2 + (-5-8)^2 + (15-8)^2 + (10-8)^2] / 5
  • Variance = [16 + 0 + 169 + 49 + 4] / 5
  • Variance = 238 / 5 = 47.6

Step 3: Calculate Standard Deviation:

  • Standard Deviation = √47.6 = 6.90%

Step 4: Calculate Coefficient of Variation:

  • CV = 6.90% / 8% = 0.8625

Step 5: Calculate Z-Score for 20% Return:

  • Z = (20% - 8%) / 6.90% = 12% / 6.90% = 1.74

Analysis:

  • The stock has an average return of 8% with a standard deviation of 6.90%
  • The coefficient of variation of 0.86 indicates moderate risk relative to return
  • A 20% return has a Z-score of 1.74, meaning it's 1.74 standard deviations above the mean. This is a relatively good return but not extremely unusual (Z-scores between -2 and +2 are common)

Python exercise

#| label: practice-5-1
#| fig-cap: "Practice Problem 5.1: Stock Return Analysis"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display
from scipy import stats

# Stock returns data
returns = np.array([12, 8, -5, 15, 10])
mean_return = np.mean(returns)
std_return = np.std(returns, ddof=1)
variance = np.var(returns, ddof=1)
cv = std_return / mean_return
next_return = 20
z_score = (next_return - mean_return) / std_return

# Normal distribution
x = np.linspace(mean_return - 4*std_return, mean_return + 4*std_return, 100)
normal_pdf = stats.norm.pdf(x, mean_return, std_return)

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Practice Problem 5.1: Stock Return Analysis', fontsize=14, fontweight='bold')

# Plot 1: Returns Distribution and Statistics
ax1 = axes[0]
ax1.bar(range(len(returns)), returns, color=['green' if r > mean_return else 'red' if r < 0 else 'orange' for r in returns],
        alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.axhline(y=mean_return, color='blue', linestyle='--', linewidth=2, alpha=0.7, label=f'Mean: {mean_return:.1f}%')
ax1.axhline(y=mean_return + std_return, color='orange', linestyle=':', linewidth=1.5, alpha=0.5, label=f'±1σ: {mean_return+std_return:.1f}%')
ax1.axhline(y=mean_return - std_return, color='orange', linestyle=':', linewidth=1.5, alpha=0.5)
ax1.plot(len(returns), next_return, 'purple', marker='*', markersize=15, markeredgewidth=2, 
         markeredgecolor='white', zorder=5, label=f'Next Year: {next_return}%')
ax1.set_xlabel('Year', fontsize=11, fontweight='bold')
ax1.set_ylabel('Return (%)', fontsize=11, fontweight='bold')
ax1.set_title('Historical Returns and Next Year Prediction', fontsize=12, fontweight='bold')
ax1.set_xticks(range(len(returns) + 1))
ax1.set_xticklabels(['1', '2', '3', '4', '5', 'Next'])
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper right', fontsize=9)

# Plot 2: Normal Distribution with Z-Score
ax2 = axes[1]
ax2.plot(x, normal_pdf, 'b-', linewidth=3, alpha=0.8, label='Normal Distribution')
ax2.axvline(x=mean_return, color='green', linestyle='--', linewidth=2, alpha=0.7, label=f'Mean: {mean_return:.1f}%')
ax2.axvline(x=next_return, color='purple', linestyle='-', linewidth=2.5, alpha=0.8, label=f'Next Year: {next_return}% (Z={z_score:.2f})')
ax2.fill_between(x, 0, normal_pdf, where=(x >= mean_return - std_return) & (x <= mean_return + std_return),
                 alpha=0.3, color='orange', label='±1σ (68%)')
ax2.fill_between(x, 0, normal_pdf, where=(x >= next_return - 1) & (x <= next_return + 1),
                 alpha=0.5, color='purple', label=f'Z-score region')
ax2.set_xlabel('Return (%)', fontsize=11, fontweight='bold')
ax2.set_ylabel('Probability Density', fontsize=11, fontweight='bold')
ax2.set_title(f'Distribution Analysis: Z-score = {z_score:.2f}', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.legend(loc='upper right', fontsize=9)
# Add statistics text
ax2.text(0.05, 0.95, f'Mean: {mean_return:.1f}%\nStd Dev: {std_return:.2f}%\nCV: {cv:.3f}\nZ-score: {z_score:.2f}',
         transform=ax2.transAxes, ha='left', va='top', fontsize=10, fontweight='bold',
         bbox=dict(boxstyle='round,pad=0.5', facecolor='yellow', edgecolor='black', linewidth=1.5))

plt.tight_layout()
display(fig)
plt.close(fig)

Real-World Context: Investors use these statistics to understand a stock's risk-return profile. A higher standard deviation means more volatility and risk. The Z-score helps identify unusual returns - a Z-score above 2 or below -2 might indicate something significant happened. Portfolio managers use these measures to construct diversified portfolios and assess performance.

Practice Problem 5.2: Portfolio Risk Assessment

You're constructing a portfolio with two stocks:

  • Stock A: Expected return 10%, Standard deviation 15%
  • Stock B: Expected return 8%, Standard deviation 12%

If you invest 60% in Stock A and 40% in Stock B, and the correlation between the stocks is 0.3, what is the portfolio's expected return and standard deviation?

Solution:

Step 1: Calculate Portfolio Expected Return:

  • E(R_p) = w_A × E(R_A) + w_B × E(R_B)
  • E(R_p) = 0.60 × 10% + 0.40 × 8%
  • E(R_p) = 6% + 3.2% = 9.2%

Step 2: Calculate Covariance:

  • First, we need correlation: ρ_AB = 0.3
  • Covariance = ρ_AB × σ_A × σ_B
  • Covariance = 0.3 × 15% × 12% = 0.3 × 180 = 54

Step 3: Calculate Portfolio Variance:

  • σ_p^2 = w_A^2 × σ_A^2 + w_B^2 × σ_B^2 + 2 × w_A × w_B × Cov_AB
  • σ_p^2 = (0.60)^2 × (15)^2 + (0.40)^2 × (12)^2 + 2 × 0.60 × 0.40 × 54
  • σ_p^2 = 0.36 × 225 + 0.16 × 144 + 0.48 × 54
  • σ_p^2 = 81 + 23.04 + 25.92 = 129.96

Step 4: Calculate Portfolio Standard Deviation:

  • σ_p = √129.96 = 11.40%

Analysis: The portfolio has an expected return of 9.2% (between the two individual stocks) but a standard deviation of 11.40%, which is less than either stock individually (15% and 12%). This demonstrates diversification - by combining stocks with less than perfect correlation (0.3), the portfolio risk is reduced. The portfolio return is a weighted average, but the risk is less than a weighted average due to diversification.

Python exercise

#| label: practice-5-2
#| fig-cap: "Practice Problem 5.2: Portfolio Risk Assessment"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Stock parameters
return_a = 10
return_b = 8
std_a = 15
std_b = 12
weight_a = 0.60
weight_b = 0.40
correlation = 0.3

# Portfolio calculations
portfolio_return = weight_a * return_a + weight_b * return_b
covariance = correlation * std_a * std_b
portfolio_variance = (weight_a**2 * std_a**2) + (weight_b**2 * std_b**2) + (2 * weight_a * weight_b * covariance)
portfolio_std = np.sqrt(portfolio_variance)

# Risk-return comparison
stocks = ['Stock A', 'Stock B', 'Portfolio\n(60% A, 40% B)']
returns = [return_a, return_b, portfolio_return]
stds = [std_a, std_b, portfolio_std]

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Practice Problem 5.2: Portfolio Risk Assessment', fontsize=14, fontweight='bold')

# Plot 1: Risk-Return Scatter
ax1 = axes[0]
ax1.scatter(std_a, return_a, s=300, color='blue', alpha=0.7, edgecolor='black', linewidth=2, label='Stock A', zorder=5)
ax1.scatter(std_b, return_b, s=300, color='green', alpha=0.7, edgecolor='black', linewidth=2, label='Stock B', zorder=5)
ax1.scatter(portfolio_std, portfolio_return, s=400, color='red', alpha=0.7, edgecolor='black', linewidth=2, 
           marker='*', label='Portfolio', zorder=6)
# Draw line connecting stocks
ax1.plot([std_a, std_b], [return_a, return_b], 'k--', linewidth=1, alpha=0.3, label='Weighted Average (no diversification)')
ax1.set_xlabel('Standard Deviation (Risk, %)', fontsize=11, fontweight='bold')
ax1.set_ylabel('Expected Return (%)', fontsize=11, fontweight='bold')
ax1.set_title('Risk-Return Profile: Individual Stocks vs Portfolio', fontsize=12, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--')
ax1.legend(loc='lower right', fontsize=9)
# Add annotations
for stock, ret, std in zip(stocks, returns, stds):
    ax1.annotate(stock, xy=(std, ret), xytext=(std + 0.5, ret + 0.5),
                fontsize=9, fontweight='bold')

# Plot 2: Comparison Bars
ax2 = axes[1]
x = np.arange(len(stocks))
width = 0.35
bars1 = ax2.bar(x - width/2, returns, width, label='Expected Return', color='green', alpha=0.7, edgecolor='black')
bars2 = ax2.bar(x + width/2, stds, width, label='Standard Deviation (Risk)', color='red', alpha=0.7, edgecolor='black')
ax2.set_ylabel('Percentage (%)', fontsize=11, fontweight='bold')
ax2.set_title('Portfolio vs Individual Stocks', fontsize=12, fontweight='bold')
ax2.set_xticks(x)
ax2.set_xticklabels(stocks)
ax2.legend(loc='upper left', fontsize=9)
ax2.grid(True, alpha=0.3, linestyle='--', axis='y')
for bars in [bars1, bars2]:
    for bar in bars:
        height = bar.get_height()
        ax2.text(bar.get_x() + bar.get_width()/2., height + 0.5,
                 f'{height:.1f}%', ha='center', va='bottom', fontsize=9, fontweight='bold')
ax2.text(0.5, 0.95, f'Diversification Benefit:\nPortfolio risk ({portfolio_std:.1f}%) < Weighted avg',
         transform=ax2.transAxes, ha='center', va='top', fontsize=10, fontweight='bold',
         bbox=dict(boxstyle='round,pad=0.5', facecolor='yellow', edgecolor='black', linewidth=1.5))

plt.tight_layout()
display(fig)
plt.close(fig)

Real-World Context: This is the foundation of modern portfolio theory. By combining assets with different risk-return characteristics and correlations, investors can create portfolios with better risk-adjusted returns. This principle underlies the construction of mutual funds, ETFs, and institutional portfolios. The key insight is that correlation matters - lower correlation provides better diversification benefits.

Practice Problem 5.3: Probability of Investment Outcomes

An investment has three possible outcomes:

  • 30% probability of 15% return
  • 50% probability of 8% return
  • 20% probability of -5% return

Calculate the expected return, variance, and standard deviation. What is the probability of earning at least 8%?

Solution:

Step 1: Calculate Expected Return:

  • E(R) = 0.30 × 15% + 0.50 × 8% + 0.20 × (-5%)
  • E(R) = 4.5% + 4% - 1% = 7.5%

Step 2: Calculate Variance:

  • Variance = 0.30 × (15 - 7.5)^2 + 0.50 × (8 - 7.5)^2 + 0.20 × (-5 - 7.5)^2
  • Variance = 0.30 × 56.25 + 0.50 × 0.25 + 0.20 × 156.25
  • Variance = 16.875 + 0.125 + 31.25 = 48.25

Step 3: Calculate Standard Deviation:

  • σ = √48.25 = 6.95%

Step 4: Probability of earning at least 8%:

  • Outcomes with at least 8% return: 15% (30% probability) and 8% (50% probability)
  • Probability = 30% + 50% = 80%

Analysis:

  • The investment has an expected return of 7.5% with a standard deviation of 6.95%
  • There's an 80% chance of earning at least 8%, but also a 20% chance of losing 5%
  • The risk-return trade-off depends on the investor's risk tolerance

Python exercise

#| label: practice-5-3
#| fig-cap: "Practice Problem 5.3: Probability of Investment Outcomes"
#| fig-width: 14
#| fig-height: 6
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

# Investment outcomes
outcomes = [15, 8, -5]
probabilities = [0.30, 0.50, 0.20]
expected_return = sum(p * r for p, r in zip(probabilities, outcomes))
variance = sum(p * (r - expected_return)**2 for p, r in zip(probabilities, outcomes))
std_dev = np.sqrt(variance)
prob_at_least_8 = probabilities[0] + probabilities[1]  # 15% and 8%

fig, axes = plt.subplots(1, 2, figsize=(16, 6))
fig.suptitle('Practice Problem 5.3: Probability of Investment Outcomes', fontsize=14, fontweight='bold')

# Plot 1: Probability Distribution
ax1 = axes[0]
colors = ['green', 'blue', 'red']
bars = ax1.bar(range(len(outcomes)), probabilities, color=colors, alpha=0.7, edgecolor='black', linewidth=1.5)
ax1.axhline(y=expected_return/10, color='orange', linestyle='--', linewidth=2, alpha=0.5, 
            label=f'Expected Return: {expected_return:.1f}%')
ax1.set_xlabel('Return Outcome (%)', fontsize=11, fontweight='bold')
ax1.set_ylabel('Probability', fontsize=11, fontweight='bold')
ax1.set_title('Probability Distribution of Returns', fontsize=12, fontweight='bold')
ax1.set_xticks(range(len(outcomes)))
ax1.set_xticklabels([f'{r}%' for r in outcomes])
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper right', fontsize=9)
for bar, prob, outcome in zip(bars, probabilities, outcomes):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.02,
             f'{prob*100:.0f}%\n({outcome}%)', ha='center', va='bottom', fontsize=10, fontweight='bold')

# Plot 2: Cumulative Probability
ax2 = axes[1]
sorted_outcomes = sorted(zip(outcomes, probabilities))
sorted_returns = [o[0] for o in sorted_outcomes]
cumulative_prob = np.cumsum([o[1] for o in sorted_outcomes])
ax2.plot(sorted_returns, cumulative_prob, 'b-', linewidth=3, marker='o', markersize=8, alpha=0.8)
ax2.axhline(y=prob_at_least_8, color='green', linestyle='--', linewidth=2, alpha=0.7, 
            label=f'P(≥8%): {prob_at_least_8*100:.0f}%')
ax2.axvline(x=8, color='green', linestyle='--', linewidth=2, alpha=0.7)
ax2.fill_between(sorted_returns, 0, cumulative_prob, alpha=0.3, color='blue')
ax2.set_xlabel('Return (%)', fontsize=11, fontweight='bold')
ax2.set_ylabel('Cumulative Probability', fontsize=11, fontweight='bold')
ax2.set_title('Cumulative Probability Distribution', fontsize=12, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.legend(loc='upper left', fontsize=9)
ax2.set_ylim(0, 1.05)
ax2.text(0.5, 0.95, f'Expected Return: {expected_return:.1f}%\nStd Dev: {std_dev:.2f}%\nP(≥8%): {prob_at_least_8*100:.0f}%',
         transform=ax2.transAxes, ha='center', va='top', fontsize=10, fontweight='bold',
         bbox=dict(boxstyle='round,pad=0.5', facecolor='yellow', edgecolor='black', linewidth=1.5))

plt.tight_layout()
display(fig)
plt.close(fig)

Real-World Context: This type of analysis is used in risk assessment and investment decision-making. Financial analysts use probability distributions to model investment outcomes and assess risk. This helps investors understand not just the expected return, but the range of possible outcomes and their probabilities. Options traders use similar probability analysis to price options and assess risk.

Expected Value and Risk

Expected Value (Expected Return): The weighted average of possible outcomes, weighted by their probabilities.

E(X)=∑i=1nxi×P(xi)E(X) = \sum_{i=1}^{n} x_i \times P(x_i)

Example: If a stock has a 30% chance of returning 10%, a 50% chance of returning 5%, and a 20% chance of returning -5%:

  • Expected Return = 0.30 × 10% + 0.50 × 5% + 0.20 × (-5%)
  • Expected Return = 3% + 2.5% - 1% = 4.5%

Variance of Returns: Measures the dispersion of possible returns around the expected return.

σ2=∑i=1nP(xi)×(xi−E(X))2\sigma^2 = \sum_{i=1}^{n} P(x_i) \times (x_i - E(X))^2

Standard Deviation of Returns: The square root of variance. It measures risk - higher standard deviation means higher risk.

Example: Using the stock above (expected return = 4.5%):

  • Variance = 0.30 × (10-4.5)^2 + 0.50 × (5-4.5)^2 + 0.20 × (-5-4.5)^2
  • Variance = 0.30 × 30.25 + 0.50 × 0.25 + 0.20 × 90.25
  • Variance = 9.075 + 0.125 + 18.05 = 27.25
  • Standard Deviation = √27.25 = 5.22%

Python exercise

#| label: expected-value-risk-visualization
#| fig-cap: "Expected Value and Risk: Understanding Return Distributions"
#| fig-width: 14
#| fig-height: 8
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display
from scipy.stats import norm

# Example stock returns
outcomes = np.array([10, 5, -5])  # Returns in %
probabilities = np.array([0.30, 0.50, 0.20])
expected_return = np.sum(outcomes * probabilities)
variance = np.sum(probabilities * (outcomes - expected_return)**2)
std_dev = np.sqrt(variance)

# Create probability distribution visualization
x_continuous = np.linspace(-15, 20, 1000)
# Approximate normal distribution for visualization
normal_approx = norm.pdf(x_continuous, expected_return, std_dev) * max(probabilities) * 2

# Risk-return comparison scenarios
scenarios = ['Stock A\n(Current)', 'Stock B\n(High Risk)', 'Stock C\n(Low Risk)', 'Stock D\n(High Return)']
expected_returns = [4.5, 6.0, 3.0, 8.0]
std_deviations = [5.22, 12.0, 2.0, 15.0]

# Efficient frontier concept
risk_levels = np.linspace(2, 18, 100)
# Simplified efficient frontier: higher risk should offer higher return
efficient_frontier = 2 + 0.4 * risk_levels

fig, axes = plt.subplots(2, 2, figsize=(16, 12))
fig.suptitle('Expected Value and Risk: Understanding Return Distributions', fontsize=16, fontweight='bold')

# Plot 1: Probability Distribution and Expected Value
ax1 = axes[0, 0]
bars = ax1.bar(outcomes, probabilities, color=['green', 'blue', 'red'], alpha=0.7, edgecolor='black', linewidth=1.5, width=2)
ax1.axvline(x=expected_return, color='red', linestyle='--', linewidth=3, alpha=0.8, label=f'Expected Return: {expected_return:.1f}%')
ax1.plot(x_continuous, normal_approx, 'b-', linewidth=2, alpha=0.5, label='Normal Approximation')
ax1.set_xlabel('Return (%)', fontsize=12, fontweight='bold')
ax1.set_ylabel('Probability', fontsize=12, fontweight='bold')
ax1.set_title('Probability Distribution of Returns', fontsize=13, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--', axis='y')
ax1.legend(loc='upper left', fontsize=10)
for bar, prob, outcome in zip(bars, probabilities, outcomes):
    height = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2., height + 0.02,
             f'{prob*100:.0f}%\n{outcome}%', ha='center', va='bottom', fontsize=9, fontweight='bold')

# Plot 2: Variance and Standard Deviation Breakdown
ax2 = axes[0, 1]
deviations = outcomes - expected_return
squared_deviations = deviations**2
weighted_squared = probabilities * squared_deviations
components = ['Outcome 1\n(10%)', 'Outcome 2\n(5%)', 'Outcome 3\n(-5%)']
x_pos = np.arange(len(components))
bars2 = ax2.bar(x_pos, weighted_squared, color=['green', 'blue', 'red'], alpha=0.7, edgecolor='black', linewidth=1.5)
ax2.axhline(y=variance, color='purple', linestyle='--', linewidth=3, alpha=0.8, label=f'Total Variance: {variance:.2f}')
ax2.set_ylabel('Weighted Squared Deviation', fontsize=12, fontweight='bold')
ax2.set_title('Variance Calculation: Weighted Squared Deviations', fontsize=13, fontweight='bold')
ax2.set_xticks(x_pos)
ax2.set_xticklabels(components)
ax2.grid(True, alpha=0.3, linestyle='--', axis='y')
ax2.legend(loc='upper right', fontsize=10)
for bar, val, dev in zip(bars2, weighted_squared, deviations):
    height = bar.get_height()
    ax2.text(bar.get_x() + bar.get_width()/2., height + 0.5,
             f'{val:.2f}\n(dev: {dev:+.1f}%)', ha='center', va='bottom', fontsize=9, fontweight='bold')
ax2.text(0.5, 0.95, f'Standard Deviation: {std_dev:.2f}% = √{variance:.2f}',
         transform=ax2.transAxes, ha='center', va='top', fontsize=11, fontweight='bold',
         bbox=dict(boxstyle='round,pad=0.5', facecolor='yellow', edgecolor='black', linewidth=1.5))

# Plot 3: Risk-Return Scatter
ax3 = axes[1, 0]
colors_scatter = ['blue', 'red', 'green', 'orange']
scatter = ax3.scatter(std_deviations, expected_returns, s=300, c=colors_scatter, alpha=0.7, 
                     edgecolors='black', linewidths=2, zorder=5)
for i, (std, er, label) in enumerate(zip(std_deviations, expected_returns, scenarios)):
    ax3.annotate(label, (std, er), xytext=(5, 5), textcoords='offset points', 
                fontsize=9, fontweight='bold')
ax3.plot(risk_levels, efficient_frontier, 'b--', linewidth=2, alpha=0.5, label='Efficient Frontier (Concept)')
ax3.set_xlabel('Risk (Standard Deviation %)', fontsize=12, fontweight='bold')
ax3.set_ylabel('Expected Return (%)', fontsize=12, fontweight='bold')
ax3.set_title('Risk-Return Trade-off', fontsize=13, fontweight='bold')
ax3.grid(True, alpha=0.3, linestyle='--')
ax3.legend(loc='lower right', fontsize=10)
ax3.text(0.05, 0.95, 'Higher risk → Higher expected return\nLower risk → Lower expected return',
         transform=ax3.transAxes, ha='left', va='top', fontsize=10, fontweight='bold',
         bbox=dict(boxstyle='round,pad=0.5', facecolor='lightblue', edgecolor='blue', linewidth=1.5))

# Plot 4: Return Distribution Comparison
ax4 = axes[1, 1]
x_norm = np.linspace(-20, 20, 1000)
for i, (er, std, label, color) in enumerate(zip(expected_returns, std_deviations, scenarios, colors_scatter)):
    normal_dist = norm.pdf(x_norm, er, std)
    normal_dist = normal_dist / max(normal_dist) * 0.3  # Normalize for visibility
    ax4.plot(x_norm, normal_dist + i*0.35, label=label, color=color, linewidth=2, alpha=0.8)
    ax4.axvline(x=er, color=color, linestyle='--', linewidth=1.5, alpha=0.5)
ax4.set_xlabel('Return (%)', fontsize=12, fontweight='bold')
ax4.set_ylabel('Probability Density (Normalized)', fontsize=12, fontweight='bold')
ax4.set_title('Return Distributions: Different Risk Levels', fontsize=13, fontweight='bold')
ax4.grid(True, alpha=0.3, linestyle='--')
ax4.legend(loc='upper right', fontsize=9)
ax4.set_yticks([])

plt.tight_layout()
display(fig)
plt.close(fig)

Correlation and Covariance

Covariance: Measures how two variables move together.

Cov(X,Y)=E[(X−E(X))×(Y−E(Y))]Cov(X,Y) = E[(X - E(X)) \times (Y - E(Y))]

Or for sample data:

Cov(X,Y)=∑i=1n(xi−xˉ)(yi−yˉ)n−1Cov(X,Y) = \frac{\sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y})}{n-1}

Correlation: A standardized measure of how two variables move together, ranging from -1 to +1.

ρXY=Cov(X,Y)σX×σY\rho_{XY} = \frac{Cov(X,Y)}{\sigma_X \times \sigma_Y}

Interpretation:

  • ρ = +1: Perfect positive correlation (move together perfectly)
  • ρ = 0: No correlation (independent)
  • ρ = -1: Perfect negative correlation (move in opposite directions)

Importance in Finance: Correlation is crucial for portfolio diversification. Lower correlation between assets means better diversification and lower portfolio risk. Understanding correlation helps construct efficient portfolios.

Python exercise

#| label: correlation-covariance-visualization
#| fig-cap: "Correlation and Covariance: Understanding Asset Relationships"
#| fig-width: 14
#| fig-height: 8
#| echo: false
#| warning: false

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display
from scipy.stats import pearsonr

# Generate example data for different correlation scenarios
np.random.seed(42)
n_points = 100

# Positive correlation (0.8)
x1 = np.random.normal(0, 1, n_points)
y1_pos = 0.8 * x1 + np.random.normal(0, 0.6, n_points)
corr_pos = np.corrcoef(x1, y1_pos)[0, 1]

# Negative correlation (-0.7)
y1_neg = -0.7 * x1 + np.random.normal(0, 0.7, n_points)
corr_neg = np.corrcoef(x1, y1_neg)[0, 1]

# No correlation (0.0)
x2 = np.random.normal(0, 1, n_points)
y2 = np.random.normal(0, 1, n_points)
corr_zero = np.corrcoef(x2, y2)[0, 1]

# Strong positive correlation (0.95)
y1_strong = 0.95 * x1 + np.random.normal(0, 0.3, n_points)
corr_strong = np.corrcoef(x1, y1_strong)[0, 1]

# Calculate covariance for each
cov_pos = np.cov(x1, y1_pos)[0, 1]
cov_neg = np.cov(x1, y1_neg)[0, 1]
cov_zero = np.cov(x2, y2)[0, 1]
cov_strong = np.cov(x1, y1_strong)[0, 1]

# Standard deviations
std_x = np.std(x1)
std_y_pos = np.std(y1_pos)
std_y_neg = np.std(y1_neg)
std_y_zero = np.std(y2)
std_y_strong = np.std(y1_strong)

# Portfolio diversification example
returns_a = np.random.normal(8, 15, 100)
returns_b_pos = returns_a * 0.8 + np.random.normal(0, 9, 100)  # High correlation
returns_b_neg = -returns_a * 0.7 + np.random.normal(6, 10, 100)  # Negative correlation
returns_b_zero = np.random.normal(6, 12, 100)  # No correlation

portfolio_pos = 0.5 * returns_a + 0.5 * returns_b_pos
portfolio_neg = 0.5 * returns_a + 0.5 * returns_b_neg
portfolio_zero = 0.5 * returns_a + 0.5 * returns_b_zero

fig, axes = plt.subplots(2, 2, figsize=(16, 12))
fig.suptitle('Correlation and Covariance: Understanding Asset Relationships', fontsize=16, fontweight='bold')

# Plot 1: Positive Correlation
ax1 = axes[0, 0]
ax1.scatter(x1, y1_pos, alpha=0.6, color='green', s=50, edgecolors='black', linewidths=0.5)
z = np.polyfit(x1, y1_pos, 1)
p = np.poly1d(z)
x_line = np.linspace(x1.min(), x1.max(), 100)
ax1.plot(x_line, p(x_line), "r--", linewidth=2, alpha=0.8, label=f'Correlation: {corr_pos:.2f}')
ax1.set_xlabel('Asset X Returns', fontsize=12, fontweight='bold')
ax1.set_ylabel('Asset Y Returns', fontsize=12, fontweight='bold')
ax1.set_title(f'Positive Correlation (ρ = {corr_pos:.2f})', fontsize=13, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--')
ax1.legend(loc='upper left', fontsize=10)
ax1.text(0.05, 0.95, f'Covariance: {cov_pos:.2f}\nAssets move together', 
         transform=ax1.transAxes, ha='left', va='top', fontsize=10, fontweight='bold',
         bbox=dict(boxstyle='round,pad=0.5', facecolor='lightgreen', edgecolor='green', linewidth=1.5))

# Plot 2: Negative Correlation
ax2 = axes[0, 1]
ax2.scatter(x1, y1_neg, alpha=0.6, color='red', s=50, edgecolors='black', linewidths=0.5)
z2 = np.polyfit(x1, y1_neg, 1)
p2 = np.poly1d(z2)
ax2.plot(x_line, p2(x_line), "b--", linewidth=2, alpha=0.8, label=f'Correlation: {corr_neg:.2f}')
ax2.set_xlabel('Asset X Returns', fontsize=12, fontweight='bold')
ax2.set_ylabel('Asset Y Returns', fontsize=12, fontweight='bold')
ax2.set_title(f'Negative Correlation (ρ = {corr_neg:.2f})', fontsize=13, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.legend(loc='upper left', fontsize=10)
ax2.text(0.05, 0.95, f'Covariance: {cov_neg:.2f}\nAssets move oppositely', 
         transform=ax2.transAxes, ha='left', va='top', fontsize=10, fontweight='bold',
         bbox=dict(boxstyle='round,pad=0.5', facecolor='lightcoral', edgecolor='red', linewidth=1.5))

# Plot 3: No Correlation
ax3 = axes[1, 0]
ax3.scatter(x2, y2, alpha=0.6, color='gray', s=50, edgecolors='black', linewidths=0.5)
z3 = np.polyfit(x2, y2, 1)
p3 = np.poly1d(z3)
x_line2 = np.linspace(x2.min(), x2.max(), 100)
ax3.plot(x_line2, p3(x_line2), "orange", linestyle='--', linewidth=2, alpha=0.8, label=f'Correlation: {corr_zero:.2f}')
ax3.set_xlabel('Asset X Returns', fontsize=12, fontweight='bold')
ax3.set_ylabel('Asset Y Returns', fontsize=12, fontweight='bold')
ax3.set_title(f'No Correlation (ρ = {corr_zero:.2f})', fontsize=13, fontweight='bold')
ax3.grid(True, alpha=0.3, linestyle='--')
ax3.legend(loc='upper left', fontsize=10)
ax3.text(0.05, 0.95, f'Covariance: {cov_zero:.2f}\nIndependent assets', 
         transform=ax3.transAxes, ha='left', va='top', fontsize=10, fontweight='bold',
         bbox=dict(boxstyle='round,pad=0.5', facecolor='lightyellow', edgecolor='orange', linewidth=1.5))

# Plot 4: Portfolio Diversification Effect
ax4 = axes[1, 1]
correlations = ['High\nCorrelation\n(ρ=0.8)', 'Negative\nCorrelation\n(ρ=-0.7)', 'No\nCorrelation\n(ρ=0.0)']
portfolio_stds = [np.std(portfolio_pos), np.std(portfolio_neg), np.std(portfolio_zero)]
individual_std = np.std(returns_a)
colors_port = ['red', 'green', 'blue']
bars = ax4.bar(correlations, portfolio_stds, color=colors_port, alpha=0.7, edgecolor='black', linewidth=1.5)
ax4.axhline(y=individual_std, color='orange', linestyle='--', linewidth=2, alpha=0.7, 
            label=f'Individual Asset Risk: {individual_std:.1f}%')
ax4.set_ylabel('Portfolio Standard Deviation (%)', fontsize=12, fontweight='bold')
ax4.set_title('Diversification Effect: Lower Correlation → Lower Portfolio Risk', fontsize=13, fontweight='bold')
ax4.grid(True, alpha=0.3, linestyle='--', axis='y')
ax4.legend(loc='upper right', fontsize=10)
for bar, std in zip(bars, portfolio_stds):
    height = bar.get_height()
    reduction = ((individual_std - height) / individual_std) * 100
    ax4.text(bar.get_x() + bar.get_width()/2., height + 0.5,
             f'{std:.1f}%\n({reduction:+.1f}% vs\nindividual)', ha='center', va='bottom', fontsize=9, fontweight='bold')
ax4.text(0.5, 0.95, 'Lower correlation → Better diversification\n→ Lower portfolio risk',
         transform=ax4.transAxes, ha='center', va='top', fontsize=10, fontweight='bold',
         bbox=dict(boxstyle='round,pad=0.5', facecolor='lightblue', edgecolor='blue', linewidth=1.5))

plt.tight_layout()
display(fig)
plt.close(fig)

Applications in Financial Markets

Statistics and probability are fundamental to financial markets:

Risk Measurement: Standard deviation measures volatility and risk. Value at Risk (VaR) and other risk measures use statistical concepts.

Portfolio Theory: Modern portfolio theory uses expected returns, standard deviations, and correlations to construct optimal portfolios.

Option Pricing: Option pricing models (like Black-Scholes) use probability distributions to value options.

Credit Risk: Probability of default and loss given default are key measures in credit risk assessment.

Performance Evaluation: Sharpe ratio, alpha, beta, and other performance measures use statistical concepts.

Market Analysis: Statistical analysis helps identify patterns, trends, and relationships in market data.

Forecasting: Statistical models are used to forecast prices, returns, and economic variables.

Understanding statistics and probability is essential for understanding risk, making investment decisions, and analyzing financial markets.


In Module 4: Mathematics for Finance

  1. Introduction
  2. Time Value of Money: The Foundation of Finance
  3. Compound Interest: The Power of Exponential Growth
  4. Present Value and Future Value: Valuing Money Across Time
  5. Annuities and Perpetuities
  6. Basic Statistics and Probability: Understanding Uncertainty
  7. Financial Ratios and Percentages: Tools for Analysis
  8. Advanced Financial Mathematics
  9. Mathematical Modeling in Finance
  10. End-of-Module Assessment