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
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).

Related Links

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

Categories

HOME
winapi
raspbian
backup
qpython3
wms
extract
angular2-directives
survival-analysis
search-engine
spring-cloud-contract
vsftpd
deeplearning4j
octopus-deploy
game-maker-studio-1.4
wysiwyg
image-recognition
react-leaflet
postmessage
rebol2
netezza
bar-chart
riak-ts
cairo
flexlm
shippo
uiautomator
servicemix
tarantool
binutils
searchbar
jflex
scalajs-react
auditing
metis
ui5
winscp
sharp
cell-array
encase
piecewise
mapguide
rhino
lego
initializer
topic-modeling
ntfs-mft
ddms
service-fabric-stateful
rich-text-editor
w3-total-cache
livefyre
infinite-scroll
project-template
cfeclipse
vst
visible
gameanalytics
pax-web
multifile-uploader
dojox.charting
pagekit
spring-lemon
dac
eml
loopj
anythingslider
schtasks.exe
p-np
visual-studio-code
uptodate
adodb
jai
client-side-validation
belongs-to
cocoascript
argument-passing
cppdepend
magic-numbers
sim900
execvp
dynamics-ax-2009
vertical-scrolling
ubuntu-11.10
css-tables
hobo
ubuntu-11.04
hinstance
posting
gethashcode
email-spec
mvccontrib-grid
msn
carbide
graph-layout
swfloader
gears
database-diagramming

Resources

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