Portfolio risk

With the use of R language, we can manage portfolios better by mitigating the risk and portfolio optimization. To avoid the risk associated with portfolio analysis, diversification of the portfolio is required, with the selection of optimum weights for the portfolio's constituents.

Let us try to find the optimal weight of the portfolio whose stocks are IBM and FB, and using the CAPM. First, let us get the relevant data by executing the following code:

>GPSCMonthlyUrl<-'http://ichart.yahoo.com/table.csv?s=%5EGSPC&a=00&b=1&c=2015&d=00&e=1&f=2017&g=m' >GPSCMonthlyData <- read.csv(GPSCMonthlyUrl) >IBMMonthlyUrl<-'http://ichart.yahoo.com/table.csv?s=IBM&a=00&b=1&c=2015&d=00&e=1&f=2017&g=m' >IBMMonthlyData <- read.csv(IBMMonthlyUrl) >FBMonthlyUrl<-'http://ichart.yahoo.com/table.csv?s=FB&a=00&b=1&c=2015&d=00&e=1&f=2017&g=m' ...

Get Learning Quantitative Finance with R now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.