11: The price of one share of stock in the Pilsdorff Beer Company (see Exercise 8.2.12) 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 µ = 0 and variance σ

2 = 1/4. If Y1 = 100, estimate the probability that Y365 is ### (a) ≥ 100. ### (b) ≥ 110. ### (c) ≥ 120.

mu <- 0  
variance <- 1/4 
sigma <- sqrt(variance) 
Y1 <- 100  

estimate_probability <- function(Y, threshold) {
  z <- (threshold - Y) / sigma  
  probability <- 1 - pnorm(z, mean = mu, sd = sigma)  
  return(probability)
}

probability_a <- estimate_probability(Y1, 100)
cat("Probability that Y365 is ≥ 100:", probability_a, "\n")
## Probability that Y365 is ≥ 100: 0.5

(b) Estimate probability that Y365 is ≥ 110

probability_b <- estimate_probability(Y1, 110)
cat("Probability that Y365 is ≥ 110:", probability_b, "\n")
## Probability that Y365 is ≥ 110: 0

(c) Estimate probability that Y365 is ≥ 120

probability_c <- estimate_probability(Y1, 120)
cat("Probability that Y365 is ≥ 120:", probability_c, "\n")
## Probability that Y365 is ≥ 120: 0

2: . Calculate the expected value and variance of the binomial distribution using the moment generating function.

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

expected_value_binomial <- function(n, p) {
  d_MGF <- D(expression((1 - p + p * exp(t))^n), "t")
  eval(d_MGF, list(t = 0))
}

variance_binomial <- function(n, p) {
  d2_MGF <- D(D(expression((1 - p + p * exp(t))^n), "t"), "t")
  d_MGF <- D(expression((1 - p + p * exp(t))^n), "t")
  eval(d2_MGF, list(t = 0)) - eval(d_MGF, list(t = 0))^2
}


n <- 10 
p <- 0.5 

mean_binomial <- expected_value_binomial(n, p)
variance_binomial <- variance_binomial(n, p)

cat("Expected value (mean) of the binomial distribution using MGF:", mean_binomial, "\n")
## Expected value (mean) of the binomial distribution using MGF: 5
cat("Variance of the binomial distribution using MGF:", variance_binomial, "\n")
## Variance of the binomial distribution using MGF: 2.5

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

lambda <- 2


MGF_exponential <- function(t, lambda) {
  lambda / (lambda - t)
}


expected_value_exponential <- function(lambda) {
  MGF_derivative <- -lambda / (lambda - 0)^2  
  MGF_derivative
}

variance_exponential <- function(lambda) {
  MGF_second_derivative <- 2 * lambda^2 / (lambda - 0)^3  
  MGF_second_derivative
}

mean_exponential <- expected_value_exponential(lambda)
variance_exponential <- variance_exponential(lambda)

cat("Expected value (mean) of the exponential distribution using MGF:", mean_exponential, "\n")
## Expected value (mean) of the exponential distribution using MGF: -0.5
cat("Variance of the exponential distribution using MGF:", variance_exponential, "\n")
## Variance of the exponential distribution using MGF: 1