Portfolio Frontier with Two Risky Assets and Varying Correlation

w.e <- seq(-0.5, 1.5, by = 0.01)
w.d <- 1 - w.e
r.e <- 0.12
r.d <- 0.09
E <- w.e * r.e + w.d * r.d
s.e <- 0.2
s.d <- 0.11
corr <- 0.3
S <- sqrt((w.e^2) * s.e^2 + (w.d^2) * s.d^2 + 2 * w.d * w.e * s.e * s.d * corr)
plot(S, E, type = "l", xlim = c(0, 0.3), xlab = "Portfolio Standard Deviation", 
    ylab = "Portfolio Expected Return")

f <- seq(-1, 1, by = 0.1)
S2 <- matrix(0, nrow = 201, ncol = 21)
for (i in 1:21) {
    Sys.sleep(0.5)
    S2[, i] <- sqrt((w.e^2) * s.e^2 + (w.d^2) * s.d^2 + 2 * w.d * w.e * s.e * 
        s.d * f[i])
    lines(S2[, i], E, col = i, lwd = 2)
}

plot of chunk unnamed-chunk-1