This project aims to optimize stock portfolios by minimizing “tail risk” during extreme market conditions. Using the LQ45 index data (2021-2025), I compared Sharia and Non-Sharia portfolios using the Mean-CVaR method and Student-t Copula simulation.
In financial data, extreme risks are often hidden in the “fat tails” of the distribution. Traditional methods fail to capture this. Below is the visualization of the LQ45 stock returns distribution.
# Load Data & Calculate Returns
library(dplyr)
library(reshape2)
library(ggplot2)
adj <- read.csv("AdjClose_LQ45_Bulanan_2020_2025.csv", sep=";", header=TRUE)
adj$Date <- as.Date(adj$Date, format="%d/%m/%Y")
returns <- adj %>%
arrange(Date) %>%
mutate(across(-Date, ~ log(.x / lag(.x)))) %>%
na.omit()
# Plotting Boxplot to show outliers (Fat Tails)
returns_no_date <- returns[, -1]
returnsboxplot <- melt(returns_no_date)
ggplot(returnsboxplot, aes(x = variable, y = value)) +
geom_boxplot(fill = "lightblue") +
labs(title = "Boxplot Return Saham LQ45",
subtitle = "Presence of extreme outliers indicates the need for Copula simulation",
x = "Saham", y = "Return") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, size = 7))To capture the non-linear dependency and crash risk between assets, I employed the Student-t Copula method. Unlike traditional Gaussian models that assume zero tail dependence, this model successfully detects extreme simultaneous crashes during market fluctuations.
library(copula)
# Fit Gaussian Copula
normal_cop <- normalCopula(dim = ncol(u_matrix), dispstr = "un")
fit_normal <- fitCopula(normal_cop, u_matrix, method = "mpl")
# Fit Student-t Copula (Selected Model due to Tail Dependence feature)
t_cop <- tCopula(dim = ncol(u_matrix), dispstr = "un")
fit_t <- fitCopula(t_cop, u_matrix, method = "mpl")
# Generate 10,000 Monte Carlo Simulations
model_simulasi <- fit_t@copula
sim_u <- rCopula(10000, model_simulasi)After running 10,000 Monte Carlo scenarios, I optimized the asset allocation using the Mean-CVaR approach to minimize the 95% Expected Shortfall.
A. Efficient Frontier & Capital Market Line The chart below visualizes the risk-return trade-off. The highlighted tangency points indicate the optimal portfolio weights. The results prove that the Sharia portfolio achieved a higher STARR ratio, offering superior risk-adjusted returns compared to the Non-Sharia portfolio.
library(ggplot2)
# Code Snippet for Efficient Frontier + CML Extended
ggplot() +
geom_segment(aes(x = 0, y = Rf_fix, xend = max_risk_plot, yend = y_end_syariah),
color = "#2ecc71", linetype = "dashed", size = 0.6, alpha = 0.6) +
geom_segment(aes(x = 0, y = Rf_fix, xend = max_risk_plot, yend = y_end_konv),
color = "#e74c3c", linetype = "dashed", size = 0.6, alpha = 0.6) +
geom_path(data = df_frontier_plot, aes(x = CVaR, y = Exp_Ret, color = Type, group = Type), size = 1.2) +
geom_point(data = df_frontier_plot, aes(x = CVaR, y = Exp_Ret, color = Type), size = 2) +
scale_color_manual(values = c("Syariah" = "#2ecc71", "Non-Syariah" = "#e74c3c")) +
theme_minimal()B. Asset Allocation Dynamics To understand how the optimization model behaves, the stacked bar chart below illustrates the dynamic shift in asset weights. As the target return increases (from Decile 1 to Decile 9), the algorithm intelligently substitutes defensive stocks with high-yield, higher-risk assets.
A predictive model is only valuable if it holds up against historical reality. I validated the Mean-CVaR model for both portfolio types using the Kupiec Proportion of Failures (POF) test.
The visualizations below confirm that the actual losses for both Sharia and Non-Sharia portfolios rarely breached the 95% Value-at-Risk (VaR) threshold, proving the model’s reliability and robustness in real-world trading scenarios.