Why is this utility function not picking up its penalty?

I was reading this seminal paper by Infanger. On page 40, Figure 11. was quite interesting. In particular I was interested in the top one, 19 Years and I wanted to reproduce this plot. To give some background: It's about utility maximization which should be solved by DP approach, i.e.

$$\max_{x_t,0\le t\le T} E[u(W_T)]$$

where $u$ is a utility function and $W_T$ is the wealth at time $T$. We want therefore to maximize terminal wealth. For the picture he uses the following "quadratic downside risk" function

$$u(W) = W - \frac{\lambda}{2}\max{(0,W_d-W)^2}$$

where $W_d$ is a target amound and $\lambda$ a scaling parameter. As wealth evolves via $W_{t+1} = W_t \cdot\langle x_t, R\rangle$ where $x_t$ are the allocation and $R$ the return, he writes down the Bellman equation of this problem:

$$V_{t}(W_t) = \max_{x_t}E[V_{t+1}(W_t\cdot \langle x_t, R\rangle)|W_t]$$ since I'm just interested in the final step, we have $V_T = u$ and the maximization problem I want to solve is $$V(W) = \max_{x}E[u(W\cdot \langle x, R\rangle)|W]$$ dropping the time $t$ index. I assumed (as Infanger did if I get him right), that $R$ are normally distributed. I use then Gauss-Hermite quadrature to approximate the expectation (see page 71 in this paper). $$V(W) = \frac{1}{\sqrt{\pi}}\max_{x}\sum_{i=1}^m w_i u(W(1+\hat{\mu}(x)+\sqrt{2}\hat{\sigma}(x)\cdot q_i))$$ where $\hat{\mu} = \langle \mu, x\rangle$ and $\hat{\sigma} = \sqrt{\langle x, \Sigma x\rangle}$ and $w_i$ are the Gauss-Hermite weights and $q_i$ the corresponding nodes.

I've coded a very simple and not optimized version to see if I get the desired picture.

first a picture of the utility function:

utility <- function(w){
K <- 100000
temp <- K-w
temp[temp<=0] <- 0
return(w - 1000*temp^2)
}

x <- seq(90000,120000,1000)
y <- utility(x)
plot(x,y,type="l") Now I just generated a sequences of $W$ and solved the above problem. The following code junk defines the covariance and expected return vector. The data is from the Infanger paper above.

wealth <- seq(50000,150000,5000)
mu <- c(0.108, 0.1037, 0.0949, 0.079, 0.0561)
cor <- matrix(c(1, 0.601, 0.247, 0.062, 0.094,
0.601, 1.0, 0.125, 0.027, 0.006,
0.247, 0.125, 1.0, 0.883, 0.194,
0.062, 0.027, 0.883, 1.0, 0.27,
0.094, 0.006, 0.194, 0.27, 1.0),
ncol=5, nrow=5,byrow=T)
std <- c(0.1572, 0.1675, 0.0657, 0.0489, 0.007)
temp <- std%*%t(std)
cov <- temp*cor


With this data at hand and a sequence of wealth (see above) I just run an optimization for each given wealth and store the solution (assuming no short selling). To solve the problem I used the Rsolnp package in R. It solves a minimization problem that's why I'm returning a $-1$ in the objective function below:

library(Rsolnp)
library(statmod)
obj <- function(x, currentWealth, mu, cov, r=0, nodes, weights){
drift <- sum((mu-r)*x)+r
cor <- sqrt(sum(x*(cov%*%x)))
term1 <- currentWealth*(1+drift)
term2 <- currentWealth*sqrt(2)*cor*nodes
return(-1/sqrt(pi)*sum(weights*utility(term1+term2)))
}

g_constraints <- function(x,currentWealth, mu, cov, r=0, nodes, weights){
return(sum(x))
}

x0 <- rep(0.25,length(mu))
weights <- gauss.quad(10,"hermite")$weights nodes <- gauss.quad(10,"hermite")$nodes
solmat <- matrix(NA, ncol=length(mu),nrow=length(wealth))
for(i in 1:length(wealth)){
sol <- solnp(pars=x0, fun = obj,
eqfun = g_constraints,
eqB = 1,
LB = rep(0, length(mu)),
UB = rep(1, length(mu)),
currentWealth = wealth[i], mu = mu, cov = cov,
r = 0, nodes = nodes, weights = weights)
solmat[i,] <- sol$pars x0 <- sol$pars
}
colnames(solmat) <- c("US Stock", "Int Stocks", "Corp Bonds", "Gvnt Bond", "Cash")
rownames(solmat) <- as.character(wealth)


However, I get a constant allocation where all money is invested in US Stocks. What's wrong with this and how do I get this chart from Infanger?

• Can you set your utility functions to $U(x) =x$ and check that you get the exact same answer? An algorithm is not wrong just because an algorithm is doesn't do what you expect. This way we can rule out one possibility before getting started... – will Jul 11 '17 at 6:03
• @will I've changed the utility function to the identity function and it still assigns all weight to the US Stock, i.e. the same result – math Jul 11 '17 at 6:36
• Can you change the penalty function to be $U(x) =1$, see if the algo then assigns the stocks evenly/randomly? – will Jul 11 '17 at 6:38
• @will then the solution is just the initial value of $\frac{1}{n}$ to the assets. In this case $0.2$ – math Jul 11 '17 at 6:41
• It will depend on your algo. If you end up with all in American equities again we can be suspicious. – will Jul 11 '17 at 6:42

The problem was a missing $W_t$ in the equation for correlation. I've updated the above code and did a rerun. We have now the following allocation which is much closer to the Infanger paper.

> solmat
US Stock  Int Stocks Corp Bonds    Gvnt Bond         Cash
50000  5.043872e-01 0.089871441 0.40574133 2.745030e-08 1.788550e-09
55000  4.050341e-01 0.090625580 0.50434024 2.744996e-08 1.788417e-09
60000  3.222272e-01 0.091347143 0.58642565 2.744972e-08 1.788325e-09
65000  2.521815e-01 0.091750138 0.65606829 2.744945e-08 1.788218e-09
70000  1.920722e-01 0.092167629 0.71576010 2.744928e-08 1.788152e-09
75000  1.401952e-01 0.092551771 0.76725296 2.744917e-08 1.788109e-09
80000  9.542976e-02 0.092965569 0.81160464 2.744770e-08 1.787578e-09
85000  5.926248e-02 0.085949047 0.77256462 2.548693e-10 8.222386e-02
90000  2.556086e-02 0.042435548 0.35690767 2.546768e-10 5.750959e-01
95000  5.666367e-07 0.007460414 0.02786258 1.724982e-12 9.646764e-01
1e+05  4.086260e-03 0.018524853 0.14238886 1.318764e-04 8.348682e-01
105000 4.229705e-03 0.021298108 0.33601246 1.319004e-04 6.383278e-01
110000 4.261748e-03 0.022020057 0.49978208 1.319047e-04 4.738042e-01
115000 1.014474e-02 0.042426599 0.62859439 3.219158e-03 3.156151e-01
120000 1.040348e-02 0.046451692 0.76095787 3.218435e-03 1.789685e-01
125000 1.308464e-02 0.132081249 0.79793418 3.218537e-03 5.368139e-02
130000 1.429210e-02 0.239570571 0.72417454 3.105067e-03 1.885772e-02
135000 1.471366e-02 0.313967841 0.65235180 3.064252e-03 1.590244e-02
140000 1.492658e-02 0.369961444 0.59727148 3.044485e-03 1.479601e-02
145000 1.506062e-02 0.416426483 0.55128612 3.032353e-03 1.419442e-02
150000 1.515564e-02 0.456708072 0.51130955 3.023891e-03 1.380285e-02