I've been working on making an asset allocation model that requires I price a lot of financial instruments (i.e. bonds, options) and optimize based on a certain constraint. I was originally doing this in Matlab, but am now looking to switch it to Python. Is there a package that would be equivalent to the Matlab Financial Toolbox in Python? I've read about many of them (i.e. vollib, QuantLib/PyQL), but I'm not sure which one is the most trusted / popular / commonly used.


I took a quick look at Matlab's Financial Toolbox and attempted to map the features to corresponding Python packages –

For asset allocation, portfolio optimization, and risk analytics:

  • Standard packages such as scipy provide a large number of optimizers that should suit your needs. There are also pre-canned packages that do portfolio optimizations more directly, but I don't have much experience with them.
  • Specialized packages such as pyfolio and alphalens provide a ton of functions that make performance and risk analytics super easy.
  • For some risk applications, you may also find Copulalib useful.

For pricing instruments -

  • As you've already mentioned, Quantlib is almost certainly the best open-source solution out there and there are a few ways to make Quantlib accessible from Python (e.g., QuantLib-Python).
  • If you have other C++ code that you already use for pricing, take a look at Boost Python.

For time series analysis:

  • A combination of pandas and statsmodels is the gold standard and should be more than sufficient for most purposes. The former provides a large collection of utilities for working with time series (DataFrame, Series, Panel, etc.), while the latter provides a comprehensive library for running anything for linear regressions to sophisticated Dynamic Factor Models.
  • pandas-datareader has many pre-built functions for retrieving financial and economic data from public sources.
  • I've also found arch quite nifty for running GARCH-type models.

For Technical Analysis:

  • ta-lib has an easy-to-use Python wrapper.

For Financial Charts:

  • matplotlib is the core library. pandas has built-in plotting functions that use matplotlib to make many chart types very easy to work with.
  • For prettier charts, also check out seaborn.

For SDEs:

  • I have yet to run into problems can't solved by scipy.

And for general numeric computing, you need:

  • numpy for numerical computing;
  • scikit-learn for machine learning.
  • sympy for symbolic mathematics.

To get started, check out Anaconda from Continuum Analytics. They package all the various scientific and statistical Python libraries under one convenient installer. Some of these packages can be challenging to install if you try to install them piecemeal. If you've got Anaconda you've more or less got the full financial toolbox for Python and then you can start exploring the individual packages. Anaconda provides a list of installed packages with links to the documentation for each package: https://docs.continuum.io/anaconda/pkg-docs.html

If you want to start with a specific library provided by Anaconda, I would suggest pandas. It farms out to many other libraries under the hood for calculations, but it's a pretty ubiquitous top-level library (i.e. library the user interacts with) when it comes to quantitative finance in Python.

  • $\begingroup$ The only reference I see to anything financial in the list of packages you linked is Quandl, and that's data, not analytics. "More or less the full financial toolbox" seems a bit of an exaggeration... $\endgroup$ May 17 '17 at 20:58
  • $\begingroup$ @LuigiBallabio, according to its website, MatLab Financial Toolbox "provides functions for mathematical modeling and statistical analysis of financial data." That's also what the libraries packaged under Anaconda do (though they can also be used for non-financial data). $\endgroup$ May 18 '17 at 0:21
  • $\begingroup$ To clarify, the MatLab Financial Toolbox provides functions that do the modeling and analysis directly, i.e. I give it necessary market data and it will price an option for me. The Anaconda libraries are more general, and I would need to write my own functions for all the financial instrument pricing. I'm looking for a Python package that would do that all for me. $\endgroup$
    – john
    May 18 '17 at 2:11
  • $\begingroup$ I see. If the emphasis is on analysis, then yes, your "more or less" works. $\endgroup$ May 18 '17 at 7:39
  • $\begingroup$ pandas has a few utils for pulling remote data: pandas-datareader.readthedocs.io/en/latest/remote_data.html $\endgroup$ May 18 '17 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.