beta_hat <- 0.98
se_beta <- 0.17
t_crit <- 1.98
# H0: beta = 0
t_beta0 <- (beta_hat - 0) / se_beta
t_beta0
## [1] 5.764706
t_beta1 <- (beta_hat - 1) / se_beta
t_beta1
## [1] -0.1176471
abs(t_beta1) > t_crit
## [1] FALSE
alpha_hat <- 0.0017
se_alpha <- 0.0020
t_alpha <- alpha_hat / se_alpha
t_alpha
## [1] 0.85
abs(t_alpha) > t_crit
## [1] FALSE
R2 <- 0.50
systematic <- R2 * 100
diversifiable <- (1 - R2) * 100
cat("Systematic:", systematic, "%\nDiversifiable:", diversifiable, "%\n")
## Systematic: 50 %
## Diversifiable: 50 %
E_mkt_premium <- 0.70 # percent
E_fund <- beta_hat * E_mkt_premium
E_fund
## [1] 0.686
coefs <- c(alpha = 0.0029, MKT = 0.97, SMB = 0.75, HML = -0.13)
ses <- c(alpha = 0.0018, MKT = 0.08, SMB = 0.11, HML = 0.13)
t_stats <- coefs / ses
sig <- abs(t_stats) > 1.98
results <- data.frame(
Estimate = coefs,
Std.Error = ses,
t_stat = round(t_stats, 4),
Significant = sig
)
results
## Estimate Std.Error t_stat Significant
## alpha 0.0029 0.0018 1.6111 FALSE
## MKT 0.9700 0.0800 12.1250 TRUE
## SMB 0.7500 0.1100 6.8182 TRUE
## HML -0.1300 0.1300 -1.0000 FALSE
t_alpha_ff <- t_stats["alpha"]
abs(t_alpha_ff) > 1.98
## alpha
## FALSE
R2_capm <- 0.75
R2_ff <- 0.92
adj_R2 <- 0.918
improvement <- R2_ff - R2_capm
improvement
## [1] 0.17
b0 <- -0.02; b1 <- 5.4; b2 <- -0.38
r_lag <- 0.010
dvix <- 1.5
log_odds <- b0 + b1 * r_lag + b2 * dvix
prob_up <- 1 / (1 + exp(-log_odds))
cat("Log-odds:", round(log_odds, 4), "\n")
## Log-odds: -0.536
cat("P(Up) :", round(prob_up, 4), "\n")
## P(Up) : 0.3691
cat("Class :", ifelse(prob_up >= 0.5, "Up", "Down"), "\n")
## Class : Down
TP <- 67; FP <- 44; FN <- 33; TN <- 56
n <- 200
accuracy <- (TP + TN) / n
sensitivity <- TP / (TP + FN) # True positive rate for "Up"
specificity <- TN / (TN + FP) # True negative rate for "Down"
precision <- TP / (TP + FP) # Positive predictive value
cat("Accuracy :", round(accuracy, 4), "\n")
## Accuracy : 0.615
cat("Sensitivity:", round(sensitivity, 4), "\n")
## Sensitivity: 0.67
cat("Specificity:", round(specificity, 4), "\n")
## Specificity: 0.56
cat("Precision :", round(precision, 4), "\n")
## Precision : 0.6036
# Balanced classes: 100 Up, 100 Down => majority class = either (both 50%)
naive_accuracy <- 100 / 200 # always predicts majority class
beats_naive <- accuracy > naive_accuracy
cat("Naive accuracy :", round(naive_accuracy, 4), "\n")
## Naive accuracy : 0.5
cat("Model accuracy :", round(accuracy, 4), "\n")
## Model accuracy : 0.615
cat("Model beats naive:", beats_naive, "\n")
## Model beats naive: TRUE
r_bar <- 0.70
s <- 5.50
SR_monthly <- r_bar / s
SR_annual <- SR_monthly * sqrt(12)
cat("Monthly Sharpe :", round(SR_monthly, 4), "\n")
## Monthly Sharpe : 0.1273
cat("Annual Sharpe :", round(SR_annual, 4), "\n")
## Annual Sharpe : 0.4409
cat("Scaling factor :", round(sqrt(12), 4), "\n")
## Scaling factor : 3.4641
set.seed(42)
n_months <- 48
B <- 10000
r_obs <- rnorm(n_months, mean = 0.70, sd = 5.50) # placeholder observed data
boot_SR <- replicate(B, {
r_boot <- sample(r_obs, size = n_months, replace = TRUE)
mean(r_boot) / sd(r_boot) * sqrt(12)
})
SE_boot <- sd(boot_SR)
cat("Bootstrap SE of annual Sharpe:", round(SE_boot, 4), "\n")
## Bootstrap SE of annual Sharpe: 0.516
lambda_min <- 0.030; factors_min <- 14
lambda_1se <- 0.065; factors_1se <- 7
# Conceptual walk-forward structure
n_total <- 60 # months
min_train <- 36 # minimum training window
results <- list()
for (t in min_train:(n_total - 1)) {
train <- 1:t # expanding training set
test <- t + 1 # single next-month out-of-sample prediction
# 1. Fit LASSO on train using lambda_1se from inner CV
# 2. Predict on test month
# 3. Record prediction and actual return
# results[[t]] <- list(pred = ..., actual = ...)
}
# Evaluate Sharpe, hit rate, etc. on the sequence of OOS predictions