At Man AHL, we use Python for almost everything. We build models in Python, support trading systems in Python, and write web visualisation tools in Python.
A common question we get is: why Python? Isn’t it too slow? How do you scale it to the size of your team? How do you ensure your software is robust?
A Lingua Franca
The biggest strength of Python is that everyone can use it.
We have carefully reviewed, thoroughly tested production code that’s widely used in live trading. We also have scrappy experiments, one-off scripts that are thrown away after being run. Python is great for both scenarios.
Previously, research on models would be done in R, and the model would be rewritten in Java for production. This presented a number of challenges:
- The rewrite increased the time taken to take a model to production.
- If the model isn’t behaving as expected, was the bug introduced by the Java translation, or did it exist in the R prototype?
- If a bug is found in the Java version, is the bugfix applied to the R version too?
- How can we run experiments on our R prototype and be confident that the Java implementation will behave the same way?
By using Python everywhere, we facilitate communication between teams. Anyone can run an experiment using the same code that runs in production.
Using a single language is also great for analytics. We can dump interesting data as a production model runs, and be confident that we can analyse it from our usual research tools.
Great Interactive Tooling
ipython is excellent. It’s easy to load up some data and interactively examine it or plot it.
In the above screenshot, I’ve loaded up the historical price of a FTSE future and plotted the near price.
The dynamic nature of Python is great for this. You can run snippets of code without needing to write a full program. We even support running model simulations from within the Python shell.
In the above screenshot, you can see that I’ve run individual lines inside a function definition, allowing me to develop functions incrementally.
We’re not a high-frequency shop, but we do deal with non-trivial amounts of data.
For example, consider a model using one year of one-minute price history. With 64-bit floats, that’s over 4 GiB for each market.
To deal with this volume of data, we use numpy extensively. Numpy gives you C-style arrays of floating point arrays, with C-level memory usage (efficient, contiguous numbers in memory).
If you can express your computation in terms of numpy operations, you can even get C-like performance from your Python code!
Of course, sometimes that’s still too slow. If you’re implementing computationally expensive machine learning algorithms, or low-level data types, you need every last drop of performance.
We use Cython or roll our own C/C++ in these situations. Cython is great for making your code more low-level whilst still preserving the structure of the original Python implementation.
Python has a huge selection of libraries available, and particularly excels at numerical computing.
The quality and breadth of existing Python libraries enables us to build more robust software in shorter periods of time.
It’s worth mentioning that we’re not exclusively using Python. Our execution team uses Java: their code is more latency sensitive. The data team has some tooling in Go (we don’t need the ability to do interactive experiments with data ingestion).
Overall, Python has been a great fit for Man AHL. It’s great for collaborating, performant, and the ecosystem is extensive.
If you’re interested in working on a Python platform used to trade 19bn USD, we’re hiring!
Opinions expressed are those of the author and may not be shared by all personnel of Man Group plc (‘Man’). These opinions are subject to change without notice, are for information purposes only and do not constitute an offer or invitation to make an investment in any financial instrument or in any product to which the Company and/or its affiliates provides investment advisory or any other financial services. Any organisations, financial instrument or products described in this material are mentioned for reference purposes only which should not be considered a recommendation for their purchase or sale. Neither the Company nor the authors shall be liable to any person for any action taken on the basis of the information provided. Some statements contained in this material concerning goals, strategies, outlook or other non-historical matters may be forward-looking statements and are based on current indicators and expectations. These forward-looking statements speak only as of the date on which they are made, and the Company undertakes no obligation to update or revise any forward-looking statements. These forward-looking statements are subject to risks and uncertainties that may cause actual results to differ materially from those contained in the statements. The Company and/or its affiliates may or may not have a position in any financial instrument mentioned and may or may not be actively trading in any such securities. This material is proprietary information of the Company and its affiliates and may not be reproduced or otherwise disseminated in whole or in part without prior written consent from the Company. The Company believes the content to be accurate. However accuracy is not warranted or guaranteed. The Company does not assume any liability in the case of incorrectly reported or incomplete information. Unless stated otherwise all information is provided by the Company. Past performance is not indicative of future results.