view_on_covariance: Views on Covariance Matrix

View source: R/views.R

view_on_covarianceR Documentation

Views on Covariance Matrix

Description

Helper to construct views on variance-covariance matrix.

Usage

view_on_covariance(x, mean, sigma)

## Default S3 method:
view_on_covariance(x, mean, sigma)

## S3 method for class 'matrix'
view_on_covariance(x, mean, sigma)

## S3 method for class 'xts'
view_on_covariance(x, mean, sigma)

## S3 method for class 'tbl_df'
view_on_covariance(x, mean, sigma)

Arguments

x

An univariate or a multivariate distribution.

mean

A double for the location parameter of the series in x.

sigma

A matrix for the target variance-covariance parameter of the series in x.

Value

A list of the view class.

Examples

library(ggplot2)

# Invariant (stationarity)
ret <- diff(log(EuStockMarkets))

# Expectations for location and dispersion parameters
mean <- colMeans(ret) # No active expectations for returns
cor <- matrix(0, ncol = 4, nrow = 4) # diagonal covariance matrix
diag(cor) <- 1                       # diagonal covariance matrix
sds <- apply(ret, 2, sd)             # diagonal covariance matrix
covs <- diag(sds) %*% cor %*% diag(sds) ## diagonal covariance matrix

# prior probabilities (usually equal weight scheme)
prior <- rep(1 / nrow(ret), nrow(ret))

# Views
views <- view_on_covariance(x = ret, mean = mean, sigma = covs)
views

# Optimization
ep <- entropy_pooling(p = prior, Aeq = views$Aeq, beq = views$beq, solver = "nlminb")
autoplot(ep)

# original covariance matrix
stats::cov(ret)

# Posterior covariance matrix
ffp_moments(x = ret, p = ep)$sigma

ffp documentation built on Sept. 29, 2022, 5:10 p.m.