Suppose you've written an algorithm that's developed a signal (for example, a Pipeline Factor) that's predictive of forward returns over some time horizon. You might think that the hard is over, but you're still left with the daunting task of translating your signal into an algorithm that can turn a profit while also managing risk exposures.

Traditionally in quantitative finance, the solution to the problem of maximizing returns while constraining risk has been to employ some form of Portfolio Optimization, but performing sophisticated optimizations is challenging on today's Quantopian.

Python libraries like scipy.optimize, CVXOPT, and CVXPY (all available on Quantopian today) provide generic tools for solving optimization problems. These libraries are powerful and flexible, but it takes significant expertise to convert the data structures available on Quantopian into the specific formats understood by these libraries.

Algorithm authors who want to perform even simple optimizations spend much of their time to figuring out how to encode conceptually simple ideas like "constrain gross leverage" into complicated matrices that are hard to interpret and hard to debug when something goes wrong.

The open source Python ecosystem already provides excellent implementations of the algorithms needed to implement a quality portfolio optimization library. What's missing is an interface that maps domain concepts from finance onto the low-level primitives exposed by existing libraries.

Today we're announcing ** quantopian.experimental.optimize**, a suite of new tools designed to make portfolio optimization on Quantopian more accessible to algorithm authors. As the name suggests, all the functions and classes currently available are

**experimental**and should be considered subject to change at any time. We are releasing these APIs early in the development cycle so that we can gather feedback about how to make them as useful as possible to the community when the time comes for a stable release.

The `optimize`

module has three major components in this release:

`calculate_optimal_portfolio`

, a top-level entrypoint.`Objective`

classes, representing functions to be minimized or maximized by the optimizer.`Constraint`

classes, representing constraints to be enforced by the optimizer.

To run a portfolio optimization, you call `calculate_optimal_portfolio`

and provide three values:

- An
`Objective`

to optimize. - A list of
`Constraints`

to enforce. - A pandas Series containing weights for the current portfolio. The index of the current portfolio series defines the assets that are allowed in the target portfolio.

The attached notebook provides a detailed walkthrough of the new API. There's still a lot of work to do and many questions to answer before we move beyond experimental status. With help from the Quantopian community, we hope to answer these questions in the coming weeks. I'm excited about the opportunities that optimization creates for algorithm authors, and I look forward to hearing feedback and to seeing what the community builds with these tools. **The optimization API is only available in notebooks for this release.** Work is currently ongoing to make optimization available in the backtester. See the **Next Steps** section at the bottom of this notebook for more details.

Happy Optimizing!