9 Great Tools for Algo Trading

In the last 5–10 years algorithmic trading, or algo trading, has gained popularity with the individual investor. The rise in popularity has been accompanied by a proliferation of tools and services, to both test and trade with algorithms. I’ve put together a list of 9 tools you should consider using for your algo trading process.

Photo by  Adrian Curiel  on  Unsplash

Photo by Adrian Curiel on Unsplash

Web Services:

The following are managed-services that you can use through web browsers, and don’t require much setup from the user. As someone who’s recently started in this field, I found it easy for new algo traders to try out.

(1) Quantopian:

1_xmqbJh3dGQIXylJTSCD7dA.png

A Boston-based crowd-sourced hedge fund, Quantopian provides an online IDE to backtest algorithms. Their platform is built with python, and all algorithms are implemented in Python. When testing algorithms, users have the option of a quick backtest, or a larger full backtest, and are provided the visual of portfolio performance.

Live-trading was discontinued in September 2017, but still provide a large range of historical data. They also have a serious community of developers, and now hold an ongoing DAILY contest with 10 winners awarded each day for a total of $5,000 per month in prize money (*updated from previously written as "periodically hold contests"). Quantopian provides capital to the winning algorithm. 

(2) QuantConnect:

1_eQopy9i2kr63RFeCFQq-sA.png

QuantConnect, is another platform that provides an IDE to both backtest and live-trade algorithmically. Their platform was built using C#, and users have the options to test algorithms in multiple languages, including both C# and Python.

QuantConnect also embraces a great community from all over the world, and provides access to equities, futures, forex and crypto trading. They offer live-trading integration with various names such as InteractiveBrokers, OANDA, and GDAX.

(3) QuantRocket:

QuantRocket is a platform that offers both backtesting and live trading with InteractiveBrokers, with live trading capabilities on forex as well as US equities. It’s specifically designed for trading with InteractiveBrokers, and sets itself apart with its flexibility.

QuantRocket supports multiple engines — its own Moonshot, as well as third party engines chosen by the user. While QuantRocket doesn’t have a traditional IDE, it is integrated well with Jupyter to produce something similar. One thing to keep in mind is that QuantRocket is not free. Pricing plans start at 19.99/month USD, with annual options.

Local Backtesting/LiveTrading Engines:

In today’s software world, you have lots more freedom if you make some effort outside of those managed-services. If you are comfortable this way, I recommend backtesting locally with these tools:

(4) Zipline/Zipline-Live:

quantopian/zipline
zipline - Zipline, a Pythonic Algorithmic Trading Librarygithub.com

Quantopian’s IDE is built on the back of Zipline, an open source backtesting engine for trading algorithms. Zipline runs locally, and can be configured to run in virtual environments and Docker containers as well. Zipline comes with all of Quantopian’s functions, but not all of its data. To balance that, users can write custom data to backtest on. Zipline also provides raw data from backtests, allowing for versatile uses of visualization.

Zipline discontinued live trading in 2017, but there is an open source project Zipline-live that works with Interactive Brokers. It has many of the same features Zipline does, and provides live trading.

(5) BackTrader:

backtrader - Backtesting / Trading
from datetime import datetime import backtrader as bt class SmaCross(bt.SignalStrategy): params = (('pfast', 10)…www.backtrader.com

Backtrader is currently one of the most popular backtesting engines available. It was built using python, and has a clean, simple, and efficient interface that runs locally (no Web Interface). One thing to keep in mind, backtrader doesn’t come with any data, but you can hook up your own market data in csv and other formats pretty easily.

Starting with release 1.5.0, BackTrader has live-trading capabilities. It’s been a popular choice with algo traders, especially after Zipline discontinued live trading.

(6) IBPy:

blampe/IbPy
IbPy - Python API for the Interactive Brokers on-line trading system.github.com

IBPy is an unaffiliated third party python wrapper for InteractiveBroker’s Trade Workstation API. Before IB started providing their official API library for python, this was the only way to connect to TWS for algorithms written in python.

IB has released an official python SDK, and this library is heading towards begin obsolete(while still being relevant for python2 users). But there still remain a significant number of live trading engines/tools that still use this library, and it’s good learning material for whoever wants to learn about implementing API’s.

While it’s good to learn about this library since it’s ubiquitous, if you are starting fresh, we recommend IB’s official python SDK.

Alpaca Trade API Python SDK is even much simpler to use!

Analytical Tools:

Back testing will output a significant amount of raw data. Some IDE’s will provide basic visualization and analysis, usually algorithm performance. If you’re looking for deeper evaluation, I recommend these tools:

(7) Pyfolio:

quantopian/pyfolio
pyfolio - Portfolio and risk analytics in Pythongithub.com

Pyfolio is another open source tool developed by Quantopian that focuses on evaluating a portfolio. What sets Pyfolio apart, is its ability to introduce degrees of uncertainty to a static set of data points, and evaluate Bayesian metrics from the user’s portfolio. The Pyfolio API offers a number of visualizations, which can be found on their GitHub repository.

(8) Alphalens:

quantopian/alphalens
alphalens - Performance analysis of predictive (alpha) stock factorsgithub.com

Alphalens is also an analysis tool from Quantopian. Unlike Pyfolio, Alphalens works well with the raw data output from Zipline, and rather than evaluate the portfolio, is performance analysis of predictive stock factors. Alphalens has its own range of visualizations found on their GitHub repository.

1_HnTL1cG_aBDoyBDyOzfkew.png

Median Daily Returns by Factor Quantile — one of the visualizations that alphalens offers

(9)TradingView:

1_Vy5CbHA0AdW7pwSmiwoZng.png

TradingView is a visualization tool with a vibrant open-source community. It’s entirely web-based, and allows users to visualize data, whether the data is the result of paper trading or algorithmic back-testing. Like Quantopian, TradingView allows users to share their results and visualizations with others in the community, and receive feedback.

(Bonus) Execution Platforms aka Broker-Dealers:

(10)InteractiveBrokers:

1_jAUoYLH-Fa3CyOtsfzsW3w.png

InteractiveBrokers is an online broker-dealer for active traders in general. They have been in the market since 1978. Algo trading isn’t IB’s focus, but multiple engines offer live trading through integration with their Trader Workstation. We’ve mentioned IB several times in this article — they’re just that good!

(11)Alpaca:

1_bhSUXCHVNP_JQmsMHklPlg.png

Finally, Alpaca! Alpaca was founded in 2015, and is an up and coming commission-free, broker-dealer designed specifically for algo trading. Alpaca also has a trade api, along with multiple open-source tools, which include a database optimized for time-series financial data known as the MarketStore.

The brokerage is scheduled to be publicly available this September (you can play around with the MarketStore right now), but if you can’t wait, head over to our website and jump on the waitlist for a chance at early access!

Alpaca | Algo Trading Commission Free with REST API
Lower your cost, Maximize your profits. Algo trading commision free.alpaca.markets

Miscellaneous Tools to Take a Look At:

  • qtpylib — another simplistic python backtesting engine
  • Multicharts — proprietary trading platform for forex and equities
  • WealthLab — desktop tool which allows C# backtesting, with live trading exclusive to Fidelity
  • Enygma Catalyst — for crypto trading
  • MetaTrader — backtesting/livetrading desktop app, de-fact in forex

I hope this quick primer on tools available right now was useful. If you liked it, please leave a clap (or two, I don’t mind). If you think there are tools that I missed, leave a comment below! I always appreciate any, and all feedback.

by Rao Vinnakota

/

Algo Trading for Dummies -  Building a Custom Back-tester (Part 3)

While there are many simple backtesting libraries available, they can be quite complex to use effectively — requiring a lot of extra processing of data sets. It is sometimes worth coding a custom back-tester to suit your needs.

Image from iOS (4).png

Building a back-tester is a fantastic conceptual exercise. Not only does this give you a deeper insight into orders and their interaction with the market, but it can also provide the framework for the order handling module of your trading bot.

Order Handling

One of the key pieces to an active trading strategy is the handling of more advanced orders types, such as trailing stops, automatically hedged positions or conditional orders.

For this you’ll want a separate module to manage the order logic before submitting to an exchange. You may even need a dedicated thread to actively manage orders once submitted, in case the platform itself doesn’t offer the necessary types.

Its best for the module to keep an internal representation of each position and its associated orders, which is then verified and amended as the orders are filled. This means you can run calculations against your positions without the need to constantly be querying the broker. It also allows you to easily convert the code for use in your back-tester, by simply altering the order fill checks to reference the historical data at each time step.

(Code Snippet of an order handling function as part of a position handler — full script at end of article)

(Code Snippet of an order handling function as part of a position handler — full script at end of article)

It may also be worth implementing order aggregation and splitting algorithms. For example, you may want a function to split a larger limit order across multiple price levels to hedge your bets on the optimal fill. Or, indeed, you might need a system to net together the orders of multiple simultaneous strategies.

Assumptions and Issues of Back-testing

Unless you’re using tick data and bid/ask snapshots to back-test against, there will always be a level of uncertainty in a simulated trade as to whether it would fill fully, at what price, and at what time. The period of each data point can also cause issues if its above the desired polling rate of the trading bot.

These uncertainties are lessened as the average holding period for each trade increased vs the resolution of your data, but is never fully eliminated. It is advised to always assume the worst case scenario in your simulation, as its better for a strategy to be over prepared than under.

(Back-testing order processing logic implemented into position handler — full script at end of article)

(Back-testing order processing logic implemented into position handler — full script at end of article)

For example, if a stop-loss order would have been triggered during the span of a bar, then you’d want to add some slippage to its trigger price and/or use the bar’s closing price. In reality, your are unlikely to get filled so unfavorably, but it’s impossible to tell without higher granularity data.

On top of this, it is impossible to simulate the effect of your order on the market movement itself. While this would be unlikely to have a noticeable effect on most strategies, if you’re using extremely short holding times on each trade or larger amounts of capital, it could certainly be a factor.

Designing an Efficient Back-tester

When calculating the next time step for an indicator, unless you’ve stored all relevant variables you will be recalculating a lot of information from the look-back period. This is unavoidable in a live system and, indeed, less of an issue, as you won’t be able to process data faster than it arrives. But you really don’t want to wait around longer than you have to for a simulation to complete.

The easiest and most efficient workaround is to calculate the full set of indicators over the whole dataset at start-up. These can then be indexed against their respective symbols and time stamps and saved for later. Even better, you could run a batch of back-tests in the same session without needing to recalculate the basic indicators between runs.

At each time you will then simply query the set of indexed indicators, construct the trading signals and push the orders to the order handling module, where the simulated positions are calculated along with their profit/ loss. You’ll also want to store the position and order fill information, either as a subscript to the back-tester or integrated directly into the position handling module.

Even Improving Your Back-tester

Back-testing is only as useful as the insight its statistics provide. Common review metrics include win/loss ratio, average profit/loss, average trade time, etc. However you may want to generate more insightful reports, such as position risk:reward ratios or an aggregate of price movement before and after each traded signal, which allows you to fine tune the algorithm.

Once the full framework has been designed, implemented and debugged should you start looking for ways to speed up and upgrade the inner loop of the back-tester (the order handling module). It is a lot easier to take a working program and make it faster than it is to take an overly optimized program and make it work.

By Matthew Tweed

Full position handling class framework:

/

So You Want to Trade Crypto - Technical Analysis (Part 3)

A healthy balance between fundamental and technical analysis is necessary when trading any financial product, especially so in Cryptocurrencies, due to both the nature of the asset class and the types of traders in the market.

Technical Analysis of Crypto

Technical analysis in any market is broadly the same, you look for repeating patterns that can be exploited to increase your odds of success. This may be through moving averages, oscillators, support levels or more complex methodologies. All of which serve to reduce the noise in the price data to produce cleaner trading signals.

I’ve seen many arguments about whether or not technical analysis actually produces viable strategies, most of which boil down to the same misunderstanding as to what TA really sets out to achieve.

You will not create a system which can always predict where the market will go. In fact, it will not even be able to predict where the market is likely to go the majority of the time.

Instead, you are looking for system which will deliver signals whose success rate is justified by its risk:reward ratio. The signals may only be correct 10% of the time, but if its profits outsize its losses 10:1, it can still break even.

Technical analysis is not designed to predict the future, it is designed to allow you to understand risk and adapt accordingly. 

Some of the most simple and successful strategies can just take a position aligned with the long term trend and occasionally adjust exposure to keep downside risk at a comfortable level.

Due to the huge bull run Cryptocurrency saw in the past few years, it is important to make sure you back-test and verify strategies during long term downturns too, such as post 2013.

It would be easy to look at the bull run from late 2015 to the start of 2018 and conclude that the most effective method is to “buy the dip” at every opportunity. This only looks at half of the picture, a market always acts in cycles of bullish and bearish periods, whether that be the longer term trend or the short term pullback.

Methods such as the use of an “equity curve” can be used to produce an adaptive trading system, where different strategies will only be trading during favorable market conditions. You may even with to use long term moving average crosses to help differentiate between a pullback and the shift into a new bear/ bull market.

Types of Traders and Investors in Cryptocurrency

Due to the extremely new and highly technical nature of Cryptocurrencies, it has taken a long time for institutions to even acknowledge Crypto, let alone become involved in the market. This has left a market filled with experts in technology rather than the world of finance and trading.

This may be one of the contributing factors to the huge levels of historical volatility, as inexperienced traders and investors playing around with a highly speculative asset are prone to being caught up in the hype and fear cycles of market swings, adding yet more momentum and irrationality to the mix.

In trading, you don’t have to be the smartest in the market (although it can certainly help), simply keeping your head above the emotion of trading cycles and sticking rigidly to a trading strategy is one of the most important factors in success. Emotional trading drives us to FOMO into assets as they near the top before panic selling as it comes crashing back down.

This need for simple and objective decision making is one of the main benefits of algorithmic trading over manual trading. 

A trading bot will not get tired, stressed or emotional. It sticks to the rules of your tried and tested strategy.

Algorithmic trading can be particularly successful in Cryptocurrency due to the level of inefficiency still present. We’re not even past the point where retail traders can still profit from arbitrage strategies — imagine the numbers of other strategies that haven’t been tapped yet!

There are many trading strategies that will give you very limited results in more mature financial markets, such as basic moving average crosses. Every strategy has a limit to the effective capital it can support before it becomes infeasible due to diminishing returns. When everyone knows the same basic strategy, it becomes a race as to who can trade the signals first — and a retail trader can’t compete with a well funded institution.

Final Words

This effect is lessened as the time-period of the strategy increases, but it still pays to find a truly unique strategy, as you will have more opportunity take advantage of its capital limits, rather than fighting to be first on each signal.

by Matthew Tweed

/

So You Want to Trade Crypto  -  Volatility (Part 2)

The Cryptocurrency market is extremely new and has yet to mature with greater regulation and institutional involvement, leading to sharp moves and high volatility as the market grows. This is a double edged sword — heaven for day traders looking for a bit of excitement while adding significant risk to those wishing to trade longer term.

Historical Volatility

Historical Volatility comparison of asset classes.

  • GVZVIX — CBOE Volatility index for Gold
  • VIX — CBOE Volatility index for the S&P 500
  • EUVIX — CBOE Volatility index for Euro/USD pair
  • BTCVIX — Bitcoin 30 day historical volatility (Bitcoin volatility on right axis as it’s so much higher)
Volatility_comparison.png

As we can see, there is a clear correlation between the volatility of more traditional traded assets, especially so during events such as the 2009 bounce. Bitcoin, on the other hand, seems to hold limited correlation to any of these other classes of products, even when factoring out the huge difference in average volatility.

Even the volatility of equities, currently at 13.4% from the VIX, is completely dwarfed by that of Bitcoin, coming in at 70% (down from 150% earlier in the year) — and Bitcoin is historically one of the less volatile Cryptocurrencies. Cryptocurrency markets represent a huge shift in gear, incurring more risk while giving the possibility of greater reward.

How to manage the volatility

Managing downside risk is an important part of any successful trading strategy, more so in the extreme volatility of Cryptocurrency. I personally prefer to define a hard stop-loss level prior to each trade, however a “soft” soft-loss/ exit parameter can be sufficient depending on the frequency of the trading strategy.

Very few Crypto exchanges cater to higher frequency trading at the moment, making faster trading strategies more difficult if not impossible in many cases. High frequency market making or scalping strategies are less concerned with hard stop-losses, due to the extremely short exposure to directional risk.

As hold duration for each trade moves into the span of minutes, absolute risk is still relatively limited in most cases. However, as in any market, there are occasional spikes in volatility — but these can be amplified too.

12th Apr 2018 — A move of $1200 — greater than the entire span of previous 2 weeks

12th Apr 2018 — A move of $1200 — greater than the entire span of previous 2 weeks

The risk:reward ratio of each trade is an important factor to a profitable trading system, along with the success rate 

If there is no plan for risk management, a black-swan event (such as the margin cascade seen above) could undo a week’s profits — or even wipe out a while account.

Moving into longer term strategies, such as swing trading

Volatility makes common strategies trickier. The simplest way to reduce the risk on a trade is to reduce position sizing on signals with lower confidence. For example, in forex trading, leverage is widely used to make efficient use of capital on relatively smaller movements. Meanwhile, it’d be madness to take that level of leverage on a Crypto swing trade. Risk doesn’t have to be any higher between asset classes, as long as volatility is adjusted for.

From active trading strategies into indexing, the Cryptocurrency market has provided huge returns over the past couple of years, with the total market capitalization rising from $18.3B at the start of 2017 to $613B by the start of 2018 — over 3000% growth. Unfortunately, past performance isn’t indicative of future returns — it would be impossible to continue at such a rate. Between Jan 2018 and Apr 2018, there was a pullback of 60% from which we’re still recovering.

An automatically re-balanced Cryptocurrency index fund can offer a simple but effective way to gain diversified exposure to the market, but be warned that you will have to be able to stomach the possibility of high drawdowns.

Volatility and Speculative Assets

As I mentioned in the first post of the series, Cryptocurrency cannot be analyzed in the same manner as traditional assets. You have no physical item or stake in a company to which the price is tied. The whole valuation of your token is based on the expectation of future demand, and is thus very susceptible to changes in sentiment.

A stock will be priced above the value of its dividends and assets to account for the expected growth in the business over time. However, during a market downturn, investors become less optimistic about the future as the economy constricts, driving down prices. The business itself may lose some revenue as consumers of the economy have less cash to spend, but there is still a functioning business with value.

Meanwhile, the whole success of Cryptocurrency relies on the ability of a project to attract businesses and developers to use the platform. Speculators are betting that the project will be successful in this goal long term, but there is no tangible asset to retain value if the project falters or market sentiment shifts against it.

This is one of the main reasons why the Cryptocurrency market remains so volatile compared to any other asset class

While this effect will reduce over time, as successful applications and businesses form in the ecosystem, it will not be a quick or easy process.

by Matthew Tweed

/

So You Want to Trade Crypto  - Fundamental Analysis (Part 1)

This will be a mini-series looking into: 

  • the nature of Cryptocurrency trading and investment, 
  • the key factors which shift the markets, and
  • the important differences between Crypto and more traditional traded assets.

Fundamental factors of Cryptocurrencies vs traditional assets.

In terms of investing and long term trading, Cryptocurrency can be analyzed somewhere between a stock and a commodity.

It should be seen very much as a speculative investment — in the case of most Cryptocurrencies, you’re buying into a token which represents no stake in a company nor any voting rights, similar to a commodity. However, you’re not investing into a physical asset either. You’re simply betting that over time the use-case and thus demand for your token will grow, driving up the price.

Since price over time will be relative to the success of product, it can be analyzed similarly to an investment in a start-up. The main focus when looking at a token should be the team and their ability to deliver a working product that will actually be used. Not only this, you should also take
into consideration the use of the token itself within their product.

Will growth of the product actually lead to higher demand for the token, or is it simply tacked on as an after thought?

Additionally, Cryptocurrency projects seem to have a very different valuation split to previous technologies. A shift in valuation from the applications built on top of a protocol to the Blockchain protocol itself. No-one is investing in creating a new protocol layer for the internet, as the captured value comes from the applications and companies build upon it, such as Google, Facebook and Amazon.

On the other hand, Cryptocurrencies such as Bitcoin and Ethereum have market caps of $100B while very few applications have even been produced yet, let alone applications in wide use outside of the sphere of Crypto-enthusiasts.

This may be a symptom of a wider speculative bubble around the Cryptocurrency market as a whole, or simply a fact of the technology — requiring a sufficient valuation to be maintained to allow efficient flow of payments. That being said, we haven’t seen a truly successful product built
on Blockchain yet, maybe the Blockchain killer app will dwarf current valuations in the long term - only time will tell.

What to look for in projects

The core proposition of Cryptocurrencies over the traditional financial system is the fact that you don’t have to trust a third party. 

Trust-less decentralization

A transaction can be sent to anyone anywhere in the world without needing a bank or escrow account in the middle. This property of trust-less decentralization should be the backbone of any good Cryptocurrency.

However, simple transactions are a very basic and limited use-case, which has been offered by Bitcoin since its first release in 2009. A project has to offer a unique and useful advancement on basic Blockchain technology. Many new Cryptos are becoming “smart contract platforms”.

Smart contracts are pieces of code which can be run on top of the Blockchain, in the same decentralized and trust-less manner as payments. This allows the easy creation of full applications on top of the basic transaction layer, providing much wider uses for businesses and developers.

Longterm Scalability

Longer term, one of the fundamental issues that needs to be solved in Blockchain technology is that of scaling. Since the basic Blockchain model relies on all connected nodes to process every transaction, it quickly runs into limitations of how fast a payment can be distributed and verified, not to mention that of storage.

While there are many projects out there which claim “1,000,000 transactions per second”, almost all of these approaches are either impractical in real life or break the fundamental premise of a Cryptocurrency being trust-less and decentralized. Its relatively easy to achieve “1M tps” when running high powered servers in the same location that all have implicit trust.
However, in reality, flow of transactions is limited by latency between nodes around the globe and the fact that we shouldn’t rely on a central node for verification — otherwise why don’t we just use a regular bank?

The scaling issue is being progressed on with such technologies as “sharding” or a change from a traditional Blockchain to a “DAG”. In the long term, these are the kind of advancements which will achieve reliable scaling, rather than misleading promises from certain projects.

Product Value w/ Blockchain

Finally, and most importantly, you should consider who the Cryptocurrency is developed for and whether it is truly a useful product to them. Many have tried applying Blockchain in a misguided manner to any and all systems to join in with the hype. However, unless you need the very specific properties of a decentralized and trust-less system, Blockchain is no more than a glorified
database.

Final thoughts

While there is innovation left and right in the Cryptocurrency space, caution is still strongly advised. Out of the over 1500 coins and tokens in existence, only a handful of projects are likely to survive. While the vast majority will fail in the long run, due diligence pays off — helping us sift through the rubbish to find those which have a chance at leading the revolution of decentralized finance.

by Matthew Tweed

/