Mathematical Statistics

Functions of Random Variables: Introduction and Distribution Functions

Samir Orujov, PhD

ADA University, School of Business

Information Communication Technologies Agency, Statistics Unit

2026-02-22

🎯 Learning Objectives

πŸ“š By the end of this lecture, you will be able to:

  • Identify and formulate functions of random variables in financial contexts such as portfolio returns, option payoffs, and risk metrics

  • Compute probability distributions of discrete transformations using the probability function method for financial applications

  • Apply the method of distribution functions to derive probability distributions of transformed continuous random variables

  • Calculate probabilities for derived distributions such as sums, differences, and ratios of stock returns using CDFs

  • Implement statistical transformations in R to analyze real financial data and validate theoretical distributions

πŸ“± Attendance Check-in

πŸ“‹ Overview

πŸ“š Topics Covered Today

  • Why Functions of Random Variables? – Motivation from portfolio theory, derivatives pricing, and risk management

  • Finding Probability Distributions – Techniques for deriving distributions of transformations

  • Method of Distribution Functions – Using CDFs to find distributions of \(U = g(Y)\) for continuous random variables

  • Financial Applications – Portfolio returns, option payoffs, profit/loss distributions

  • Case Study – Analyzing transformed stock returns using real market data

πŸ“– Why Study Functions of Random Variables?

🎯 Motivation

In finance and economics, we constantly work with transformations of random variables:

Portfolio & Investment:

  • Portfolio return = weighted sum of individual stock returns
  • Profit/Loss = Stock price - Purchase price
  • Return on investment = (Final - Initial) / Initial
  • Option payoffs = max(S - K, 0)

Risk Management:

  • Value at Risk (VaR) transformations
  • Portfolio variance from covariances
  • Credit ratings from default probabilities
  • Exchange rate conversions

πŸ’‘ Real-World Example

Scenario: You invest in a stock with uncertain return \(Y\) (in %). Your initial investment is $10,000.

Your profit is a function of the return: \[U = 10000 \times \frac{Y}{100}\]

Important

Question: If we know the probability distribution of \(Y\) (the return), how do we find the probability distribution of \(U\) (the profit)?

This is the central problem:

Given:

  • Random variable \(Y\)
  • Function \(U = g(Y)\)
  • Distribution of \(Y\)

Find:

  • Distribution of \(U\)

πŸ“– Key Problem Statement

🎯 Central Question of Chapter 6

Given:

  1. Random variable(s): \(Y\) or \((Y_1, Y_2, \ldots, Y_n)\)
  2. A function: \(U = g(Y)\) or \(U = g(Y_1, Y_2, \ldots, Y_n)\)
  3. The probability distribution of \(Y\) (or joint distribution)

Find: The probability distribution of \(U = g(Y)\)

Why does this matter?

  • Statistical inference often requires knowing distributions of sample statistics (e.g., \(\bar{Y}\), \(S^2\))
  • Financial models require distributions of derived quantities (portfolio returns, option values)
  • Risk management needs distributions of transformed variables (VaR, profit/loss)

πŸ” Example 6.1: Profit from Investment (Discrete)

Problem: A stock’s return \(Y\) (in $) has the following probability distribution:

\(y\) -2 -1 0 1 2
\(p(y)\) 0.10 0.20 0.30 0.25 0.15

You bought 1 share for $50. Your profit is: \[U = Y - 5 \text{ (subtracting transaction cost)}\]

Find: The probability distribution of \(U\).

Solution:

For each value of \(y\), compute \(u = y - 5\):

\(y\) \(u = y-5\) \(p(u)\)
-2 -7 0.10
-1 -6 0.20
0 -5 0.30
1 -4 0.25
2 -3 0.15

Tip

The probabilities remain the same! Only the values shift.

πŸ“Š Visualizing the Transformation

πŸ“– General Approach for Discrete RVs

πŸ“ Method for Discrete Transformations

Given: Discrete random variable \(Y\) with probability function \(p_Y(y)\)

Let: \(U = g(Y)\) be a transformation

Steps to find \(p_U(u)\):

  1. List all possible values of \(Y\): \(y_1, y_2, \ldots\)

  2. Compute corresponding values of \(U\): \(u_i = g(y_i)\)

  3. For each unique value \(u\), find all \(y\) values that map to it

  4. Sum probabilities: \(p_U(u) = \sum_{y: g(y)=u} p_Y(y)\)

πŸ” Example 6.2: Non-One-to-One Function

Problem: Stock return \(Y\) has distribution:

\(y\) -2 -1 0 1 2
\(p(y)\) 0.10 0.20 0.30 0.25 0.15

Define absolute return: \[U = |Y|^2\]

Find \(p_U(u)\).

Mapping: Multiple \(y\) values map to same \(u\):

\(y\) \(u = y^2\) \(p_Y(y)\)
-2 4 0.10
-1 1 0.20
0 0 0.30
1 1 0.25
2 4 0.15

Solution: Combine probabilities for same \(u\):

\(u\) \(p_U(u)\)
0 0.30
1 0.45
4 0.25

Tip

\(p_U(1) = p_Y(-1) + p_Y(1)\)

\(= 0.20 + 0.25 = 0.45\)

πŸ“– Method of Distribution Functions (Continuous)

πŸ”§ Method of Distribution Functions

For continuous random variables, we use CDFs to find distributions:

Given:

  • Continuous RV \(Y\) with pdf \(f_Y(y)\) and CDF \(F_Y(y)\)
  • Transformation \(U = g(Y)\)

Steps:

  1. Find CDF of \(U\): \(F_U(u) = P(U \leq u) = P(g(Y) \leq u)\)

  2. Convert to inequality in \(Y\): \(P(Y \in A_u)\) where \(A_u = \{y: g(y) \leq u\}\)

  3. Differentiate to get pdf: \(f_U(u) = \frac{d}{du}F_U(u)\)

πŸ” Example 6.3: Linear Transformation

Problem: Daily stock return \(Y \sim \text{Uniform}(0, 1)\), so \(f_Y(y) = 1\) for \(0 \leq y \leq 1\).

An investor scales and shifts the return: \(U = 2Y + 1\)

Find: The pdf of \(U\).

Solution:

  1. Find support of U: Since \(0 \leq Y \leq 1\), then \(1 \leq U \leq 3\)

  2. Find CDF: For \(1 \leq u \leq 3\): \[F_U(u) = P(U \leq u) = P(2Y + 1 \leq u) \] \[ = P\left(Y \leq \frac{u-1}{2}\right) = F_Y\left(\frac{u-1}{2}\right)\]

Solution (continued):

  1. Since \(Y \sim \text{Uniform}(0,1)\): \(F_Y(y) = y\), so \(F_U(u) = \frac{u-1}{2}\)

  2. Differentiate: \[f_U(u) = \frac{d}{du}\left(\frac{u-1}{2}\right) = \frac{1}{2}, \quad 1 \leq u \leq 3\]

Tip

\(U \sim \text{Uniform}(1, 3)\) β€” Linear transformation of uniform is uniform!

πŸ“Š Interactive: Linear Transformation of Uniform

πŸ” Example 6.4: Nonlinear Transformation

Problem: Stock return \(Y \sim \text{Uniform}(0, 1)\).

Define squared return: \(U = Y^2\)

Find: The pdf of \(U\).

Solution:

  1. Support: If \(0 \leq Y \leq 1\), then \(0 \leq U \leq 1\)

  2. CDF: For \(0 \leq u \leq 1\): \[F_U(u) = P(U \leq u) = P(Y^2 \leq u) \] \[= P(Y \leq \sqrt{u}) = \sqrt{u}\]

Solution (continued):

  1. PDF: Differentiate: \[f_U(u) = \frac{d}{du}(\sqrt{u}) = \frac{1}{2\sqrt{u}}, \quad 0 < u < 1\]

Warning

Note: The density goes to infinity as \(u \to 0^+\)! This is valid because \(\int_0^1 \frac{1}{2\sqrt{u}} du = 1\).

πŸ“Š Comparing Linear vs Nonlinear Transformations

Tip

Key Insight:

  • Linear: Preserves uniform shape
  • Quadratic: Density β†’ ∞ as u β†’ 0
  • Cubic: Higher concentration near 0
  • Square Root: Linear increase in density

πŸ’Ό Think-Pair-Share: Portfolio Returns

πŸ“‹ Scenario

You invest in two stocks:

  • Stock A: \(Y_A \sim \text{Normal}(\mu_A = 0.08, \sigma_A = 0.15)\)
  • Stock B: \(Y_B \sim \text{Normal}(\mu_B = 0.12, \sigma_B = 0.20)\)

You allocate 60% to A and 40% to B.

Portfolio return: \[U = 0.6 Y_A + 0.4 Y_B\]

❓ Discussion Questions

1. What method would you use to find the distribution of \(U\)?

2. If \(Y_A\) and \(Y_B\) are independent, what is the distribution of \(U\)?

3. How would correlation between \(Y_A\) and \(Y_B\) affect your answer?

⏱️ Discuss with your neighbor for 5 minutes

πŸ“Š Case Study: Demonstrating YΒ² Transformation

πŸ’Ό Visualizing the Quadratic Transformation

Key Learning: When \(Y \sim \text{Uniform}(0,1)\) and \(U = Y^2\), we expect:

\[f_U(u) = \frac{1}{2\sqrt{u}}\]

Let’s verify this with simulation!

Method: - Generate 10,000 samples from Uniform(0,1) - Transform to \(U = Y^2\) - Compare empirical histogram to theoretical density

πŸ“Š Show Code
library(tidyverse)

# Generate samples from Uniform(0,1)
set.seed(123)
n <- 10000
y_samples <- runif(n, 0, 1)
u_samples <- y_samples^2

# Theoretical density for U = YΒ²
u_seq <- seq(0.01, 1, length.out = 200)
f_u_theoretical <- 1 / (2 * sqrt(u_seq))

# Create comparison plot
ggplot() +
  # Empirical histogram
  geom_histogram(aes(x = u_samples, y = after_stat(density)), 
                 bins = 50, fill = "darkred", alpha = 0.5, color = "white") +
  # Theoretical density
  geom_line(aes(x = u_seq, y = f_u_theoretical), 
            color = "blue", linewidth = 2) +
  # Annotations
  annotate("text", x = 0.7, y = 3, 
           label = "Theoretical: f[U](u)==frac(1,2*sqrt(u))",
           parse = TRUE, size = 6, color = "blue") +
  annotate("text", x = 0.7, y = 2.5, 
           label = "Empirical: 10,000 samples",
           size = 5, color = "darkred") +
  labs(title = "Transformation U = YΒ² where Y ~ Uniform(0,1)",
       subtitle = "Notice: Density β†’ ∞ as u β†’ 0, matching our theoretical result!",
       x = "u = yΒ²", y = "Density f_U(u)") +
  theme_minimal(base_size = 16) +
  coord_cartesian(ylim = c(0, 4))

πŸ“Š Case Study: Real Stock Portfolio Transformation

πŸ’Ό Linear Transformation of Stock Returns

Scenario: Portfolio with: - 60% Apple (AAPL) - 40% Microsoft (MSFT) - Monthly data: 2020-2024

Transformation: \[R_p = 0.6 \cdot R_{AAPL} + 0.4 \cdot R_{MSFT}\]

Key Question: How does the portfolio return distribution compare to individual stocks?

πŸ“Š Show Code
library(tidyverse)
library(tidyquant)

# Download monthly returns for AAPL and MSFT (2020-2024)
stocks <- c("AAPL", "MSFT")
prices <- tq_get(stocks, 
                 from = "2020-01-01", 
                 to = "2024-12-31",
                 get = "stock.prices")

# Calculate monthly returns
returns <- prices %>%
  group_by(symbol) %>%
  tq_transmute(select = adjusted,
               mutate_fun = periodReturn,
               period = "monthly",
               col_rename = "ret")

# Pivot to wide format
returns_wide <- returns %>%
  pivot_wider(names_from = symbol, values_from = ret) %>%
  drop_na()

# Create portfolio returns (60% AAPL, 40% MSFT)
returns_wide <- returns_wide %>%
  mutate(Portfolio = 0.6 * AAPL + 0.4 * MSFT)

# Plot distributions
returns_wide %>%
  select(date, AAPL, MSFT, Portfolio) %>%
  pivot_longer(-date, names_to = "Asset", values_to = "Return") %>%
  ggplot(aes(x = Return, fill = Asset, color = Asset)) +
  geom_density(alpha = 0.4, linewidth = 1.2) +
  scale_fill_manual(values = c("AAPL" = "#3498db", 
                                "MSFT" = "#e74c3c", 
                                "Portfolio" = "#2ecc71")) +
  scale_color_manual(values = c("AAPL" = "#2980b9", 
                                 "MSFT" = "#c0392b", 
                                 "Portfolio" = "#27ae60")) +
  labs(title = "Distribution of Monthly Returns (2020-2024)",
       subtitle = "Portfolio = 60% AAPL + 40% MSFT",
       x = "Monthly Return", y = "Density") +
  theme_minimal(base_size = 14) +
  theme(legend.position = "top")

πŸ“Š Case Study: Portfolio Statistics

πŸ“Š Show Code
library(knitr)

# Calculate summary statistics
stats <- returns_wide %>%
  summarise(
    across(c(AAPL, MSFT, Portfolio),
           list(
             Mean = ~mean(., na.rm = TRUE) * 12 * 100,  # Annualized %
             SD = ~sd(., na.rm = TRUE) * sqrt(12) * 100,  # Annualized %
             Sharpe = ~(mean(., na.rm = TRUE) / sd(., na.rm = TRUE)) * sqrt(12)
           ),
           .names = "{.col}_{.fn}"
    )
  ) %>%
  pivot_longer(everything(), 
               names_to = c("Asset", ".value"),
               names_pattern = "(.*)_(.*)") %>%
  mutate(across(where(is.numeric), ~round(., 2)))

kable(stats, caption = "Annualized Statistics: AAPL, MSFT, and 60/40 Portfolio")
Annualized Statistics: AAPL, MSFT, and 60/40 Portfolio
Asset Mean SD Sharpe
AAPL 29.12 28.93 1.01
MSFT 22.91 22.31 1.03
Portfolio 26.64 24.38 1.09

πŸ”‘ Key Insights

Linear Transformation Property:

  • Portfolio return is a weighted sum of individual returns
  • \(E[R_p] = 0.6 \cdot E[R_{AAPL}] + 0.4 \cdot E[R_{MSFT}]\) (linearity!)
  • Portfolio volatility depends on correlation between stocks
  • Diversification benefit: Portfolio SD typically lower than weighted average of individual SDs

πŸ“ Quiz #1: Linear Transformations

A stock return Y follows a Uniform(0, 2) distribution. You transform it to U = 3Y + 1. What is the distribution of U?

  • Uniform(0, 6)
  • Uniform(1, 7)
  • Uniform(3, 7)
  • Normal(4, 1)

πŸ“ Quiz #2: Quadratic Transformation

If \(Y \sim \text{Uniform}(0, 1)\) and \(U = Y^2\), what is \(f_U(0.25)\)?

  • 0.25
  • 0.5
  • 1.0
  • 2.0

πŸ“ Quiz #3: Distribution Function Method

Why do we use the method of distribution functions for continuous RVs instead of directly transforming the pdf?

  • It’s computationally faster
  • The CDF method properly accounts for the change in probability measure
  • PDFs cannot be transformed
  • It gives the same result either way

πŸ“ Quiz #4: Non-One-to-One Functions

For discrete RV Y with transformation U = g(Y), if g is not one-to-one, what do we do?

  • The transformation is invalid
  • We must use a different method
  • Sum probabilities of all y values that map to each u
  • The pdf becomes undefined

πŸ“š Summary

Key Takeaways:

  • Functions of random variables are ubiquitous in finance: portfolio returns, option payoffs, risk metrics

  • Discrete case: Transform values and preserve/sum probabilities

  • Continuous case: Use the method of distribution functions (CDF approach)

  • Linear transformations preserve distributional families (e.g., uniform β†’ uniform, normal β†’ normal)

  • Nonlinear transformations can dramatically change the shape of distributions

  • Real data often requires empirical validation of theoretical distributions

πŸ“ Practice Problems

Problem 1:

If \(Y \sim \text{Exponential}(\lambda = 0.5)\) and \(U = 2Y\), find \(f_U(u)\).

Problem 2:

Stock return \(Y \sim \text{Normal}(0.10, 0.04)\). An option payoff is \(U = \max(Y - 0.08, 0)\). Describe how you would find \(F_U(u)\).

Problem 3:

Two stocks have returns \(Y_1\) and \(Y_2\). Portfolio return is \(U = 0.5Y_1 + 0.5Y_2\). If both are independent Uniform(0, 1), find \(f_U(u)\).

Problem 4:

Prove that if \(Y \sim \text{Uniform}(a, b)\) and \(U = cY + d\) (with \(c > 0\)), then \(U \sim \text{Uniform}(ca + d, cb + d)\).

πŸ“± Late Check-in

πŸ‘‹ Thank You!

πŸ“¬ Contact Information:

Samir Orujov, PhD

Assistant Professor

School of Business

ADA University

πŸ“§ Email: sorujov@ada.edu.az

🏒 Office: D312

⏰ Office Hours: By appointment

πŸ“… Next Class:

Topic: Method of Transformations (Theorem 6.2)

Reading: Wackerly Sections 6.4-6.5

Preparation: Review derivatives and inverse functions

⏰ Reminders:

βœ… Complete Practice Problems 1-4

βœ… Review the chain rule from calculus

βœ… Think about when transformations are invertible

βœ… Work hard!

❓ Questions?

πŸ’¬ Open Discussion

Key Topics for Discussion:

  • Why is the distribution function method considered the most general approach?

  • How do fat tails in return distributions affect risk management decisions?

  • What are some other financial quantities that are functions of random variables?

  • When might we prefer simple returns over log returns?

  • In practice, when would you use empirical methods vs theoretical transformation methods?