Getting started with open source for quantitative finance
Twenty years ago, quantitative research mostly required expensive commercial software. Today almost every step, from downloading data to pricing derivatives and training models, can be done with free, open-source tools. The difficulty has shifted from access to choice. This guide sets out the main options and how to start without getting lost.
Choosing a language
Python is the default for most new quantitative work. Its scientific stack is mature, it is used across banks, hedge funds and universities, and it connects to almost everything: databases, broker APIs, machine-learning frameworks and cloud services. Its weakness is raw speed in pure Python loops, which is usually addressed by vectorised libraries or compiled extensions.
R remains strong in statistics and econometrics, with a deep library of packages on CRAN, many written by the academics who developed the methods. Its time-series and performance-analysis packages are excellent for research and reporting.
Julia, first released in 2012, aims to combine the convenience of a high-level language with the speed of compiled code. Its ecosystem is smaller but growing, and it suits numerically heavy tasks such as simulation.
C++ is still used where latency or raw throughput matters: execution systems, pricing libraries and high-frequency infrastructure. Most researchers interact with C++ code through Python bindings rather than writing it themselves.
For someone starting out, Python is the most practical choice, with R as a valuable second language for statistics.
The core Python stack
- NumPy provides fast arrays and linear algebra; nearly everything else builds on it.
- pandas provides labelled data frames and time-series tools: resampling, rolling windows, alignment of dates. Its original author, Wes McKinney, began developing it in 2008 while working at the asset manager AQR, which is one reason it handles financial time series so naturally.
- SciPy adds optimisation, statistics and signal processing.
- statsmodels covers regression, time-series models such as ARIMA, and statistical tests such as the augmented Dickey-Fuller test.
- scikit-learn is the standard library for classical machine learning, with consistent interfaces for models, pipelines and cross-validation.
- arch implements GARCH-family volatility models and related tests.
- Matplotlib and other plotting libraries handle charts; Jupyter notebooks mix code, results and notes.
Pricing and risk
QuantLib, started in 2000, is a comprehensive open-source C++ library for derivatives pricing, yield-curve construction and risk, with Python bindings. It is used both in education and in production systems. Learning it is a good way to understand how curves, day-count conventions and calendars work in practice.
Backtesting frameworks
Backtesting libraries fall into two broad designs:
- Event-driven frameworks simulate the market bar by bar or tick by tick, passing each event to the strategy, which places orders that are then filled by a simulated broker. They are realistic and flexible but slower. Zipline, originally developed by Quantopian and now maintained by the community as zipline-reloaded, and Backtrader are well-known Python examples.
- Vectorised frameworks compute signals and positions for the whole history at once using array operations. They are very fast, which makes them good for testing many parameter combinations, but it is easier to introduce look-ahead bias by accident.
Whatever framework is used, check how it handles transaction costs, slippage, corporate actions, delisted securities and the timing of signal versus execution. Before trusting a framework, reproduce a simple strategy by hand, for example the moving-average rule in our spreadsheet tutorial, and check that the results match.
Data
Free data sources are good enough for learning and for research on factors and macro series. The Kenneth French Data Library, FRED and Robert Shiller's long-run data are reliable starting points; we list more on our resources page. Free daily stock prices are widely available but often exclude delisted companies, which inflates backtest returns through survivorship bias. For research on individual stocks, find out whether your data include dead companies before drawing conclusions.
Communities and learning
The Quantitative Finance Stack Exchange answers technical questions; SSRN and arXiv's quantitative finance section host working papers; aggregators such as Quantocracy collect blog posts. Reading code from well-maintained projects on GitHub is one of the most effective ways to learn. Contributing documentation fixes or tests to an open-source project is also a credible way to show skills to employers.
Habits for reproducible research
- Use version control (Git) from the first day, including for notebooks.
- Record environments with a lock file or environment file so results can be recreated.
- Separate raw data from processed data, and keep the scripts that transform one into the other.
- Write tests for any function that computes a signal, label or return.
- Log experiments, including the ones that failed, so you know how many variations you tried.
- Respect licences for both code and data; see our note on packages and licences.
These habits are the foundation of the open research approach described in running a research project in the open.
A first project
A good first exercise combines the tools above. Download the monthly momentum and market factors from the Kenneth French Data Library with pandas; compute their cumulative returns, volatility and drawdowns; run a regression of momentum on the market with statsmodels; and plot the results. Then extend it: compute rolling twelve-month volatility, scale the momentum factor to a constant volatility, and see how the drawdowns change, reproducing in miniature the research discussed in our article on momentum crashes. Commit each step to a Git repository with a short note on what you found.
Once the first project works, rebuild it from a clean environment using only your lock file and README. If you cannot reproduce your own result a week later, nobody else will be able to, and fixing that early is far easier than later.
Sources
- McKinney, W. (2010). Data Structures for Statistical Computing in Python. Proceedings of the 9th Python in Science Conference, 56–61.
- pandas documentation, About pandas (project history).
- Pedregosa, F. et al. (2011). Scikit-learn: Machine Learning in Python. Journal of Machine Learning Research, 12, 2825–2830.
- Bezanson, J., Edelman, A., Karpinski, S. and Shah, V. (2017). Julia: A Fresh Approach to Numerical Computing. SIAM Review, 59(1), 65–98.
- QuantLib, project website.
- CRAN Task View, Empirical Finance.