Learn R Programming

stockPortfolio (version 1.2)

getCorr: Average correlation

Description

Determine the average correlation or average correlation by industry of a variance-covariance matrix.

Usage

getCorr(V, industry = NULL)

Arguments

V
Variance-covariance matrix.
industry
A vector specifying the industry of the stocks in their order given in the columns (and rows) of V. This argument is optional.

Value

If industry is not provided, then the average correlation in V in the matrix is returned but ignoring the diagonal. If industry is provided, then the output is a matrix with dimension k-by-k, where k is the number of unique values in industry.

See Also

stockModel

Examples

Run this code
#===> the covariance matrix of stock94 <===#
data(stock94)
data(stock94Info)
V <- cov(stock94)

#===> the average correlation <===#
getCorr(V)
getCorr(V, industry=stock94Info$industry)

Run the code above in your browser using DataLab