Back to Community
Deprecation warning for universe parameter in order_optimal_portfolio

When I run the long-short equity example algorithm from Lecture 39, I get the following deprecation warning:

Line 245: The universe parameter to order_optimal_portfolio is deprecated. It will be ignored.

Will the 'universe' parameter of the order_optimal_portfolio function really be deprecated? What is supposed to replace it? The link included with the warning didn't help.

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: 595165b0507fee4da49cdd90
There was a runtime error.
10 responses

I also saw this and was pretty confused. Hopefully Quantopian can shed some light on this!

Jamie mentioned before that this parameter is not really needed as you pass the target weights already.

Yeah it seems redundant. But are algorithms running that have that line going to raise an error? Or is it just ignored so it shouldn't affect anything that's currently live trading (or in the contest)?

Hi folks,

Sorry for the lack of advanced warning on this one. The short answer is that the universe parameter was proving to cause more problems than it was solving. Moving forward live algos (such as those in the contest) that use it will not error, though the warning will be thrown.

All the best,
Josh

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.

Ok thanks. Maybe it would be good to correct the example algo.

Sorry for the confusing UX here; the warning pointing to the old Q2 migration page is just a bug. We're working on fixing it.

As for the actual content of the warning, we are indeed deprecating the universe parameter from order_optimal_portfolio. Previously, universe was used to tell the optimizer which assets should considered as possible candidates for new orders. In practice, there was basically always one "correct" answer for universe, which was "the assets referenced by your objective, unioned with assets in which you currently have a position". A common usage pattern, however, was to pass many more assets (e.g., the index of a pipeline_output call, which might be all the assets in existence!), which then produced unexpected behavior, such as the optimizer fixing a violated constraint by spreading a large number of very small orders across all the extra assets passed in universe.

On the latest release, we're now ignoring, universe, and instead always using the union of the assets referenced by your objective and the assets in which you currently hold a position.

For example, if your algorithm holds a position in AAPL, and you want to sell out of that position and buy MSFT and TSLA instead, previously the correct thing to do would have been:

objective = opt.TargetPortfolioWeights({MSFT: 0.5, TSLA: 0.5, AAPL: 0.0})  
constraints = []  
universe = [MSFT, TSLA, AAPL]  
order_optimal_portfolio(objective, constraints)  

With the latest update, the equivalent invocation is simpler and less error-prone:

objective = opt.TargetPortfolioWeights({MSFT: 0.5, TSLA: 0.5, AAPL: 0.0})  
# universe is inferred from objective  
order_optimal_portfolio(objective, constraints)  
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 Scott,

What if the current weight in AAPL is 1.0, and then I do:

objective = opt.TargetPortfolioWeights({MSFT: 0.5, TSLA: 0.5})  
# universe is inferred from objective  
order_optimal_portfolio(objective, constraints)  

Would AAPL be set to zero (minimizing the distance between {MSFT: 0.5, TSLA: 0.5} and the new portfolio)?

Also, do you have the optimization API in a public github repository yet? It would be nice to see what you are doing under the hood.

I second Grant's request to make the optimization API code available.

Quadratic objective functions would be useful as well (to construct minimum variance portfolios, for instance).

Would AAPL be set to zero (minimizing the distance between {MSFT: 0.5, TSLA: 0.5} and the new portfolio)?

Correct. TargetPortfolioWeights assigns a target of 0.0 for any asset that's in the universe but not given a target.

Also, do you have the optimization API in a public github repository yet? It would be nice to see what you are doing under the hood.

Not yet. I'm currently working on stabilizing the existing API (moving it out of quantopian.experimental, cleaning up some inconsistent naming choices, adding deprecated aliases for backwards compatibility, etc). Stay tuned for an announcement in that regard Soon™.

Will algorithms that enter contest break if the existing optimize API is moved out of quantopian.experimental or will the deprecated aliases ensure they continue to function same as they do today?
Do you have versioning support for the optimize code that we can switch between (say 1.0,2.0 etc.)