view_on_correlation: Views on Correlation Structure

View source: R/views.R

view_on_correlationR Documentation

Views on Correlation Structure

Description

Helper to construct views on the correlation matrix.

Usage

view_on_correlation(x, cor)

## Default S3 method:
view_on_correlation(x, cor)

## S3 method for class 'matrix'
view_on_correlation(x, cor)

## S3 method for class 'xts'
view_on_correlation(x, cor)

## S3 method for class 'tbl_df'
view_on_correlation(x, cor)

Arguments

x

An univariate or a multivariate distribution.

cor

A matrix for the target correlation structure of the series in x.

Value

A list of the view class.

Examples

library(ggplot2)

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

# Assume that a panic event throws all correlations to the roof!
co <- matrix(0.95, 4, 4)
diag(co) <- 1
co

# Prior probability (usually the equal-weight setting)
prior <- rep(1 / nrow(ret), nrow(ret))

# View
views <- view_on_correlation(x = ret, cor = co)
views

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

# prior correlation structure
stats::cor(ret)

# posterior correlation structure matches the initial view very closely
stats::cov2cor(ffp_moments(x = ret, p = ep)$sigma)

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