1. Given the following observations on X:

X: 14, 20, 18, 10, 8, 14, 16, 17, 9, 16, 16, 22, 20, 25, 15

# Given data
X <- c(14, 20, 18, 10, 8, 14, 16, 17, 9, 16, 16, 22, 20, 25, 15)

# a. Sample mean
sample_mean <- mean(X)

# b. Sample variance
sample_variance <- var(X)

# c. Sample standard deviation
sample_sd <- sd(X)

# d. Population mean (same as sample mean in this context)
population_mean <- sample_mean

# e. Population variance (adjusting the variance for population formula)
population_variance <- sample_variance

# f. Population standard deviation
population_sd <- sample_sd

# g. Standard deviation of the sample mean
sd_sample_mean <- sample_sd / sqrt(length(X))

# h. Variance of the sample mean
var_sample_mean <- var(X) / length(X)

# Output the results
list(
  a_sample_mean = sample_mean,
  b_sample_variance = sample_variance,
  c_sample_sd = sample_sd,
  d_population_mean = population_mean,
  e_population_variance = population_variance,
  f_population_sd = population_sd,
  g_sd_sample_mean = sd_sample_mean,
  h_var_sample_mean = var_sample_mean
)
## $a_sample_mean
## [1] 16
## 
## $b_sample_variance
## [1] 22.28571
## 
## $c_sample_sd
## [1] 4.720775
## 
## $d_population_mean
## [1] 16
## 
## $e_population_variance
## [1] 22.28571
## 
## $f_population_sd
## [1] 4.720775
## 
## $g_sd_sample_mean
## [1] 1.218899
## 
## $h_var_sample_mean
## [1] 1.485714

  1. A financial analyst is testing the performance of two portfolios where the end of the year index on each portfolio for the past nine years are indexed as follows: (Note: For each question you are required to define your hypothesis clearly, find the relevant statistics, and express, statistically, what your conclusions are.)
# Given portfolio data
portfolio_A <- c(123.5, 121.3, 106.5, 102.8, 118.9, 129.6, 137.9, 142.9, 153.7)
portfolio_B <- c(108.6, 101.4, 93.8, 101.9, 112.0, 119.6, 128.7, 139.5, 145.8)
T_bill_rate <- 2.6 / 100  # T-Bill rate as a decimal

# Function to calculate simple returns
calc_simple_returns <- function(index_values) {
  return(diff(index_values) / index_values[-length(index_values)])
}

# Calculate simple returns for both portfolios
simple_returns_A <- calc_simple_returns(portfolio_A)
simple_returns_B <- calc_simple_returns(portfolio_B)

# Calculate the mean simple return for both portfolios
mean_simple_return_A <- mean(simple_returns_A)
mean_simple_return_B <- mean(simple_returns_B)

# a. Test if the mean return for portfolio A is no different from T-Bill rate
# Compare the vector of simple returns for portfolio A with the T-Bill rate
t_test_A <- t.test(simple_returns_A, mu = T_bill_rate)

# b. Test if the mean return for portfolio B is no different from T-Bill rate
t_test_B <- t.test(simple_returns_B, mu = T_bill_rate)

# c. Test if the mean simple returns of portfolios A and B are statistically different
t_test_A_vs_B <- t.test(simple_returns_A, simple_returns_B)

# d. Test if the variances of the two portfolios (risk) are not statistically different
var_test <- var.test(simple_returns_A, simple_returns_B)

# e. Test if portfolio A has higher performance (mean simple return) than portfolio B (one-tailed test)
t_test_one_sided <- t.test(simple_returns_A, simple_returns_B, alternative = "greater")

# Output the results
list(
  mean_simple_return_A = mean_simple_return_A,
  mean_simple_return_B = mean_simple_return_B,
  a_t_test_A_vs_T_bill = t_test_A,
  b_t_test_B_vs_T_bill = t_test_B,
  c_t_test_A_vs_B = t_test_A_vs_B,
  d_var_test_A_vs_B = var_test,
  e_one_sided_t_test_A_vs_B = t_test_one_sided
)
## $mean_simple_return_A
## [1] 0.03098975
## 
## $mean_simple_return_B
## [1] 0.0396554
## 
## $a_t_test_A_vs_T_bill
## 
##  One Sample t-test
## 
## data:  simple_returns_A
## t = 0.16299, df = 7, p-value = 0.8751
## alternative hypothesis: true mean is not equal to 0.026
## 95 percent confidence interval:
##  -0.04140008  0.10337957
## sample estimates:
##  mean of x 
## 0.03098975 
## 
## 
## $b_t_test_B_vs_T_bill
## 
##  One Sample t-test
## 
## data:  simple_returns_B
## t = 0.55266, df = 7, p-value = 0.5977
## alternative hypothesis: true mean is not equal to 0.026
## 95 percent confidence interval:
##  -0.01877137  0.09808216
## sample estimates:
## mean of x 
## 0.0396554 
## 
## 
## $c_t_test_A_vs_B
## 
##  Welch Two Sample t-test
## 
## data:  simple_returns_A and simple_returns_B
## t = -0.22027, df = 13.403, p-value = 0.829
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.09339778  0.07606649
## sample estimates:
##  mean of x  mean of y 
## 0.03098975 0.03965540 
## 
## 
## $d_var_test_A_vs_B
## 
##  F test to compare two variances
## 
## data:  simple_returns_A and simple_returns_B
## F = 1.5351, num df = 7, denom df = 7, p-value = 0.5857
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  0.3073292 7.6675917
## sample estimates:
## ratio of variances 
##           1.535081 
## 
## 
## $e_one_sided_t_test_A_vs_B
## 
##  Welch Two Sample t-test
## 
## data:  simple_returns_A and simple_returns_B
## t = -0.22027, df = 13.403, p-value = 0.5855
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
##  -0.07817618         Inf
## sample estimates:
##  mean of x  mean of y 
## 0.03098975 0.03965540

A. Accept the null/fail to reject; no different than T-bill at alpha = .05

B. Accept the null/fail to reject; no different than T-bill at alpha = .05

C. Accept the null/fail to reject; no different from each other at alpha = .05

D. Accept the null/fail to reject; variances of returns are not different at alpha = .05

E. Accept the null/fail to reject; cannot conclude higher performance at alpha = .05

I do not agree with the analyst’s claim that portfolio A has higher performance than portfolio B. The p value for this test is .59, so we accept the null hypothesis that the mean difference is not greater than 0.


  1. Given the distribution of the following variable (X), find the mean, E(X), and the variance V(X) of the variable X.
# Given data
X <- c(10, 6, 5, 8, 3, 4, 4.5)
P <- c(0.1, 0.15, 0.3, 0.2, 0.05, 0.1, 0.1)

# a. E(X): Calculate the expected value of X
E_X <- sum(X * P)
cat("a. E(X) = ", E_X, "\n")  # Outputs the mean E(X)
## a. E(X) =  6
# What does E(X) represent?
cat("E(X) represents the mean (expected value) of the variable X.\n\n")
## E(X) represents the mean (expected value) of the variable X.
# b. V(X): Calculate the variance of X
E_X2 <- sum((X^2) * P)
V_X <- E_X2 - (E_X^2)
cat("b. V(X) = ", V_X, "\n")  # Outputs the variance V(X)
## b. V(X) =  3.775
# What does V(X) represent?
cat("V(X) represents the variance, which is the measure of spread or dispersion of X from its mean.\n\n")
## V(X) represents the variance, which is the measure of spread or dispersion of X from its mean.
# c. Given data for Y and E(XY)
E_Y <- 5
V_Y <- 82
E_XY <- 15.2

# d. E(Z) where Z = 10X + 3Y
E_Z <- 10 * E_X + 3 * E_Y
cat("d. E(Z) = ", E_Z, "\n")  # Outputs E(Z)
## d. E(Z) =  75
# e. V(Z) where Z = 10X + 3Y
Cov_XY <- E_XY - (E_X * E_Y)
V_Z <- (10^2 * V_X) + (3^2 * V_Y) + 2 * 10 * 3 * Cov_XY
cat("e. V(Z) = ", V_Z, "\n")  # Outputs V(Z)
## e. V(Z) =  227.5
# f. Covariance of X and Y
cat("f. Cov(X, Y) = ", Cov_XY, "\n")  # Outputs Covariance Cov(X, Y)
## f. Cov(X, Y) =  -14.8
# g. Correlation coefficient between X and Y
Corr_XY <- Cov_XY / (sqrt(V_X * V_Y))
cat("g. Corr(X, Y) = ", Corr_XY, "\n")  # Outputs Correlation coefficient Corr(X, Y)
## g. Corr(X, Y) =  -0.8411943

  1. Given that E(X) = 5, E(Y) = 8, E(X2) = 68, E(Y2) = 75 and rx,y = .35, find the followings.
# Given data
E_X <- 5
E_Y <- 8
E_X2 <- 68
E_Y2 <- 75
r_xy <- 0.35  # Correlation coefficient

# a. Find V(X)
V_X <- E_X2 - E_X^2
cat("a. V(X) =", V_X, "\n")
## a. V(X) = 43
# b. Find V(Y)
V_Y <- E_Y2 - E_Y^2
cat("b. V(Y) =", V_Y, "\n")
## b. V(Y) = 11
# c. Find E(5 + 3X)
E_5_3X <- 5 + 3 * E_X
cat("c. E(5 + 3X) =", E_5_3X, "\n")
## c. E(5 + 3X) = 20
# d. Find E(2X - 2Y)
E_2X_2Y <- 2 * E_X - 2 * E_Y
cat("d. E(2X - 2Y) =", E_2X_2Y, "\n")
## d. E(2X - 2Y) = -6
# e. Find E(5XY)
E_5XY <- 5 * E_X * E_Y
cat("e. E(5XY) =", E_5XY, "\n")
## e. E(5XY) = 200
# f. Find E(3X^2)
E_3X2 <- 3 * E_X2
cat("f. E(3X^2) =", E_3X2, "\n")
## f. E(3X^2) = 204
# g. Find V(2 + 4Y)
V_2_4Y <- 4^2 * V_Y
cat("g. V(2 + 4Y) =", V_2_4Y, "\n")
## g. V(2 + 4Y) = 176
# h. Find V(5X - 2Y)
Cov_XY <- r_xy * sqrt(V_X * V_Y)
V_5X_2Y <- 5^2 * V_X + (-2)^2 * V_Y + 2 * 5 * (-2) * Cov_XY
cat("h. V(5X - 2Y) =", V_5X_2Y, "\n")
## h. V(5X - 2Y) = 966.7601
# i. Find V(X * Y) 
print("Not possible with given info")
## [1] "Not possible with given info"
# j. Find Cov(X,Y)
Cov_XY <- r_xy * sqrt(V_X * V_Y)
cat("j. Cov(X,Y) =", Cov_XY, "\n")
## j. Cov(X,Y) = 7.611997