I have historical adjusted closing prices for $k$ stocks over $n$ days. I have a budget of $B$ dollars, and I'd like to choose allocations for each of the stocks, $a_{1:k}$, such that I maximize the Sharpe ratio for this time period.
More formally:
\begin{align*} \text{given } & c_{i, j} \text{ for } i=1...n, \; j=1...k && \text{adjusted close of stock } j \text{ on day } i \\ \text{and } & B && \text{total budget} \\ \text{find } & a_{1:k} && \text{allocations for each stock} \\ \text{that maximize } & s = \frac{\mu}{\sigma} && \text{Sharpe ratio} \\ \text{where } & \mu = \frac{1}{n} \sum_{i=1}^n r_i && \text{sample mean of the daily returns} \\ & \sigma = \sqrt{\frac{1}{n}\sum_{i=1}^n (r_i - \mu)^2} && \text{sample standard deviation of the daily returns} \\ & r_1 = 0 && \text{return on day one is zero} \\ & r_i = \frac{p_i}{p_{i-1}} - 1 \;\; \text{for } i=2...n && \text{percent change in portfolio value on day } i \\ & p_i = a^{\top} c_i && \text{portfolio value on day } i \\ \text{subject to } & a_j \geq 0 \text{ for } j = 1...k && \text{only non-negative allocations for each stock} \\ & \sum_{j=1}^k a_j = B && \text{must use total budget} \end{align*}
One way I tried solving this was simply setting $a_{1:k} = B \times \texttt{softmax}(w_{1:k})$ or $a_{1:k} = B \times \frac{\texttt{relu}(w_{1:k})}{\texttt{sum}(\texttt{relu}(w_{1:k}))}$, for some latent variables $w_{1:k}$, and then running gradient ascent using TensorFlow. This works well in practice, but I'm wondering if there is a better way (i.e., something with guaranteed convergence to the global maximum).