8 Best Python Libraries for Algorithmic Trading
Tags: python, programming, productivity, beginners
Published: 2020-11-28 16:49:01

Even as someone with significant experience in software engineering and some knowledge of data science, I underwent a learning curve when I started algorithmic trading. Feeling productive took some time. I found myself writing my own Bollinger bands, or scouring for trading calendars, or using each cryptocurrency exchange's idiosyncratic APIs instead of an abstraction over all of them. These are the Python libraries I wish I'd known when I began chasing alpha. They'll help you make money faster.

## 1. FinTA

[FinTA](https://github.com/peerchemist/finta) (Financial Technical Analysis) implements over eighty trading indicators in Pandas. Unlike many other trading libraries, which try to do a bit of everything, FinTA only ingests dataframes and spits out trading indicators. Even the comments above each method are instructive, e.g., this [comment](https://github.com/peerchemist/finta/blob/master/finta/finta.py#L511-L523) annotating MACD. You'll likely see some indicators you don't even recognize, and the breadth of technical analysis encourages experimentation.

## 2. Zipline

[Zipline](https://github.com/quantopian/zipline) is the best of the generalist trading libraries. It has almost 13k stars (see my article on using data to evaluate software packages [here](https://thecarrots.io/blog/how-to-evaluate-npm-packages)) and powers [Quantopian](https://www.quantopian.com/), one of the most popular quant-finance communities, at least until Robinhood recently acquired it. Zipline allows you to ingest data from the command line (or a Jupyter notebook) and comes built-in with methods to facilitate writing complex strategies and backtesting them.

## 3. CCXT

[CCXT](https://github.com/ccxt/ccxt) (CryptoCurrency eXchange Trading) is a lifesaver if you programmatically trade cryptocurrency. No more will you have to write custom logic for each exchange. CCXT abstracts away differences between individual exchange APIs with a unified interface. It supports more than 120 exchanges. If you're not a Pythonist, you can even use the JavaScript and PHP implementations of CCXT (though you should get better taste in programming languages).

## 4. Freqtrade

[Freqtrade](https://github.com/freqtrade/freqtrade) is another crypto trading library that supports many exchanges. It facilitates backtesting, plotting, machine learning, performance status, reports, etc. You might be sighing at this point. How many cryptocurrency trading libraries does one algorithmic trading enthusiast need? What's amazing about Freqtrade is that you can control it with [Telegram](https://telegram.org/). That's right: you can henceforth DM your robot investment manager. Here are some of its awesome Telegram commands:

- `/status [table]`: lists all open trades;
- `/profit`: lists cumulative profit;
- `/forcesell <trade_id>|all`: sells the given trade;
- `/performance`: performance of each finished trade grouped by pair;
- `/balance`: account balance per currency;
- `/daily <n>`: profit or loss per day, over the last n days.

If you want to power up your Freqtrade trading bot and turn it into a Gundam ready to ravage financial markets on your behalf, check out [Freqtrade Strategies](https://github.com/freqtrade/freqtrade-strategies), which is what its name suggests.

## 5. YFinance

If you've been trading for long, you've likely heard of Yahoo! Finance. [YFinance](https://github.com/ranaroussi/yfinance) allows you to reliably and efficiently download market data from Yahoo! Finance. The library arose from a dire need when Yahoo decommissioned their historical data API. The library's creator wrote a helpful tutorial [here](https://aroussi.com/post/python-yahoo-finance).

## 6. Backtrader

[Backtrader](https://github.com/backtrader/backtrader) is a popular Python framework for backtesting and trading that includes data feeds, resampling tools, trading calendars, etc. What sets Backtrader apart aside from its features and reliability is its [active community](https://community.backtrader.com/) and [blog](https://www.backtrader.com/blog). Backtrader's community could fill a need given Quantopian's recent shutdown.

## 7. TensorTrade

[TensorTrade](https://github.com/tensortrade-org/tensortrade) is a framework for building trading algorithms that use deep reinforcement learning. It provides abstractions over `numpy`, `pandas`, `gym`, `keras`, and `tensorflow` to accelerate development. TensorTrade is still in beta, but it's quickly gaining traction and will likely become a mainstay in the quant community. Adam King, the creator of Tensor Trade, wrote an excellent [tutorial](https://towardsdatascience.com/trade-smarter-w-reinforcement-learning-a5e91163f315).

## 8. Trump2Cash

I saved the memeiest library for last. [Trump2Cash](https://github.com/maxbbraun/trump2cash) monitors Donald Trump's tweets. When he mentions publicly traded companies, it analyzes the tweet's sentiment and executes trades accordingly. The library even includes a utility to benchmark its [historical performance](https://github.com/maxbbraun/trump2cash/blob/master/benchmark.md). I'm not making any kind of recommendation, but the algorithm has been surprisingly successful.

Even supposing that Trump's ability to influence financial markets will soon wane, the source code is easily adaptable to other Twitter accounts. If you're interested in Twitter sentiment as a feature for a trading strategy, the repo is more than worth a look.

### About Us

At [Carrots](https://thecarrots.io) we're building a hiring platform specifically for software engineers. You can connect your GitHub, Stack Overflow, and more to go beyond your resume. Our algorithm shows where you rank among world-class talent and surfaces your profile to top companies. Check out our [Telegram channel](https://t.me/softwaredevjobs) for a live feed of developer jobs.