Back to Community
Anyone successfully used CVXPY?

I am getting an ImportError saying: cannot import binary_operators.

10 responses

Hi Pravin,

I haven't, but I'm interested. Please post here if you figure it out, and can provide an example.

Thanks,

Grant

Pravin -

I don't get an import error (but maybe I'd actually have to use CVXPY to see it?).

Is it working for you now?

Grant

Clone Algorithm
6
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: 5813028bb50307128be3f587
There was a runtime error.

Yes Grant. You have to use CVXPY for the error with an operation on variables. Will post an example once I get time.

Hi Pravin -

For this code, I'm getting:

ImportError: cannot import name add_expr  
There was a runtime error on line 18.  
import cvxpy as cvx  
def initialize(context):  
    context.spy = sid(8554)  
    schedule_function(run_optimization,date_rules.every_day(),time_rules.market_open())  
def run_optimization(context, data):  
    # example from http://www.cvxpy.org/en/latest/tutorial/intro/index.html

    # Create two scalar optimization variables.  
    x = cvx.Variable()  
    y = cvx.Variable()

    # Create two constraints.  
    constraints = [x + y == 1,  
                   x - y >= 1]

    # Form objective.  
    obj = cvx.Minimize(cvx.square(x - y))

    # Form and solve problem.  
    prob = cvx.Problem(obj, constraints)  
    prob.solve()  # Returns the optimal value.  
    print "status:", prob.status  
    print "optimal value", prob.value  
    print "optimal var", x.value, y.value  
Clone Algorithm
6
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: 581b033688ff5111b119dd7d
There was a runtime error.

I sent an e-mail request to Quantopian support, and will report back if I hear anything. Maybe more than import cvxpy as cvx is required for it to work?

Thanks Grant. I hope they respond.

Hi Grant/Pravin,

Looks like there's an issue with how some of CVXPY's internals interact with the backtesting sandbox. I'm looking into the issue now. Sorry for the delayed response.

  • Scott
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.

Hi Grant/Pravin,

The issues with CVXPy in the backtester should be fixed as of today. Let us know if you still run into issues.

  • Scott

Thanks Scott.

Here's a working example.

Clone Algorithm
6
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: 5826e008adeda3132de469db
There was a runtime error.