Generates scenarios from the normal distribution that exactly matches the first two moments.

match_normal(mu, sigma, n)

Arguments

mu

A double with the location parameter.

sigma

A variance-covariance matrix the dispersion parameter.

n

An integer with the number of scenarios to be generated.

Value

#TODO

See also

Examples

x     <- diff(log(EuStockMarkets))
mu    <- colMeans(x)
sigma <- cov(x)
match_normal(mu, sigma, 10)
#> # A tibble: 10 × 4
#>         DAX       SMI      CAC      FTSE
#>       <dbl>     <dbl>    <dbl>     <dbl>
#>  1 -0.00444 -0.00630  -0.0172  -0.000496
#>  2  0.00475  0.0166    0.00285  0.00469 
#>  3  0.0110   0.00571   0.0153   0.0155  
#>  4 -0.0166  -0.00927  -0.00688 -0.00664 
#>  5  0.00966  0.00178   0.00453 -0.00394 
#>  6  0.00574  0.00793   0.0181   0.00136 
#>  7 -0.00344 -0.0150   -0.00197 -0.00383 
#>  8 -0.00974 -0.00408  -0.0144  -0.0147  
#>  9  0.0179   0.0109    0.00776  0.00751 
#> 10 -0.00835 -0.000141 -0.00366  0.00481 

# correlation structure is similar
cor(x)
#>            DAX       SMI       CAC      FTSE
#> DAX  1.0000000 0.7031219 0.7344304 0.6394674
#> SMI  0.7031219 1.0000000 0.6160454 0.5847791
#> CAC  0.7344304 0.6160454 1.0000000 0.6485679
#> FTSE 0.6394674 0.5847791 0.6485679 1.0000000
cor(match_normal(mu, sigma, 10000))
#>            DAX       SMI       CAC      FTSE
#> DAX  1.0000000 0.7031219 0.7344304 0.6394674
#> SMI  0.7031219 1.0000000 0.6160454 0.5847791
#> CAC  0.7344304 0.6160454 1.0000000 0.6485679
#> FTSE 0.6394674 0.5847791 0.6485679 1.0000000

# as the location parameters
mu
#>          DAX          SMI          CAC         FTSE 
#> 0.0006520417 0.0008178997 0.0004370540 0.0004319851 
colMeans(match_normal(mu, sigma, 10000))
#>          DAX          SMI          CAC         FTSE 
#> 0.0006520417 0.0008178997 0.0004370540 0.0004319851