Q: The price of one share of stock in the Pilsdorff Beer Company is given by Yn on the nth day of the year. Finn observes that the differences (Xn = Yn+1 - Yn) appear to be independent random variables with a common distribution having mean mu = 0 and variance sqrt(sigma) = 1=4. If Y1 = 100, estimate the probability that Y365 is (a) >= 100. (b) >= 110. (c) >= 120.

A:

We can use the properties of random walks and normal distribution.Given that the \(X_n\) are independent and identically distributed, the stock price at day \(n\), \(Y_n\), is the sum of the initial price \(Y_1\) and the sum of \(n-1\) increments \(X_i\):

\[Y_n = Y_1 + \sum_{i=1}^{n-1} X_i\]

For \(Y_{365}\), this becomes:

\[Y_{365} = 100 + \sum_{i=1}^{364} X_i\]

mu <- 0
daily_variance <- 1/4
days <- 364
total_variance <- days * daily_variance
std_dev <- sqrt(total_variance)

z_score <- function(target_price, initial_price, mean, std_dev) {
  (target_price - initial_price - mean) / std_dev
}

# Z scores for different target prices
z_100 <- z_score(100, 100, mu, std_dev)
z_110 <- z_score(110, 100, mu, std_dev)
z_120 <- z_score(120, 100, mu, std_dev)

# probabilities
prob_100 <- 1 - pnorm(z_100)
prob_110 <- 1 - pnorm(z_110)
prob_120 <- 1 - pnorm(z_120)

prob_100
## [1] 0.5
prob_110
## [1] 0.1472537
prob_120
## [1] 0.01801584

==================================

Q; Calculate the expected value and variance of the binomial distribution using the moment generating function.

A:

A binomial distribution with parameters \(n\) (number of trials) and \(p\) (probability of success in each trial) can be shown as \(B(n, p)\). The moment-generating function for a binomial distribution is given by:

\[ M(t) = [pe^t + (1 - p)]^n \]

The expected value (mean) \(\mu\) and variance \(\sigma^2\) of a binomial distribution can be found by taking the first and second derivatives of the MGF, evaluated at \(t = 0\).

The first derivative of the MGF with respect to \(t\) gives us the expected value:

\[ \mu = M'(0) = \left.\frac{d}{dt}[pe^t + (1 - p)]^n \right|_{t=0} \]

The second derivative of the MGF gives us the second moment about the origin:

\[ E(X^2) = M''(0) \]

The variance is then calculated using the formula:

\[ \sigma^2 = E(X^2) - [E(X)]^2 \]

library(Deriv)

MGF <- function(t) {(p*exp(t) + (1 - p))^n}

# example
n <- 10
p <- 0.5

# the first derivative of the MGF with respect to t
first_deriv <- Deriv(MGF, 't')

# the expected value by evaluating the first derivative at t=0
expected_value <- first_deriv(t = 0)

# the second derivative of the MGF with respect to t
second_deriv <- Deriv(first_deriv, 't')

# the second moment about the origin by evaluating the second derivative at t=0
second_moment <- second_deriv(t = 0)

variance <- second_moment - expected_value^2


cat("Expected Value (Mean):", expected_value, "\n")
## Expected Value (Mean): 5
cat("Variance:", variance, "\n")
## Variance: 2.5

=============================================

Q: Calculate the expected value and variance of the exponential distribution using the moment generating function.

A:

The expected value \(\mu\) and variance \(\sigma^2\) of the exponential distribution, derived from the moment-generating function, are as follows:

These results align with the well-known properties of the exponential distribution, where the rate parameter \(\lambda\) inversely determines both the mean and the variance of the distribution.

# rate parameter of the exponential distribution (example)
lambda <- 1  

# the expected value (mean)
expected_value <- 1 / lambda

# variance
variance <- 1 / (lambda^2)

cat("Expected Value (Mean):", expected_value, "\n")
## Expected Value (Mean): 1
cat("Variance:", variance, "\n")
## Variance: 1