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 risk = quad_form(w, Sigma) 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).
Flask-strange routing issue
Upgrade path for re-usable apps with South AND django 1.7 migrations
Making scikit-learn train on all training data after cross-validation
matplotlib does not display latex fonts correctly
How to use py2exe with third-party libraries
How to extract two numbers from input line and tab delimit them?
Copy selected lines of text from one file to another with command line argument with or without spaces
TypeError: can't use a string pattern on a bytes-like object
Why does my code skip to the end and ignore parts of my code?
Matplotlib scroll_event not working with GTK3Agg backend
SELECT conditions on relations with SQLAlchemy
longest and shortest curves selected
Get the key with the maximum nested key in a python dictionary
Python fermat program only works for low numbers
How to create list of all parts of elements in NumPy array (Python list)
Encoding issue for Python tool Unidecode on CL