stockPortfolio

There are three simple steps in stockPortfolio to identifying an optimal portfolio

  1. Download data

stockData <- getReturns(vectoroftickers,start=‘2016-03-15’,end=‘2017-03-15’)

  1. Model the stock behavior using the data

model1 <- stockModel(stockData) model2 <- stockModel(storkData, model=‘CCM’)

  1. Identify the optimal portfolio suggested by the model

optPort <- optimalPort(model1)

see https://cran.r-project.org/web/packages/stockPortfolio/stockPortfolio.pdf.

library(stockPortfolio)
ticker <- c('C','BAC','JPM','WFC')
gR <- getReturns(ticker, start='2016-03-15',end='2017-03-15')
byDay <- getReturns(ticker,'d',start='2016-03-15')
byWk <- getReturns(ticker,'w',start='2016-03-15')
byMth <- getReturns(ticker,'m',start='2016-03-15')
getReturns(ticker,freq=c("month","week","day"),get=c("overlapOnly","all"),start ="2016-03-15",end=NULL)
## Time Scale: month 
## 
## Average Return
##          C        BAC        JPM        WFC 
## 0.03365373 0.05497465 0.03934434 0.01896777
theData <- getReturns(ticker, 'w',start='2016-03-15',end='2017-03-15')
plot(theData)

pairs(theData)

Create the portfolio cloud

By randomly construct many portfolios, a general view of the Risk-Return possibilities becomes apparent.

data(stock94)
sm <- stockModel(stock94, model='SIM', index=25)
portCloud(sm, add=FALSE)
portPossCurve(sm, 2.5, add=TRUE)

Frontier Curve

The top half of this curve yields the best possible investments: The efficicient forntier

There are four models to use:

Variance covariance

Constant correlation model (CCM)

Multigroup model (MGM)