CS代考 # Hypothesis Testing

# Hypothesis Testing
# Null Hypothesis: mean = 5%; Alt hypothesis: mean not = 5%
# set.seed(100)
T <- 60; mu <- 0.05; sigma <- 0.10; Copyright By PowCoder代写 加微信 powcoder

ret <- mu + rnorm(T, sd = sigma) # Estimate for return: muHat <- mean(ret) # z-score: z.score <- (muHat - 0.05) / (sigma / sqrt(T)) # Null Hypothesis: mean = 6%; Alt hypothesis: mean not = 6% z.score <- (muHat - 0.06) / (sigma / sqrt(T)) # Null Hypothesis: mean = 10%; Alt hypothesis: mean not = 10% z.score <- (muHat - 0.10) / (sigma / sqrt(T)) # one-sided test threshold for z-statistic qnorm(0.95) # one-sided test ret <- mu + rnorm(T, sd = sigma) # Estimate for return: muHat <- mean(ret) # z-score: z.score <- (muHat - 0.05) / (sigma / sqrt(T)) # p-value example: ret <- mu + rnorm(T, sd = sigma) # Estimate for return: muHat <- mean(ret) # z-score: z.score <- (muHat - 0.05) / (sigma / sqrt(T)) pnorm(-0.656) # threshold values for t-distribution with T = 60 and alpha = 5%: qt(c(0.025, 0.975), 59) # 2-sided hypothesis testing for standard deviation ret <- mu + rnorm(T, sd = sigma) sigma.hat <- sd(ret) seHat <- sigma.hat / sqrt(2*T) #2 z.score <- (sigma.hat - 0.10) / seHat #3 # threshold values for alpha = 4.5% qnorm(0.0225) # p value from z.score pnorm(z.score) * 2 # H0: mu_MSFT = mu_SBUX; H1: mu_MSFT not= mu_SBUX library(quantmod) getSymbols(c('MSFT','SBUX'), from = '2007-01-01', to = '2021-12-31') MSFT <- Ad(MSFT); SBUX <- Ad(SBUX) # keep only adjusted closing price r.m <- monthlyReturn(MSFT, type = 'log'); r.s <- monthlyReturn(SBUX, type = 'log') # calculate monthly ret # difference in sample means: deltaHat <- mean(r.m) - mean(r.s) # estimated standard error for deltaHat T <- nrow(r.m) seHat.deltaHat <- sqrt(var(r.m)/T + var(r.s)/T - 2*cov(r.m, r.s)/T) seHat.deltaHat # calculate the z-statistic z.score <- deltaHat / seHat.deltaHat # test: H0: correlation = 0.5; H1: correlation not= 0.5 rhoHat <- cor(r.m, r.s) # estimated standard error: seHat.rhoHat <- (1 - rhoHat^2) / sqrt(T) seHat.rhoHat # threshold values with alpha = 8% qnorm(c(0.04, 0.96)) # z-score: z.score <- (rhoHat - 0.5) / seHat.rhoHat # check for normality of returns # using histogram hist(r.m, freq = FALSE, main = 'Monthly Returns', breaks = 15, col = 'hotpink') curve(dnorm(x, mean(r.m), sd(r.m)), -0.25, 0.25, add = TRUE, lwd = 2) # using qqplot qqnorm(r.s, col = 'hotpink') qqline(r.s) # threshold values for jb-statistic with alpha = 5% qchisq(0.999, 2) # JB Test for normality library(PerformanceAnalytics) skewHat <- skewness(r.s) ekurtHat <- kurtosis(r.s) T <- nrow(r.s) JB <- T * (skewHat^2 / 6 + ekurtHat^2 / 24) 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com