### python

#### Maximise the Slope using CVXPY

```I'm trying to use CVXPY to maximise the Sharpe Ratio of a stock portfolio.
The variable w is a portfolio weight vector, Sigma is an nxn correlation matrix, mu - is the average return of each portfolio stock, and rf - the risk-free rate (a scalar value).
At first, I tried to construct the problem as: Maximise((ret-rf)/(sqrt(risk))), which raised a TypeError: Can only divide by a scalar constant. I tried bypassing this issue by taking the log of the value I'm trying to maximise, however now I am getting an "invalid syntax" raised by 'prob.solve()'. I'm pretty sure that the issue arising from the maximisation formula, but I'm not sure what it is.
(I've tried both CVXPY log formulas, namely log_det() and log_sum_exp())
Here's the code below:
from cvxpy import *
def portfolio(mu, Sigma, rf):
n = len(mu)
w = Variable(n)
ret = mu.T*w
prob = Problem(Maximize(log_det(ret-rf)-log_det(sqrt(risk)),
[sum_entries(w) == 1])
prob.solve()
return w.value
```
```I believe this is not convex. From what I understand there are several ways to attack this problem
Use a general purpose NLP solver (this is the method I used)
Trace the efficient frontier to find the point on this frontier with the best Sharpe Ratio
Under some conditions, this problem can be transformed into a convex QP (see e.g. Gerard Cornuejols, Reha Tütüncü, Optimization Methods in Finance, 2007).```

### Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization