getPortfolio: Create portfolio object

Description Usage Arguments Details Value Author(s) Examples

View source: R/getPortfolio.R

Description

Create a portfolio object from expected return vector, covariance matrix, and weight vector.

Usage

1
getPortfolio(er, cov.mat, weights)

Arguments

er

N x 1 vector of expected returns

cov.mat

N x N return covariance matrix

weights

N x 1 vector of portfolio weights

Details

To specify a portfolio, an expected return vector and covariance matrix for the assets under consideration as well as a vector of portfolio weights are needed. The result of getPortfolio is a portfolio object, which is list with components for the portfolio expected return, portfolio standard deviation, and portfolio weights. There are print, summary and plot methods.

Value

call

captures function call

er

portfolio expected return

sd

portfolio standard deviation

weights

N x 1 vector of portfolio weights

Author(s)

Eric Zivot

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# construct the data
asset.names = c("MSFT", "NORD", "SBUX")
er = c(0.0427, 0.0015, 0.0285)
names(er) = asset.names
covmat = matrix(c(0.0100, 0.0018, 0.0011,
                  0.0018, 0.0109, 0.0026,
                  0.0011, 0.0026, 0.0199),
                nrow=3, ncol=3)
r.free = 0.005
dimnames(covmat) = list(asset.names, asset.names)
er
covmat
r.free

# compute equally weighted portfolio
ew = rep(1,3)/3
equalWeight.portfolio = getPortfolio(er=er,cov.mat=covmat,weights=ew)
class(equalWeight.portfolio)
names(equalWeight.portfolio)
equalWeight.portfolio
summary(equalWeight.portfolio)
plot(equalWeight.portfolio, col="blue")

IntroCompFinR documentation built on May 2, 2019, 4:46 p.m.