Movatterモバイル変換


[0]ホーム

URL:


Type:Package
Title:Fully Flexible Probabilities for Stress Testing and PortfolioConstruction
Version:0.2.2
Description:Implements numerical entropy-pooling for portfolio construction and scenario analysis as described in Meucci, Attilio (2008) and Meucci, Attilio (2010) <doi:10.2139/ssrn.1696802>.
License:MIT + file LICENSE
URL:https://github.com/Reckziegel/FFP
BugReports:https://github.com/Reckziegel/FFP/issues
Depends:R (≥ 2.10)
Imports:assertthat (≥ 0.2.1), dplyr (≥ 1.0.10), forcats (≥ 0.5.2),ggdist (≥ 3.2.0), ggplot2 (≥ 3.3.6), lubridate (≥ 1.8.0),magrittr (≥ 2.0.3), methods, mvtnorm (≥ 1.1-3), purrr (≥0.3.4), rlang (≥ 1.0.6), scales (≥ 1.2.1), stringr (≥1.4.1), stats, tibble (≥ 3.1.8), tidyr (≥ 1.2.1), vctrs (≥0.4.1), nloptr (≥ 2.0.3), crayon, NlcOptim (≥ 0.6)
Suggests:copula, covr, ghyp, knitr (≥ 1.40), markdown, rmarkdown,roxygen2, spelling, testthat (≥ 3.1.4), xts (≥ 0.12.1)
Config/testthat/edition:3
Encoding:UTF-8
Language:en-US
LazyData:true
RoxygenNote:7.2.1
VignetteBuilder:knitr
NeedsCompilation:no
Packaged:2022-09-29 13:29:47 UTC; USUARIO
Author:Bernardo Reckziegel [aut, cre]
Maintainer:Bernardo Reckziegel <bernardo_cse@hotmail.com>
Repository:CRAN
Date/Publication:2022-09-29 15:10:06 UTC

Double-Decay Covariance Matrix

Description

This function computes the covariance matrix using two different decay factors.

Usage

DoubleDecay(x, decay_low, decay_high)

Arguments

x

A set of relevant risk drivers.

decay_low

Anumeric value with the low decay (long half-life).

decay_high

Anumeric value with the high decay (short half-life).

Details

A common practice is to estimate the covariance of the risk drivers using a highdecay (short half-life) for the volatilities and a low decay (long half-life)for the correlations.

Value

Alist with the posterior mean ans sigma.


Inspection of affp object with ggplot2

Description

Extends theautoplot method for theffp class.

Usage

## S3 method for class 'ffp'autoplot(object, color = TRUE, ...)## S3 method for class 'ffp'plot(object, ...)

Arguments

object

An objected of theffp class.

color

Alogical flag indicating whether (or not) thecolor argumentshould be added to theggplot2 aesthetics.

...

Additional arguments to be passed toautoplot.

Value

Aggplot2 object.

Examples

library(ggplot2)x <- exp_decay(EuStockMarkets, 0.001)y <- exp_decay(EuStockMarkets, 0.01)autoplot(x) +  scale_color_viridis_c()autoplot(y) +  scale_color_viridis_c()

Stack Flexible Probabilities

Description

This function mimicsdplyrbind. It's useful if youhave differentffp objects and want to stack them in thetidy (long) format.

Usage

bind_probs(...)

Arguments

...

ffp objects to combine.

Value

A tidytibble.

The output adds two new columns:

See Also

crispexp_decaykernel_normalkernel_entropydouble_decay

Examples

library(ggplot2)library(dplyr, warn.conflicts = FALSE)x <- exp_decay(EuStockMarkets, lambda = 0.001)y <- exp_decay(EuStockMarkets, lambda = 0.002)bind_probs(x, y)bind_probs(x, y) %>%  ggplot(aes(x = rowid, y = probs, color = fn)) +  geom_line() +  scale_color_viridis_d() +  theme(legend.position="bottom")

Stack Different Views

Description

Bind views for entropy programming.

Usage

bind_views(...)

Arguments

...

Objects of the classffp_views to combine.

Value

Alist of theview class.

Examples

library(ggplot2)# Invariantret <- diff(log(EuStockMarkets))n   <- nrow(ret)# Prior probabilities (usually equal weight scheme)prior <- rep(1 / n, n)# Prior belief for expected returns (here is 0% for each asset)view_mean <- view_on_mean(x = ret, mean = rep(0, 4))#' view on volatilityvol <- apply(ret, 2, stats::sd) * 1.1 # volatility 10% higher than averageview_volatility <- view_on_volatility(x = ret, vol = vol)views_comb <- bind_views(view_mean, view_volatility)views_combep <- entropy_pooling(p      = prior,                      Aeq    = views_comb$Aeq,                      beq    = views_comb$beq,                      A      = views_comb$A,                      b      = views_comb$b,                      solver = "nlminb")autoplot(ep)

Flexible Probabilities Driven Bootstrap

Description

Resamples historical scenarios with flexible probabilities.

Usage

bootstrap_scenarios(x, p, n)## S3 method for class 'numeric'bootstrap_scenarios(x, p, n)## S3 method for class 'matrix'bootstrap_scenarios(x, p, n)## S3 method for class 'ts'bootstrap_scenarios(x, p, n)## S3 method for class 'xts'bootstrap_scenarios(x, p, n)## S3 method for class 'tbl'bootstrap_scenarios(x, p, n)## S3 method for class 'data.frame'bootstrap_scenarios(x, p, n)

Arguments

x

A time series defining the scenario-probability distribution.

p

An object of theffp class.

n

Aninteger scalar with the number of scenarios to be generated.

Details

The argumentx is supposed to have the same size ofp.

Value

Atibble with the number of rows equal ton.

Examples

set.seed(123)ret <- diff(log(EuStockMarkets))ew  <- rep(1 / nrow(ret), nrow(ret))bootstrap_scenarios(x = ret, p = as_ffp(ew), n = 10)

Internal function used to check the validity of inputs.

Description

Internal function used to check the validity of inputs.

Usage

check_input(x)## Default S3 method:check_input(x)## S3 method for class 'numeric'check_input(x)## S3 method for class 'double'check_input(x)## S3 method for class 'matrix'check_input(x)## S3 method for class 'xts'check_input(x)## S3 method for class 'tbl_df'check_input(x)

Arguments

x

Any object passed to other functions in the package.

Value

A matrix


Full Information by Market Conditioning

Description

Give full weight to occurrences that satisfies a logical condition.

Usage

crisp(x, lgl)## Default S3 method:crisp(x, lgl)## S3 method for class 'numeric'crisp(x, lgl)## S3 method for class 'matrix'crisp(x, lgl)## S3 method for class 'ts'crisp(x, lgl)## S3 method for class 'xts'crisp(x, lgl)## S3 method for class 'data.frame'crisp(x, lgl)## S3 method for class 'tbl_df'crisp(x, lgl)

Arguments

x

An univariate or a multivariate distribution.

lgl

Alogical vector with TRUE's and FALSE's indicating which scenarios should considered.

Value

A numerical vector of classffp with the newprobabilities distribution.

See Also

exp_decaykernel_normal

Examples

library(ggplot2)# invariance (stationarity)ret <- diff(log(EuStockMarkets))# full weight on scenarios where CAC returns were above 2%market_condition <- crisp(x = ret, ret[ , 3] > 0.02)market_conditionautoplot(market_condition) +  scale_color_viridis_c()

Dataset used in Historical Scenarios with Fully Flexible Probabilities(matrix format).

Description

Dataset used in Historical Scenarios with Fully Flexible Probabilities(matrix format).

Usage

db

Format

An object of classmatrix (inherits fromarray) with 1083 rows and 9 columns.

See Also

db_tbl


Dataset used in Historical Scenarios with Fully Flexible Probabilities(tibble format).

Description

Dataset used in Historical Scenarios with Fully Flexible Probabilities(tibble format).

Usage

db_tbl

Format

An object of classtbl_df (inherits fromtbl,data.frame) with 1083 rows and 9 columns.

See Also

db


Flexible Probabilities using Partial Information

Description

Match different decay-factors on the covariance matrix.

Usage

double_decay(x, slow, fast)## Default S3 method:double_decay(x, slow, fast)## S3 method for class 'numeric'double_decay(x, slow, fast)## S3 method for class 'matrix'double_decay(x, slow, fast)## S3 method for class 'ts'double_decay(x, slow, fast)## S3 method for class 'xts'double_decay(x, slow, fast)## S3 method for class 'tbl'double_decay(x, slow, fast)## S3 method for class 'data.frame'double_decay(x, slow, fast)

Arguments

x

An univariate or a multivariate distribution.

slow

Adouble with the long half-life (slow decay) for the correlationmatrix.

fast

Adouble with the short-life (high decay) for the volatility.

Value

A numerical vector of classffp with the newprobabilities distribution.

References

De Santis, G., R. Litterman, A. Vesval, and K. Winkelmann, 2003,Covariance matrix estimation, Modern investment management: an equilibriumapproach, Wiley.

See Also

kernel_entropyhalf_life

Examples

  library(ggplot2)  slow <- 0.0055  fast <- 0.0166  ret <- diff(log(EuStockMarkets))  dd <- double_decay(ret, slow, fast)  dd  autoplot(dd) +    scale_color_viridis_c()

Summary Statistics for Empirical Distributions

Description

Computes the mean, standard deviation, skewness, kurtosis, Value-at-Risk (VaR) andConditional Value-at-Risk CVaR) under flexible probabilities.

Usage

empirical_stats(x, p, level = 0.01)## Default S3 method:empirical_stats(x, p, level = 0.01)## S3 method for class 'numeric'empirical_stats(x, p, level = 0.01)## S3 method for class 'matrix'empirical_stats(x, p, level = 0.01)## S3 method for class 'xts'empirical_stats(x, p, level = 0.01)## S3 method for class 'ts'empirical_stats(x, p, level = 0.01)## S3 method for class 'data.frame'empirical_stats(x, p, level = 0.01)## S3 method for class 'tbl_df'empirical_stats(x, p, level = 0.01)

Arguments

x

A time series defining the scenario-probability distribution.

p

An object of theffp class.

level

A number with the desired probability level. The default islevel = 0.01.

Details

The data inx andp are expected to have the same number of rows(size).

Value

A tidytibble with 3 columns:

Examples

library(dplyr, warn.conflicts = FALSE)library(ggplot2)ret <- diff(log(EuStockMarkets))# with equal weights (standard scenario)ew  <- rep(1 / nrow(ret), nrow(ret))empirical_stats(x = ret, p = as_ffp(ew)) %>%  ggplot(aes(x = name, y = value)) +  geom_col() +  facet_wrap(~stat, scales = "free") +  labs(x = NULL, y = NULL)# with ffpexp_smooth <- exp_decay(ret, 0.015)empirical_stats(ret, exp_smooth) %>%  ggplot(aes(x = name, y = value)) +  geom_col() +  facet_wrap(~stat, scales = "free") +  labs(x = NULL, y = NULL)

Effective Number of Scenarios

Description

Shows how many scenarios are effectively been considered when using flexibleprobabilities.

Usage

ens(p)

Arguments

p

An object of theffp class.

Value

A singledouble.

Examples

set.seed(123)p <- exp_decay(stats::rnorm(100), 0.01)# ens is smaller than 100ens(p)

Numerical Entropy Minimization

Description

This function solves the entropy minimization problem with equality and inequalityconstraints. The solution is a vector of posterior probabilities that distortsthe least the prior (equal-weights probabilities) given the constraints (views onthe market).

Usage

entropy_pooling(  p,  A = NULL,  b = NULL,  Aeq = NULL,  beq = NULL,  solver = c("nlminb", "solnl", "nloptr"),  ...)

Arguments

p

A vector of prior probabilities.

A

The linear inequality constraint (left-hand side).

b

The linear inequality constraint (right-hand side).

Aeq

The linear equality constraint (left-hand side).

beq

The linear equality constraint (right-hand side).

solver

Acharacter. One of: "nlminb", "solnl" or "nloptr".

...

Further arguments passed to one of the solvers.

Details

When imposing views constraints there is no need to specify the non-negativityconstraint for probabilities, which is done automatically byentropy_pooling.

For the arguments accepted in..., please see the documentation ofnlminb,solnl,nloptrand the examples bellow.

Value

A vector of posterior probabilities.

Examples

# setupret <- diff(log(EuStockMarkets))n   <- nrow(ret)# View on expected returns (here is 2% for each asset)mean <- rep(0.02, 4)# Prior probabilities (usually equal weight scheme)prior <- rep(1 / n, n)# Viewviews <- view_on_mean(x = ret, mean = mean)# Optimizationep <- entropy_pooling( p      = prior, Aeq    = views$Aeq, beq    = views$beq, solver = "nlminb")ep### Using the ... argument to control the optimization parameters# nlminbep <- entropy_pooling( p      = prior, Aeq    = views$Aeq, beq    = views$beq, solver = "nlminb", control = list(     eval.max = 1000,     iter.max = 1000,     trace    = TRUE   ))ep# nloptrep <- entropy_pooling( p      = prior, Aeq    = views$Aeq, beq    = views$beq, solver = "nloptr", control = list(     xtol_rel = 1e-10,     maxeval  = 1000,     check_derivatives = TRUE   ))ep

Full Information by Exponential Decay

Description

Exponential smoothing twists probabilities by giving relatively more weightto recent observations at an exponential rate.

Usage

exp_decay(x, lambda)## Default S3 method:exp_decay(x, lambda)## S3 method for class 'numeric'exp_decay(x, lambda)## S3 method for class 'matrix'exp_decay(x, lambda)## S3 method for class 'ts'exp_decay(x, lambda)## S3 method for class 'xts'exp_decay(x, lambda)## S3 method for class 'data.frame'exp_decay(x, lambda)## S3 method for class 'tbl'exp_decay(x, lambda)

Arguments

x

An univariate or a multivariate distribution.

lambda

Adouble for the decay parameter.

Details

The half-life is linked with the lambda parameter as follows:

For example: log(2) / 0.0166 is approximately 42. So, a parameterlambda of 0.0166can be associated with a half-life of two-months (21 * 2).

Value

A numerical vector of classffp with the newprobabilities distribution.

See Also

crispkernel_normalhalf_life

Examples

library(ggplot2)# long half_lifelong_hl <- exp_decay(EuStockMarkets, 0.001)long_hlautoplot(long_hl) +  scale_color_viridis_c()# short half_lifeshort_hl <- exp_decay(EuStockMarkets, 0.015)short_hlautoplot(short_hl) +  scale_color_viridis_c()

Manipulate theffp Class

Description

Helpers and Constructors fromffp.

Usage

ffp(x = double(), ...)is_ffp(x)as_ffp(x)## Default S3 method:as_ffp(x)## S3 method for class 'integer'as_ffp(x)

Arguments

x
  • Forffp(): A numeric vector.

  • Foris_ffp(): An object to be tested.

  • Foras_ffp(): An object to convert toffp.

...

Additional attributes to be passed toffp.

Details

Theffp class is designed to interact with doubles,but the output ofc(ffp, double) orc(double, ffp) will always returnadouble (not anffp object), since there is no way to guarantee theinteraction between a numeric vector and a probability will also be a probability.

Value

Examples

set.seed(123)p <- runif(5)p <- p / sum(p)is_ffp(p)as_ffp(p)

Internal vctrs methods

Description

Internal vctrs methods

Usage

new_ffp(x = double(), ...)## S3 method for class 'ffp'vec_ptype_abbr(x, ...)## S3 method for class 'ffp.ffp'vec_ptype2(x, y, ...)## S3 method for class 'ffp.double'vec_ptype2(x, y, ...)## S3 method for class 'double.ffp'vec_ptype2(x, y, ...)## S3 method for class 'ffp.ffp'vec_cast(x, to, ...)## S3 method for class 'ffp.double'vec_cast(x, to, ...)## S3 method for class 'double.ffp'vec_cast(x, to, ...)## S3 method for class 'ffp'obj_print_data(x, ...)## S3 method for class 'ffp'vec_math(.fn, .x, ...)## S3 method for class 'ffp'vec_arith(op, x, y, ...)

Arguments

x

A numeric vector.

Value

No return value, called for side effects.


Moments with Flexible Probabilities

Description

Computes the location and dispersion statistics under flexible probabilities.

Usage

ffp_moments(x, p = NULL)## Default S3 method:ffp_moments(x, p = NULL)## S3 method for class 'numeric'ffp_moments(x, p = NULL)## S3 method for class 'matrix'ffp_moments(x, p = NULL)## S3 method for class 'xts'ffp_moments(x, p = NULL)## S3 method for class 'data.frame'ffp_moments(x, p = NULL)## S3 method for class 'tbl_df'ffp_moments(x, p = NULL)

Arguments

x

A tabular (non-tidy) data structure.

p

An object of theffp class.

Value

Alist with 2 elements:mu andsigma.

Examples

x <- matrix(diff(log(EuStockMarkets)), ncol = 4)colnames(x) <- colnames(EuStockMarkets)p <- stats::runif(nrow(x))p <- p / sum(p)ffp_moments(x = x, p = p)# compare with the standard approachcolMeans(x)cov(x)

Double-Decay Covariance Matrix by Entropy-Pooling

Description

Internal function that computes the flexible probabilities given bydouble-decay covariance matrix.

Usage

fit_to_moments(X, m, S)

Arguments

X

Amatrix of sizeTxN with relevant the risk drivers.

m

Amatrix of sizeNx1 given byDouble_Decaywith risk drivers location.

S

Amatrix of sizeNxN given byDouble_Decaywith the dispersion matrix of the risk drivers.

Value

Amatrix vector with the posterior probabilities.


Half-Life Calculation

Description

Compute the implied half-life of a decay parameter.

Usage

half_life(lambda)

Arguments

lambda

A number.

Value

A single number with the half-life in days.

See Also

exp_decaydouble_decay

Examples

half_life(0.0166)half_life(0.01)

Partial Information Kernel-Damping

Description

Find the probability distribution that canconstrain the first two moments while imposing the minimal structure in the data.

Usage

kernel_entropy(x, mean, sigma = NULL)## Default S3 method:kernel_entropy(x, mean, sigma = NULL)## S3 method for class 'numeric'kernel_entropy(x, mean, sigma = NULL)## S3 method for class 'matrix'kernel_entropy(x, mean, sigma = NULL)## S3 method for class 'ts'kernel_entropy(x, mean, sigma = NULL)## S3 method for class 'xts'kernel_entropy(x, mean, sigma = NULL)## S3 method for class 'tbl_df'kernel_entropy(x, mean, sigma = NULL)## S3 method for class 'data.frame'kernel_entropy(x, mean, sigma = NULL)

Arguments

x

An univariate or a multivariate distribution.

mean

A numeric vector in which the kernel should be centered.

sigma

The uncertainty (volatility) around the mean. WhenNULL, only the mean is constrained.

Value

A numerical vector of classffp with the newprobabilities distribution.

See Also

double_decay

Examples

library(ggplot2)ret <- diff(log(EuStockMarkets[ , 1]))mean <- -0.01 # scenarios around -1%sigma <- var(diff(ret))ke <- kernel_entropy(ret, mean, sigma)keautoplot(ke) +  scale_color_viridis_c()

Full Information by Kernel-Damping

Description

Historical realizations receive a weight proportional totheir distance from a target mean.

Usage

kernel_normal(x, mean, sigma)## Default S3 method:kernel_normal(x, mean, sigma)## S3 method for class 'numeric'kernel_normal(x, mean, sigma)## S3 method for class 'matrix'kernel_normal(x, mean, sigma)## S3 method for class 'ts'kernel_normal(x, mean, sigma)## S3 method for class 'xts'kernel_normal(x, mean, sigma)## S3 method for class 'tbl_df'kernel_normal(x, mean, sigma)## S3 method for class 'data.frame'kernel_normal(x, mean, sigma)

Arguments

x

An univariate or a multivariate distribution.

mean

A numeric vector in which the kernel should be centered.

sigma

The uncertainty (volatility) around the mean.

Value

A numerical vector of classffp with the newprobabilities distribution.

See Also

crispexp_decay

Examples

library(ggplot2)ret <- diff(log(EuStockMarkets[ , 1]))mean <- -0.01 # scenarios around -1%sigma <- var(diff(ret))kn <- kernel_normal(ret, mean, sigma)knautoplot(kn) +  scale_color_viridis_c()# A larger sigma spreads out the distributionsigma <- var(diff(ret)) / 0.05kn <- kernel_normal(ret, mean, sigma)autoplot(kn) +  scale_color_viridis_c()

Least Information Kernel-Smoothing

Description

This is an internal function that uses the kernel-smoothing approach to computethe posterior probabilities that satisfies some macroeconomic statement.

Usage

least_info_kernel(Y, y, h2)

Arguments

Y

Amatrix with the macroeconomic indicators.

y

Anumeric scalar with the target to whichY is expectedto be near by.

h2

Amatrix with the covariance of theY factor.

Value

A vector with the new probability distribution.


Relative Entropy

Description

Computes the relative entropy of two distributions.

Usage

relative_entropy(prior, posterior)

Arguments

prior

A prior probability distribution.

posterior

A posterior probability distribution.

Value

Adouble with the relative entropy.

Examples

set.seed(222)prior <- rep(1 / 100, 100)posterior <- runif(100)posterior <- posterior / sum(posterior)relative_entropy(prior, posterior)

Plot Scenarios

Description

This functions are designed to make it easier to visualize the impact of aView in the P&L distribution.

Usage

scenario_density(x, p, n = 10000)scenario_histogram(x, p, n = 10000)

Arguments

x

An univariate marginal distribution.

p

A probability from theffp class.

n

Aninteger scalar with the number of scenarios to be generated.

Details

To generate a scenario-distribution the margins are bootstrapped usingbootstrap_scenarios. The number of resamples can be controlledwith then argument (default isn = 10000).

Value

Aggplot2 object.

Examples

x <- diff(log(EuStockMarkets))[, 1]p <- exp_decay(x, 0.005)scenario_density(x, p, 500)scenario_histogram(x, p, 500)

Views on Copulas

Description

Helper to construct constraints on copulas for entropy programming.

Usage

view_on_copula(x, simul, p)## Default S3 method:view_on_copula(x, simul, p)## S3 method for class 'matrix'view_on_copula(x, simul, p)## S3 method for class 'xts'view_on_copula(x, simul, p)## S3 method for class 'tbl_df'view_on_copula(x, simul, p)

Arguments

x

A multivariate copula.

simul

A simulated target copula.

p

An object of theffp class.

Value

Alist of theview class.

Examples

  set.seed(1)  library(ggplot2)  # Invariants  ret <- diff(log(EuStockMarkets))  u <- apply(ret, 2, stats::pnorm) # assuming normal copula  n <- nrow(u)  #' Prior probability distribution  prior <- rep(1 / n, n)  # Simulated marginals  simul_marg <- bootstrap_scenarios(ret, as_ffp(prior), as.double(n))  # Copulas derived from the simulated margins  simul_cop <- apply(simul_marg, 2, stats::pnorm) # assuming normal copula  views <- view_on_copula(x = u, simul = simul_cop, p = prior)  views  ep <- entropy_pooling(p = prior, Aeq = views$Aeq, beq = views$beq, solver = "nloptr")  autoplot(ep)

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

Amatrix for the target correlation structure ofthe series inx.

Value

Alist of theview class.

Examples

library(ggplot2)# Invariantret <- diff(log(EuStockMarkets))# Assume that a panic event throws all correlations to the roof!co <- matrix(0.95, 4, 4)diag(co) <- 1co# Prior probability (usually the equal-weight setting)prior <- rep(1 / nrow(ret), nrow(ret))# Viewviews <- view_on_correlation(x = ret, cor = co)views# Optimizationep <- entropy_pooling(p = prior, Aeq = views$Aeq, beq = views$beq, solver = "nlminb")autoplot(ep)# prior correlation structurestats::cor(ret)# posterior correlation structure matches the initial view very closelystats::cov2cor(ffp_moments(x = ret, p = ep)$sigma)

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

Adouble for the location parameter of the series inx.

sigma

Amatrix for the target variance-covariance parameterof the series inx.

Value

Alist of theview class.

Examples

library(ggplot2)# Invariant (stationarity)ret <- diff(log(EuStockMarkets))# Expectations for location and dispersion parametersmean <- colMeans(ret) # No active expectations for returnscor <- matrix(0, ncol = 4, nrow = 4) # diagonal covariance matrixdiag(cor) <- 1                       # diagonal covariance matrixsds <- apply(ret, 2, sd)             # diagonal covariance matrixcovs <- diag(sds) %*% cor %*% diag(sds) ## diagonal covariance matrix# prior probabilities (usually equal weight scheme)prior <- rep(1 / nrow(ret), nrow(ret))# Viewsviews <- view_on_covariance(x = ret, mean = mean, sigma = covs)views# Optimizationep <- entropy_pooling(p = prior, Aeq = views$Aeq, beq = views$beq, solver = "nlminb")autoplot(ep)# original covariance matrixstats::cov(ret)# Posterior covariance matrixffp_moments(x = ret, p = ep)$sigma

Views on Joint Distribution

Description

Helper to construct constraints on the entire distribution.

Usage

view_on_joint_distribution(x, simul, p)## Default S3 method:view_on_joint_distribution(x, simul, p)## S3 method for class 'matrix'view_on_joint_distribution(x, simul, p)## S3 method for class 'xts'view_on_joint_distribution(x, simul, p)## S3 method for class 'tbl_df'view_on_joint_distribution(x, simul, p)

Arguments

x

An univariate or a multivariate distribution.

simul

An univariate or multivariate simulated panel.

p

An object of theffp class.

Details

Value

Alist of theview class.

Examples

set.seed(1)library(ggplot2)# Invariantsret <- diff(log(EuStockMarkets))n <- nrow(ret)#' Prior probability distributionprior <- rep(1 / n, n)# Simulated marginalssimul <- bootstrap_scenarios(ret, as_ffp(prior), as.double(n))views <- view_on_joint_distribution(x = ret, simul = simul, p = prior)viewsep <- entropy_pooling(p = prior, Aeq = views$Aeq, beq = views$beq, solver = "nlminb")autoplot(ep)# location matchescolMeans(simul)ffp_moments(x = ret, p = ep)$mu# dispersion matchescov(simul)ffp_moments(x = ret, p = ep)$sigma

Views on Marginal Distribution

Description

Helper to construct constraints on the marginal distribution.

Usage

view_on_marginal_distribution(x, simul, p)## Default S3 method:view_on_marginal_distribution(x, simul, p)## S3 method for class 'matrix'view_on_marginal_distribution(x, simul, p)## S3 method for class 'xts'view_on_marginal_distribution(x, simul, p)## S3 method for class 'tbl_df'view_on_marginal_distribution(x, simul, p)

Arguments

x

An univariate or a multivariate distribution.

simul

An univariate or multivariate simulated panel.

p

An object of theffp class.

Details

Value

Alist of theview class.

Examples

set.seed(1)library(ggplot2)# Invariantsret <- diff(log(EuStockMarkets))n <- nrow(ret)#' Prior probability distributionprior <- rep(1 / n, n)# Simulated marginalssimul <- bootstrap_scenarios(ret, as_ffp(prior), as.double(n))views <- view_on_marginal_distribution(x = ret, simul = simul, p = prior)viewsep <- entropy_pooling(p = prior, Aeq = views$Aeq, beq = views$beq, solver = "nlminb")autoplot(ep)# location matchescolMeans(simul)ffp_moments(x = ret, p = ep)$mu# dispersion matchescov(simul)ffp_moments(x = ret, p = ep)$sigma

Views on Expected Returns

Description

Helper to construct views on expected returns.

Usage

view_on_mean(x, mean)## Default S3 method:view_on_mean(x, mean)## S3 method for class 'matrix'view_on_mean(x, mean)## S3 method for class 'xts'view_on_mean(x, mean)## S3 method for class 'tbl_df'view_on_mean(x, mean)

Arguments

x

An univariate or a multivariate distribution.

mean

Adouble for the target location parameter of the series inx.

Value

Alist of theview class.

Examples

library(ggplot2)# Invariantret <- diff(log(EuStockMarkets))n   <- nrow(ret)# View on expected returns (here is 2% for each asset)mean <- rep(0.02, 4)# Prior probabilities (usually equal weight scheme)prior <- rep(1 / n, n)# Viewviews <- view_on_mean(x = ret, mean = mean)views# Optimizationep <- entropy_pooling(p = prior, Aeq = views$Aeq, beq = views$beq, solver = "nlminb")autoplot(ep)# Probabilities are twisted in such a way that the posterior# `mu` match's exactly with previously stated beliefsffp_moments(x = ret, p = ep)$mu

Views on Relative Performance

Description

Helper to construct views on relative performance of assets.

Usage

view_on_rank(x, rank)## Default S3 method:view_on_rank(x, rank)## S3 method for class 'matrix'view_on_rank(x, rank)## S3 method for class 'xts'view_on_rank(x, rank)## S3 method for class 'tbl_df'view_on_rank(x, rank)

Arguments

x

An univariate or a multivariate distribution.

rank

Ainteger with the assets rank (from the worst to the bestperformer).

Details

Ifrank = c(2, 1) it is implied that asset in the first column will outperformthe asset in the second column. For longer vectors the interpretationis the same: assets on the right will outperform assets on the left.

Value

Alist of theview class.

Examples

library(ggplot2)# Invariantsx <- diff(log(EuStockMarkets))prior <- rep(1 / nrow(x), nrow(x))# asset in the first col will outperform the asset in the second col (DAX will# outperform SMI).views <- view_on_rank(x = x, rank = c(2, 1))viewsep <- entropy_pooling(p = prior, A = views$A, b = views$b, solver = "nloptr")autoplot(ep)# Prior Returns (SMI > DAX)colMeans(x)[1:2]# Posterior Returns (DAX > SMI)ffp_moments(x, ep)$mu[1:2]

Views on Volatility

Description

Helper to construct views on volatility.

Usage

view_on_volatility(x, vol)## Default S3 method:view_on_volatility(x, vol)## S3 method for class 'matrix'view_on_volatility(x, vol)## S3 method for class 'xts'view_on_volatility(x, vol)## S3 method for class 'tbl_df'view_on_volatility(x, vol)

Arguments

x

An univariate or a multivariate distribution.

vol

Adouble for the target volatility structureof the series inx.

Value

Alist of theview class.

Examples

library(ggplot2)# Invariantret <- diff(log(EuStockMarkets))n   <- nrow(ret)# Expected a volatility 30% higher than historical averagevol <- apply(ret, 2, stats::sd) * 1.3# Prior Probabilitiesprior <- rep(1 / n, n)# Viewsviews <- view_on_volatility(x = ret, vol = vol)views# Optimizationep <- entropy_pooling(p = prior, Aeq = views$Aeq, beq = views$beq, solver = "nlminb")autoplot(ep)# Desired volatilityvol# Posterior volatility matches very closely with the desired volatilitysqrt(diag(ffp_moments(x = ret, p = ep)$sigma))

[8]ページ先頭

©2009-2025 Movatter.jp