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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.