Maximize Sharpe's ratio using scipy.minimze
<p>I'm trying to maximize Sharpe's ratio using scipy.minimize</p>

<p><img src="http://latex.codecogs.com/gif.latex?%5Cfrac%7BE_R%20-%20E_F%7D%7B%5Csigma_R%7D" alt="1"></p>

<p>I do this for finding CAPM's Security Market Line</p>

<p><img src="http://latex.codecogs.com/gif.latex?E%28R%29%20%3D%20E_F%20&plus;%20%5Cfrac%7BE_M%20-%20E_F%7D%7B%5Csigma_M%7D%20%5Csigma" alt="2"></p>

<p>So I have an equation:</p>

<p><img src="http://latex.codecogs.com/gif.latex?%5Cfrac%7BE_R%20-%20E_F%7D%7B%5Csigma_R%7D%20%5Crightarrow%20%5Cmax" alt="3"></p>

<p><img src="http://latex.codecogs.com/gif.latex?%5Csum%20x_i%20%3D%201" alt="4"></p>

<p>Optional (if short positions is not allowed):</p>

<p><img src="http://latex.codecogs.com/gif.latex?x_i%20%3E%200" alt="5"></p>

<p>So I'm trying solve this:
</p>

<pre><code>def target_func(x, cov_matix, mean_vector, virtual_mean):
    f = float(-(x.dot(mean_vector) - virtual_mean) / np.sqrt(x.dot(cov_matix).dot(x.T)))
    return f


def optimal_portfolio_with_virtual_mean(profits, virtual_mean, allow_short=False):
    x = np.zeros(len(profits))
    mean_vector = np.mean(profits, axis=1)
    cov_matrix = np.cov(profits)
    cons = ({'type': 'eq',
             'fun': lambda x: np.sum(x) - 1})
    if not allow_short:
        bounds = [(0, None,) for i in range(len(x))]
    else:
        bounds = None
    minimize = optimize.minimize(target_func, x, args=(cov_matrix, mean_vector, virtual_mean,), bounds=bounds,
                                 constraints=cons)
    return minimize
</code></pre>

<p>But I always get Success: False (iteration limit exceeded). I tried to set maxiter = 10000 option, but it didn't help.</p>

<p>I will be greatful for any help</p>

<p>P.S. I use python 2.7</p>

<p>I dont know why, but it works perfectly, when I replacing </p>

<pre><code>x = np.zeros(len(profits))
</code></pre>

<p>With</p>

<pre><code>x = np.ones(len(profits))
</code></pre>

python scipy mathematical-optimization nonlinear-optimization