This function solves the entropy minimization problem with equality and inequality constraints. The solution is a vector of posterior probabilities that distorts the least the prior (equal-weights probabilities) given the constraints (views on the 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
A
character
. 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-negativity
constraint for probabilities, which is done automatically by entropy_pooling
.
For the arguments accepted in ...
, please see the documentation of
nlminb
, solnl
, nloptr
and the examples bellow.
Examples
# setup
ret <- 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)
# View
views <- view_on_mean(x = ret, mean = mean)
# Optimization
ep <- entropy_pooling(
p = prior,
Aeq = views$Aeq,
beq = views$beq,
solver = "nlminb"
)
ep
#> <ffp[1859]>
#> 0.0002626139 1.758547e-05 0.0003425248 8.978951e-05 6.135271e-06 ... 0.002028742
### Using the ... argument to control the optimization parameters
# nlminb
ep <- entropy_pooling(
p = prior,
Aeq = views$Aeq,
beq = views$beq,
solver = "nlminb",
control = list(
eval.max = 1000,
iter.max = 1000,
trace = TRUE
)
)
#> 0: 0.36787944: 0.00000 0.00000 0.00000 0.00000 0.00000
#> 1: 0.058529435: -0.0197601 -0.0196991 -0.0198392 -0.0198411 -0.632121
#> 2: 0.025855388: -0.0580704 -0.0577859 -0.0584405 -0.0584522 -1.23661
#> 3: -0.0039314351: -0.0601613 -0.0598133 -0.0606155 -0.0606329 -0.960871
#> 4: -0.0062039413: -0.0798744 -0.0793660 -0.0805394 -0.0805680 -0.994812
#> 5: -0.010307925: -0.141800 -0.140779 -0.143140 -0.143210 -1.03756
#> 6: -0.019570052: -0.316315 -0.313846 -0.319572 -0.319772 -1.09779
#> 7: -0.043181545: -0.819004 -0.812370 -0.827790 -0.828413 -1.19256
#> 8: -0.10177381: -2.16618 -2.14843 -2.18979 -2.19169 -1.33121
#> 9: -0.24450670: -5.57753 -5.53182 -5.63866 -5.64428 -1.50627
#> 10: -0.56153114: -13.4230 -13.3136 -13.5703 -13.5859 -1.63871
#> 11: -0.94888011: -21.2678 -21.0960 -21.5008 -21.5292 -1.52434
#> 12: -1.6484869: -36.0658 -35.7809 -36.4590 -36.5217 -0.820266
#> 13: -1.9955215: -36.7399 -36.4578 -37.1372 -37.2208 -0.187631
#> 14: -2.0494729: -39.7300 -39.4294 -40.1580 -40.2589 0.0440528
#> 15: -2.0751860: -43.2371 -42.9197 -43.6984 -43.8330 0.347319
#> 16: -2.0765785: -43.3910 -43.0785 -43.8509 -44.0018 0.399315
#> 17: -2.0767596: -43.4590 -43.1528 -43.9161 -44.0850 0.417657
#> 18: -2.0769135: -43.4939 -43.1979 -43.9459 -44.1427 0.427405
#> 19: -2.0775638: -43.5805 -43.3378 -44.0053 -44.3450 0.453965
#> 20: -2.0790107: -43.6821 -43.5731 -44.0377 -44.7336 0.491159
#> 21: -2.0829909: -43.8109 -44.0959 -43.9615 -45.7033 0.557356
#> 22: -2.0929607: -43.8973 -45.2158 -43.5082 -47.9880 0.666737
#> 23: -2.1182943: -43.7455 -47.7872 -41.9313 -53.6180 0.856961
#> 24: -2.1798935: -42.8042 -53.7356 -37.3807 -67.2880 1.19084
#> 25: -2.3151349: -39.7853 -67.2182 -25.7118 -99.2417 1.77838
#> 26: -2.4186844: -33.9735 -87.9670 -5.96992 -149.692 2.46898
#> 27: -2.4900606: -34.8994 -78.3218 -12.4289 -128.179 1.94373
#> 28: -2.5775299: -32.6956 -71.8257 -12.4512 -116.778 1.27932
#> 29: -2.6068010: -29.5070 -70.8620 -8.07330 -118.207 0.891005
#> 30: -2.6099515: -29.4968 -73.2253 -6.82148 -123.235 1.04082
#> 31: -2.6100208: -29.4780 -72.9504 -6.93546 -122.666 1.03080
#> 32: -2.6100410: -29.4209 -72.8983 -6.87400 -122.608 1.02619
#> 33: -2.6101039: -29.2902 -72.8182 -6.70931 -122.539 1.01806
#> 34: -2.6102275: -29.1332 -72.7544 -6.48708 -122.475 1.00891
#> 35: -2.6105851: -28.8556 -72.7115 -6.03600 -122.370 0.993029
#> 36: -2.6114768: -28.4424 -72.8223 -5.21726 -122.217 0.969753
#> 37: -2.6137938: -27.8170 -73.4617 -3.57894 -121.995 0.935343
#> 38: -2.6195151: -26.9722 -75.6085 -0.279708 -121.712 0.891008
#> 39: -2.6326800: -26.0838 -81.5175 6.28270 -121.447 0.850300
#> 40: -2.6574796: -25.9140 -94.4837 17.5717 -121.450 0.861513
#> 41: -2.6885771: -27.7660 -113.260 30.2660 -122.048 0.997768
#> 42: -2.7143812: -31.4827 -126.678 35.1710 -123.157 1.23449
#> 43: -2.7264724: -34.9709 -129.463 31.4215 -124.392 1.43257
#> 44: -2.7267015: -35.0093 -128.332 30.3531 -124.673 1.42848
#> 45: -2.7267088: -34.9401 -128.047 30.2254 -124.693 1.42253
#> 46: -2.7267089: -34.9366 -128.034 30.2215 -124.681 1.42188
#> 47: -2.7267092: -34.9311 -128.010 30.2108 -124.656 1.42080
#> 48: -2.7267098: -34.9246 -127.984 30.1979 -124.626 1.41959
#> 49: -2.7267116: -34.9094 -127.936 30.1711 -124.571 1.41737
#> 50: -2.7267161: -34.8779 -127.867 30.1240 -124.484 1.41395
#> 51: -2.7267279: -34.8046 -127.763 30.0309 -124.338 1.40837
#> 52: -2.7267578: -34.6340 -127.626 29.8448 -124.104 1.39970
#> 53: -2.7268314: -34.2361 -127.485 29.4630 -123.738 1.38694
#> 54: -2.7269947: -33.3736 -127.469 28.7210 -123.237 1.37141
#> 55: -2.7272818: -31.8438 -127.862 27.5310 -122.780 1.36158
#> 56: -2.7275727: -30.3208 -128.700 26.4829 -122.800 1.37111
#> 57: -2.7277430: -29.4401 -129.659 26.0224 -123.331 1.39753
#> 58: -2.7277672: -29.5781 -129.917 26.2155 -123.680 1.41099
#> 59: -2.7277689: -29.7310 -129.932 26.3474 -123.771 1.41396
#> 60: -2.7277690: -29.7537 -129.923 26.3637 -123.774 1.41397
#> 61: -2.7277690: -29.7549 -129.922 26.3644 -123.773 1.41395
ep
#> <ffp[1859]>
#> 0.0002626139 1.758547e-05 0.0003425248 8.978951e-05 6.135271e-06 ... 0.002028742
# nloptr
ep <- entropy_pooling(
p = prior,
Aeq = views$Aeq,
beq = views$beq,
solver = "nloptr",
control = list(
xtol_rel = 1e-10,
maxeval = 1000,
check_derivatives = TRUE
)
)
#> Checking gradients of objective function.
#> Derivative checker results: 0 error(s) detected.
#>
#> eval_grad_f[ 1, 1 ] = 1.976013e-02 ~ 1.975961e-02 [2.616200e-05]
#> eval_grad_f[ 2, 1 ] = 1.969911e-02 ~ 1.969862e-02 [2.477148e-05]
#> eval_grad_f[ 3, 1 ] = 1.983922e-02 ~ 1.983871e-02 [2.576603e-05]
#> eval_grad_f[ 4, 1 ] = 1.984108e-02 ~ 1.984060e-02 [2.417970e-05]
#> eval_grad_f[ 5, 1 ] = 6.321206e-01 ~ 6.321204e-01 [2.737810e-07]
#>
ep
#> <ffp[1859]>
#> 0.0002626141 1.75855e-05 0.0003425251 8.978965e-05 6.135285e-06 ... 0.002028743