Back to Community
Alternative to optimize?

I've read the forum posts about the reasons for not open sourcing optimize and the removal paper trading. Quantopian has built an amazing community and it's allowing people like myself to get started, which is amazing. Super appreciative for that.

Since my goal is to take an algorithm and deploy it to production to test and end to end flow I was wondering what's the best way to achieve something similar to optimize? Something that could be backtested in the IDE, and that could be used with pylivetrader for instance.

Watched most of the lectures, and looked through the mlfinlab library which has some optimization methods but I haven't been able to figure out a path forward yet.

Looking to do reimplement the code below. Any suggestions on how to start? Docs/tutorials would be super appreciated.

    # Our objective is to maximize alpha, where 'alpha' is defined by the negative of  
    # recent_returns_zscore factor.  
    objective = opt.MaximizeAlpha(context.adx_with_interest)  
    # We want to constrain our portfolio to invest a maximum total amount of money  
    # (defined by MAX_GROSS_EXPOSURE).  
    max_gross_exposure = opt.MaxGrossExposure(MAX_GROSS_EXPOSURE)  
    # We want to constrain our portfolio to invest a limited amount in any one  
    # position. To do this, we constrain the position to be between +/-  
    # MAX_POSITION_CONCENTRATION (on Quantopian, a negative weight corresponds to  
    # a short position).  
    max_position_concentration = opt.PositionConcentration.with_equal_bounds(  
        -MAX_POSITION_CONCENTRATION,  
        MAX_POSITION_CONCENTRATION  
    )  
    # Stores all of our constraints in a list.  
    constraints = [  
        max_gross_exposure,  
        max_position_concentration,  
    ]

    algo.order_optimal_portfolio(objective, constraints)  
7 responses

Here is an attempt to implement optimizer functions open source

Shiv's work is amazing, and I've started trying to understand the code.

Meantime I've stumbled upon libraries like pyportfolioopt which also looks interesting. Has anyone played around with it?

@Radu,

Just saw this post
https://www.quantopian.com/posts/zipline-backtest-benchmark-period-return-only-returns-0
which has

import pypfopt  

in it, which is described at:

PyPortfolioOpt

Looks good!
alan

This is amazing! Thanks Alan!

Argh, it doesn't work in Research.

InputRejected:
Importing EfficientFrontier from pypfopt.efficient_frontier raised an ImportError. No modules or attributes with a similar name were found. You tried to import a module that is not whitelisted on Quantopian. To see the list of allowed modules in the IDE, go to https://www.quantopian.com/docs/whitelists/ide-whitelist#algo-ide-whitelist. To see the list of additional modules allowed in Research, go to https://www.quantopian.com/docs/whitelists/research-whitelist#research-whitelist.

@Radu

I just posted an algorithm with all the optimization features I implemented. I hope it's of some use.

This is so cool! Thank you Shiv!