# Portfolio Risk – Diversification and Correlation

This article is a visualization of a portfolio of two assets where we see how portfolio return and risk changes as the weight changes and the correlation between the two underlying assets changes.

This is a very typical risk return plot where the horizontal axis represent the risk – standard deviation of the portfolio where the vertical axis represent the expected return of the portfolio. All the data points are color coded by the correlation between the two assets (eg. purple +1, 100% positive correlated). It might not be that obvious, but I set the size of each data point to be the weight for asset 1 where the biggest represent all the capital is allocated to the asset one, and vice versa.

Here is a screenshot of the R code to generate the graph above.

The key takeaway is that given same expected return, you want to diversify your portfolio in a way where underlying assets are more negatively correlated to each other to reduce the risk. This might sounds magical but the math did serve the purpose of proof. However, it is easier to say than doing, if you have an asset that has a good return, but might correlate positively which you will like to replace, in real life, it will be hard to find some alternative with the same return because if a stock is negatively correlated to what you already have, it probably has a subpar return rate (hedging is another thing if that is what you want to achieve).

# R – Interesting Density Plot

I always use histogram command to look at the distribution of a uni-variable data. And to distinguish the difference of distribution of a subgroup from the whole, I usually do two or more plots with the same scale.

data(mtcars)
par(mfrow=c(4,1))
hist(mtcars\$mpg, breaks=20, col=8, xlim=c(10, 40), main=’total’)
hist(mtcars\$mpg[mtcars\$cyl==4], breaks=20, col=3, xlim=c(10, 40), main=’V4′)
hist(mtcars\$mpg[mtcars\$cyl==6], breaks=20, col=4, xlim=c(10, 40), main=’V6′)
hist(mtcars\$mpg[mtcars\$cyl==8], breaks=20, col=5, xlim=c(10, 40), main=’V8′)

You can clearly read the information that the more cylinders you have in your car, the more gas it will take in general, of course, a lower MPG (Miles Per Gallon).

Also, you can use the density plot to see the distribution of data for each cylinder and plot them all together in one plot. I also attached a boxplot using factor which give a better picture of what is going on. By the way, the varwidth=TRUE will set the width of the box as the number of records in that box. In this case, you will see we have almost same amount of records inside each category.

dens = density(mtcars\$mpg)
dens.4 = density(mtcars\$mpg[mtcars\$cyl==4])
dens.6 = density(mtcars\$mpg[mtcars\$cyl==6])
dens.8 = density(mtcars\$mpg[mtcars\$cyl==8])
par(mfrow=c(2,1))
plot(dens, lwd=4, col=8, ylim=c(0, 0.25), main=”Density Plot of MPG”)
lines(dens.4, lwd=3, col=3)
lines(dens.6, lwd=3, col=4)
lines(dens.8, lwd=3, col=5)
boxplot(mtcars\$mpg ~ as.factor(mtcars\$cyl), varwidth=TRUE, col=’orange’, main=”Boxplot of MPG vs Number of Cylinders”)

# STATS – How a Auto Regressive Series and Moving Average Series Look Like

ACF of AR(1) is phi^h

ACF of MV(1) is theta/(1+theta^2) only for h=1 and 0 when h>1

——————————————————————————————–

par(mfrow=c(4,2))
a1 <- arima.sim(list(order=c(1,0,0), ar=0.9), n=100)
plot(a1, ylab=”x”, main=(expression(AR(1)~~~phi==+.9)))
acf(a1)
a2 <- arima.sim(list(order=c(1,0,0), ar=-0.9), n=100)
plot(a2, ylab=”x”, main=(expression(AR(1)~~~phi==-.9)))
acf(a2)
a3 <- arima.sim(list(order=c(0,0,1), ma=0.5), n=100)
plot(a3, ylab=”x”, main=(expression(MA(1)~~~theta==+.5)))
acf(a3)
a4 <- arima.sim(list(order=c(0,0,1), ma=-0.5), n=100)
plot(a4, ylab=”x”, main=(expression(MA(1)~~~phi==-.5)))
acf(a4)