view_on_covariance | R Documentation |
Helper to construct views on variance-covariance matrix.
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)
x |
An univariate or a multivariate distribution. |
mean |
A |
sigma |
A |
A list
of the view
class.
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.