Phân tích danh mục đầu tư nâng cao với R
Ross Bennett
Instructor
# Chạy tối ưu hóa với tái cân bằng định kỳ opt_base <- optimize.portfolio.rebalancing(R = returns, optimize_method = "ROI", portfolio = base_port_spec, rebalance_on = "quarters", training_period = 60, rolling_window = 60)# Tính lợi nhuận danh mục base_returns <- Return.portfolio(returns, extractWeights(opt_base)) colnames(base_returns) <- "base"
# Vẽ trọng số tối ưu
chart.Weights(opt_base)

# Gộp lợi nhuận chuẩn và danh mục
ret <- cbind(benchmark_returns, base_returns)
# Hiệu suất thường niên
table.AnnualizedReturns(ret)
benchmark base
Annualized Return 0.0775 0.0772
Annualized Std Dev 0.1032 0.0436
Annualized Sharpe (Rf=0%) 0.7509 1.7714

# Sao chép đặc tả danh mục box_port_spec <- base_port_spec# Cập nhật ràng buộc box_port_spec <- add.constraint(portfolio = box_port_spec, type = "box", min = 0.05, max = 0.4, indexnum = 2)# Backtest opt_box <- optimize.portfolio.rebalancing(R = returns, optimize_method = "ROI", portfolio = box_port_spec, rebalance_on = "quarters", training_period = 60, rolling_window = 60)# Tính lợi nhuận danh mục box_returns <- Return.portfolio(returns, extractWeights(opt_box)) colnames(box_returns) <- "box"
# Vẽ trọng số tối ưu
chart.Weights(opt_box)

# Gộp lợi nhuận danh mục hộp ret <- cbind(ret, box_returns)# Hiệu suất thường niên table.AnnualizedReturns(ret)
benchmark base box
Annualized Return 0.0775 0.0772 0.0760
Annualized Std Dev 0.1032 0.0436 0.0819
Annualized Sharpe (Rf=0%) 0.7509 1.7714 0.9282
Phân tích danh mục đầu tư nâng cao với R