Maximizing returns - A Bayesian approach I want to design a Bayesian model for a simple asset allocation problem.
Say I can buy $a_i$ amounts of $N$ assets. The return values of these assets are given by  random variables $r_i$ with known posteriors $p(r_i | \textbf{x})$, given some known data about the market $\textbf{x}$.
I define my utility function (i.e. negative loss) as the total return of my portfolio:
Total utility = $U(\textbf a, \textbf r) = \textbf{a} \cdot \textbf{r} = \sum_i a_i r_i$
where, sticking to the bayesian notation, $\textbf{a}$ are my actions, and $\textbf{r}$ are the random returns.  
I would like to maximize the total expected utility using bayesian decision theory. 
From what I understand, I could write this as follows:
$\underset{\textbf{a}}{\operatorname{argmax}}  E\{U(\textbf{a} ,\textbf{r}) | \textbf{x}\}  =  \underset{\textbf{a}}{\operatorname{argmax}} \int   (\textbf{a} \cdot \textbf{r}) \; p(\textbf{r})\;d  \textbf{r}$
Assuming that 


*

*$\sum_i a_i \le C$ is a constraint so that there is a limit in how many assets in total I can buy

*I can only buy (not sell) assets, i.e. $a_i \ge 0$.


My questions are: 


*

*How can I modify this formulation to penalize risk (uncertainty) in a principled manner ? (i.e. penalize the action of buying assets with high variance/entropy/uncertainty)

*What type of optimization problem is this? What solvers are applicable to this problem? (assuming a finite number of assets $N$)

*Are there readily available libraries for solving this problem?  Perhaps in PyMC.?


As a bonus extension:


*

*How can I modify this formulation to add the fact that there is a limited random supply $q_i$ of asset $i$ that follows  $p(q_i|\textbf{x})$?

 A: As a general principle, risk-responsiveness is incorporated into an economic analysis through the shape of the utility function.  In your analysis you have a utility function $U$ that operates on the total return $\boldsymbol{a} \cdot \boldsymbol{r}$ to produce the utility of that return.  Since your utility function is linear with respect to the return, it is risk-neutral.  Optimisation of this utility function will place the maximum allowable investment in the asset with the highest expected return, then the maximum allowable investment in the asset with the next highest expected return, and so on.
If you would like to change to a risk-averse position, you should change the utility function to some concave function.  For example, if you would like to use a utility function with constant relative-risk aversion you could use the isoelastic utility function:
$$U(x) = \left\{ \begin{matrix} \frac{x^{1-\phi}-1}{1-\phi} & & \text{for } \phi \neq 1 \\
\ln(x) & & \text{for } \phi = 1 \end{matrix} \right\} $$
where the parameter $\phi$ is the coefficient of relative-risk aversion.  You could then formulate your problem as a constrained non-linear optimisation problem, and solve it using either Lagrangian optimisation or penalty methods.  The concavity of the utility function will then militate against "putting all your eggs in one basket", and the optimum will tend to involve a greater asset spread.
