Back to Community
help w/ CVXOPT

I get a build error for this line:

P = matrix(np.diag([1,0]), tc=’d’) --> SyntaxError: invalid syntax

Any idea what I'm doing wrong?

# From "Quadratic Programming with Python and CVXOPT," https://courses.csail.mit.edu/6.867/wiki/images/a/a7/Qp-cvxopt.pdf

import numpy as np  
from cvxopt import matrix, solvers

def initialize(context):  
    context.spy = sid(8554) # SPY

def handle_data(context, data):  
    # Define QP parameters (directly)  
    # P = matrix([[1.0,0.0],[0.0,0.0]])  
    # q = matrix([3.0,4.0])  
    # G = matrix([[-1.0,0.0,-1.0,2.0,3.0],[0.0,-1.0,-3.0,5.0,4.0]])  
    # h = matrix([0.0,0.0,-15.0,100.0,80.0])  
    # Define QP parameters (with NumPy)  
    P = matrix(np.diag([1,0]), tc=’d’)  
    q = matrix(np.array([3,4]), tc=’d’)  
    G = matrix(np.array([[-1,0],[0,-1],[-1,-3],[2,5],[3,4]]), tc=’d’)  
    h = matrix(np.array([0,0,-15,100,80]), tc=’d’)  
    # Construct the QP, invoke solver  
    sol = solvers.qp(P,q,G,h)  
    # Extract optimal value and solution  
    x = sol[’x’] # [7.13e-07, 5.00e+00]  
    po = sol[’primal objective’] # 20.0000061731  
    print 'x = ' + str(x)  
    print 'po = ' + str(po)  
14 responses

Those single quotes seem like Windows "smart"--eh-hem--quotes, (I use Notepad Replace-All to straighten them up).

Thanks! Now I'm getting this error:

sol = solvers.qp(P,q,G,h) --> Runtime exception: ImportError: cannot import name misc

Possible workaround here and then this says have to skip the first day.

Thanks again. I'll play around with it. Hey Q, mysterious build errors suck!

O.K. It now runs with the work-around posted by Richard Prokopyshen on https://www.quantopian.com/posts/cvxopt-module.

So, Quantopian support, what's the story here? I'd like to use the module, but I need to skip the first bar of the day? Doesn't sound correct. If you can provide any guidance, it would be most appreciated.

Thanks,

Grant

Clone Algorithm
3
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 555bcf5f24963a10a52b8f03
There was a runtime error.

Grant, if I understand correctly you want to implement OLMAR strategy and its relatives using CVXOPT. Personally I felt that CVXOPT is a steep learning curve and difficult to use which is why I requested for CVXPY. With CVXPY optimization problems can be easily specified and we can focus on trading algorithms instead of wasting time formulating optimization problems. I hope I made the case for CVXPY and request you to push Q for this module as well.

CVXOPT hasn't been integrated into the IDE/research yet. Once it's done we'll let everyone know!

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Sigh... It was announced as a module on Dec 10, 2014 by Karen Rubin (see https://www.quantopian.com/posts/cvxopt-module). It is now May 20, 2015. It's wonderful that you released it, but if bugs are found, shouldn't they be fixed? Does something else need to be fixed that is holding up getting CVXOPT fully integrated? What's the story?

You might consider that if you are going to release modules, they need to be fully supported. What if someone unknowingly grabs a module that has not been fully integrated, uses it to trade real money, and loses money because the module had a known bug that wasn't fixed? I realize that overall, Quantopian technically is still in "beta" but it's kinda scary that a module could be released and not be fully integrated and de-bugged after 5 months. Perhaps this is an isolated and innocuous case, but it does appear to set a bad precedent.

Sorry for the venting, but I'm just not following what happened here? Did CVXOPT just slip off the radar screen?

I can see how Thomas' and my comments could get misconstrued in that thread. The short version is that we tried to implement the module, but there were some bugs. We then paused on that work. Somewhere down the line, parts of the module appeared to be working, as a side-benefit of active work we're doing on the platform. So the module isn't yet fully supported - there may be parts that work, but I haven't dug into them yet. When CVXOPT is fully functional, we'll let you know.

Sigh... Well, presumably you released the module because you'd like it to work and have users apply it. I still don't follow, but that's o.k. I should be able to use it with the work-around.

Hi Alisa,

I know you said above, "When CVXOPT is fully functional, we'll let you know" but it's been a month and I hadn't heard anything, so I thought I'd check back. Has there been any work in getting it fully functional and supported?

At some point, I'd like to start using it, but if it is not fully supported as an importable module, I'm kinda reluctant.

Grant

There's no new news on this front, we haven't been working on this module. We've been working on other features and when CVXOPT is fully supported, I'll make sure to post back here.

Hi Alisa,

Thought I'd check back, to see if maybe you've wrapped up the other features, and got to this (assuming it is still on the list). Any progress?

Kinda weird that you'd release it as a module back in Dec. 2014, and it is still hanging out there incomplete. Was there a big shift in priorities? A re-direction of resources?

Grant