Translate

Sunday, February 21, 2021

Ultimate List of Automated Trading Strategies You Should Know

Sources:

Ultimate List of Automated Trading Strategies You Should Know - Part 1 https://medium.com/automation-generation/ultimate-list-of-automated-trading-strategies-you-should-know-part-1-c9a333f58930

Ultimate List of Automated Trading Strategies You Should Know - Part 2 https://medium.com/automation-generation/ultimate-list-of-automated-trading-strategies-you-should-know-part-2-88184b27cd60

Ultimate List of Automated Trading Strategies You Should Know - Part 3 https://medium.com/automation-generation/ultimate-list-of-automated-trading-strategies-you-should-know-part-3-25d580ccab0c


Since the public release of Alpaca’s commission-free trading API, many developers and tech-savvy people have joined our community slack to discuss various aspects of automated trading. We are excited to see many have already started running algorithms in production, while others are testing their algorithms with our paper trading feature, which allows users to play with our API in a real-time simulation environment.

When we started thinking about a trading API service earlier this year, we were looking at only a small segment of algo trading. However, the more users we talked with, the more we realized there are many use cases for automated trading, particularly when considering different time horizons, tools, and objectives.

Today, as a celebration of our public launch and as a welcome message to our new users, we would like to highlight various automated trading strategies to provide you with ideas and opportunities you can explore for your own needs.

Please note that some concepts overlap with others, and not every item necessarily talks about a specific strategy per se, and some of the strategies may not be applicable to the current Alpaca offering.

(1) Time-Series Momentum/Mean Reversion

(2) Cross-Sectional Momentum/Mean Reversion

(3) Dollar Cost Averaging

(4) Market Making

(5) Day Trading Automation

(6) News/Event-Driven Trading

(7) Using Machine Learning

(8) Exchange Arbitrage (N/A for Alpaca)

(9) Portfolio Rebalancing

(10) ETF/Index Arbitrage.

(11) Market/Social Sentiment Strategy

(12) Pairs/Long-Short

(13) HFT (High-Frequency Trading)

(14) Order Slicing (N/A for Alpaca)

(15) Synthetic Options Strategy (N/A for Alpaca)

(1) Time-Series Momentum/Mean Reversion

Background

(Time-series) momentum and mean reversion are two of the most well known and well-researched concepts in trading. Billions of dollars are put to work by CTAs employing these concepts to produce alpha and create diversified return streams.

What It Is

The fundamental idea of time-series forecasting is to predict future values based on previously observed values. Time-series momentum, also known as trend-following, seeks to generate excess returns through an expectation that the future price return of an asset will be in the same direction as that asset’s return over some lookback period.

Trend-following strategies might define and look for specific price actions, such as range breakouts, volatility jumps, and volume profile skews, or attempt to define a trend based on a moving average that smooths past price movements. One of the simple, well-known strategies is the “simple moving average crossover”, which buys a stock if its short-period moving average value surpasses its long-period moving average value, and sells if the inverse event happens.

Mean-reversion is the expectation that the future price return of an asset will be in the opposite direction of that asset’s return over some lookback period. One of the most popular indicators is the Relative Strength Index, or RSI, which measures the speed and change of price movements using a scale of 0 to 100. For the purposes of trying to assess the likelihood of mean-reversion, a higher RSI value is said to indicate an overbought asset while a lower RSI value is said to indicate an oversold asset.

For Implementation

Trend-following and mean-reversion strategies are easy to understand since they look at a single asset’s time-series and try to make a prediction about that asset’s future return, but there are many ways to interpret the past behavior. You will need access to historical price data and may benefit from an indicator calculator library such as TA-lib. Virtually every trading framework library, including pyalgotrade, backtrader, and pylivetrader, can support these types of strategies.

Here is the Quantopian tutorial with backtest result for moving average crossover:

(2) Cross-Sectional Momentum/Mean Reversion

Background

In the U.S. stock market, there are more than 6,000 names listed on the exchanges and actively traded every day. One of the hardest problems in stock trading (and also true for global cryptocurrency trading) is how to pick the stocks.

What It Is

Cross-sectional momentum compares the momentum metrics across different stocks to try to predict the future returns of one or more of them. Even if two stocks such as Facebook and Google are indicating a momentum breakout, this may be driven by the market, but you try to beat the market by taking stronger momentum between those signals. Same for mean reversion. The point is that we consider the market movement that drives each individual stock and consider the relative strength of signals across stocks in an effort to produce a strategy that will outperform the market. This tends to be more computationally heavy, since you need to calculate the metrics with potentially tens to hundreds of time-series.

For Implementation

Again, for this type of strategy libraries like TA-Lib may make it easier to calculate the indicators. Also, you may need simultaneous access to multiple symbols’ price data. IEX’s API can provide up daily bar data for up to 100 stocks per query.

A medium post about cross-sectional study:

(3) Dollar Cost Averaging

Background

This is one of the simplest automated trading strategies and it is widely used by many investors.

What It Is

The idea is to invest a fixed amount of money into an asset periodically. You may doubt it, but some research indicates that this works in the real world, especially long-term. The logic behind it is that price fluctuates many times, and you may buy the stock cheaper overall compared to just investing in the stock at one point in time.

Remember, all of you who contribute to your 401k account are basically doing this. However, you might never think about doing it yourself, simply because there has been no easy way to automate this process.

For Implementation

Now with Alpaca trading API, it’s much simpler and provides much more flexibility.

(4) Market Making

Background

Market makers are important intermediaries who stand ready to buy and sell securities continuously. By doing this, they provide much-needed liquidity and are compensated for their inventory risk primarily by capturing bid-ask spreads.

Market making used to be done primarily by humans, who worked as floor traders in the pits, but now it’s almost entirely performed by machines. As exchanges have become more and more electronic, the strategy market makers employ has naturally required automation.

What It Is

There are a variety of approaches to market making but most typically rely upon successful inventory management through hedging and limiting adverse selection.

Some market makers may have very tight exposure limits and seek to turn over their positions quickly with the goal of being flat at the end of each day. Others may operate on a much longer horizon, carrying a large and diverse portfolio of securities long and short indefinitely. Undoubtedly, for any market maker, speed helps. The speed of calculation allows the market maker to continuously update its pricing and portfolio risk models, while the speed of execution allows the market maker to act on its models in a timely manner in an effort to reduce adverse selection and get better pricing on its hedges.

Competitive market makers need high-resolution data and a low latency infrastructure, although typically the longer their trading horizon is, the less sensitive they are to these things, and a smart but slow model goes a long way.

For Implementation

Also, in order to process vast amounts of data quickly and handle concurrency, languages like python may not be suitable. Go/Rust would be a good choice for balance between ease of concurrency handling and processing speed, as well as functional languages like Erlang/OCaml or good old languages like C++.

Some high-level explanation of market making:

(5) Day Trading Automation

Background

Lots of day traders develop their trading strategies based on a mechanical set of conditions that are first based on intuition. Since manual day trading involves continuously assessing market conditions and making discretionary trading decisions on the spot, it can often be very physically and emotionally draining. Because the strategies are based on some rules or heuristics which can be codified, it is natural to think they can be automated, which is likely the case.

What It Is

One of the very well-known day trading strategies is the gap-up momentum strategy.

Suppose between the previous market close and next market open there is a positive earnings report. The market opens with a big gap, drawing lots of traders’ attention, and the price keeps going up for a while in the morning (but may not continue for long).

This strategy seeks to capture this follow-through momentum. The challenge here is that not all gap-up stocks keep going up, and among a handful of screened stocks, you need to watch each one’s price action simultaneously.

Some traders may enter on a price breakout from a certain price resistance level, while others may wait to see a chart pattern form to determine the first bottom before going higher. Day trading often relies on analyzing the stock’s price chart and fine-tuning the algorithm to capture the price action can be tricky. That said, once it’s well developed, you are letting your bot trade on your behalf as if you were trading manually, and now you don’t need to monitor the markets and you can also monitor more stocks at the same time without any emotions affecting your trade execution, which is very compelling.

For Implementation

The main thing you need for this is access to market data. You may not even need indicator calculations but instead, you may need a stock screening library such as pipeline-live. The latency typically isn’t so important, so you don’t need to write your system in C++. Python, as well as other lightweight languages, are likely sufficient.


(6) News/Event-Driven Trading

Background

Trump says something about Amazon, and the company’s share price drops. The FDA publishes an approval for an outstanding generic application, and one biotech company’s share price jumps up. Elon Musk tweets about taking Tesla private, and the Tesla stock quickly trades higher.

News can cause significant changes in a stock price, but it’s challenging to (a) identify such events and to (b) take the right actions as soon as they happen.

Possible Approach

For (a), it’s the era of data, and you can get historical news and tweets from several sources, and identify keywords or particular events that may have led to a material price movement. Machine learning, or more specifically natural language processing, might solve some of the problems here, too.

For (b), again, it may not make sense for you to keep monitoring Twitter, StockTwits, Bloomberg or Y! Finance and react to the news with a manual trade. Rather, with Alpaca Trading API, you can automate this if-then-that process into something that continuously scans for news or events and reacts accordingly.

For Implementation

All you need here is a news and/or Twitter feed, which you can constantly monitor for new actionable events. Twitter and StockTwits both provide APIs for personal use as well. Some cloud environment such as Amazon Lambda may be a good solution for this too.

Trigger Finance’s (now part of Circle) Trump Trigger:

(7) Using Machine Learning

Background

The evolution of AI and machine learning technology is also changing the landscape of algo trading.

While institutions have been doing massive experiments using terabytes of data and GPU clusters, due to the nature of secrecy in the industry, public discussion and research have often been limited to simple price predictions with bare minimal LSTM or ARIMA models.

Use Cases

But the power of ML allows the practitioner to find the optimal signal among a set of rules with varying parameters. Without ML, a trader might develop a rules-based system that is too inflexible to changing market conditions. Or a trader’s mechanical system might have suboptimal feature parameters that do not effectively capture the feature’s predictive value.

For example, ML can be used to choose the dynamic parameters of indicators like MACD for developing an exit strategy based on the context and other factors.

The application of machine learning in trading isn’t just for analyzing price data. Lots of new hedge funds are making use of satellite images to add fundamental information for better investment decisions. Natural language processing is another.

Data-driven trading is improving a lot with machine learning today. It is not just a coincidence that we at Alpaca are also seeing great interest among users for ML-based trading strategies.

For Implementation

You will certainly need a good set of tools such as scikit-learn and tensorflow, in addition to good data sources, and possibly may benefit from computer resources such as a GPU to build your trained model.

On the other hand, you may need less or even no market knowledge. Deep learning or the use of multi-layered neural nets has become possible to do even with a consumer laptop, and often it can be difficult for the practitioner to understand the logic behind the decisions generated from a deep learning model. Generally, it’s probably going to be helpful to have domain knowledge, no matter what industry you apply ML to, as ML and deep learning are by no means a silver bullet.

A public python notebook about stock prediction using LSTM:

(8) Exchange Arbitrage (N/A for Alpaca)

What It Is

The idea of exchange arbitrage is simple — you want to capture the price differences that occur when a certain fungible asset trades on more than one venue.

In Reality

This is not particularly applicable to the U.S. equities today as the markets are incredibly efficient. Rather, there still exist opportunities for individuals to engage in cryptocurrency exchange arbitrage, but even these are rapidly disappearing and involve other operational and counterparty risks not seen in U.S. stocks.

While exchange arbitrage sounds promising, it is not risk-free nor is it riskless and you should be aware of and consider all operational, technical, and legal issues that can arise. That said, exchange arbitrage is well understood and mechanical and hence much more suitable for automation.

Again, the US equity market is very efficient today, and regulations prohibit locked or crossed markets, so opportunities are extremely rare and short-lived. Further, Alpaca currently does not offer direct market access at this moment.

Great overview of crypto exchange arbitrage:

(9) Portfolio Rebalancing

Background

As the old saying goes, you may not want to put all your eggs into one basket. By diversifying your investment into multiple different assets, you can distribute risk, and your entire portfolio value can be more efficient in terms of the risk/return profile. It all sounds good, and this is what you can expect to hear from your financial advisors and asset managers. It’s based on the simple mathematics as follows:

Image for post

What we are talking about here is maximizing the return while keeping the risk (volatility) at the lowest possible point for the expected return.

In Reality

You can do research on the expected risk/return by looking into the historical data for each stock so that you can construct the portfolio from scratch.

Great. Now, you need to actually buy those stocks to make this happen, but what if we are talking about 50 different names? It’s error-prone and time-consuming to do it manually. OK, let’s say you managed to do so once, now time flies and weeks or months later, some stocks moved a lot more than the others, and risk profile of your portfolio might have been changed. You now need to do the calculation again and find out the optimal portfolio structure, then buy and sell stocks resulted by the calculation!

For Implementation

You may notice that this is all about numbers and pretty mechanical from a risk/return calculation to placing orders. This is a part of the reasons why there are now many Robo Advisors, which automated this work to charge fees for advisory and asset management.

With Alpaca’s commission-free REST trading API, there is nothing that prevents you from doing it yourself. You can even do it by using a Google Spreadsheet now.

Ref. some medium article about Modern Portfolio Theory:

(10) ETF/Index Arbitrage

Background

While there are many exotic ETFs that hold complicated structured products such as swaps and options, some ETFs are purely baskets of individual stocks.

Since an Index ETF and a basket of their underlying holdings are fundamentally the same things, there exist price arbitrage opportunities when the ETF price dislocates from the basket price.

In Reality

Super active ETFs like SPY (which tracks the S&P 500 Index) likely have no chance for individuals to take such arbitrage opportunities, but for some of the less liquid ETFs, individuals may have an opportunity. Any arbitrage opportunities are very short-lived, and again you need to keep monitoring the market activities to locate them.

Once you detect an opportunity, you may want to get in before it disappears. It would be likely to last somewhere between a few seconds to minutes. While a latency should not be a major issue here, it’s still not suitable to be manually traded either.

(11) Market/Social Sentiment Strategy

Background

It is a great era that such exotic data like social sentiment time series data is available for our personal use. It is similar to the news/event-driven strategy, but social sentiment can target a longer timeframe and can incorporate several different news as well as sentiment sources.

Anecdotally, we’ve seen the traders' sentiment turn negative right before the price starts rising, which is, in a way, very opposite to one’s intuition.

The great thing about making a use of data is that you can do the research and analysis to uncover patterns which may be very counterintuitive.

Where to get the data

StockTwits tracks bulls and bears among internet users for each stock name, and there is also more aggregated data such as the bull-bear ratio published by Investment Intelligence.

For this strategy to work, it may make sense to develop a model that scores sentiment and associates the score with future returns at various time-horizons. The algorithm itself may not be that computational heavy or latency sensitive because the strategy’s time horizon tends to be longer. Also, most likely you can prototype something lightweight using Python Jupyter Notebook.

Bull-bear ratio chart from YChart:

(12) Pairs/Long-Short

Background

A stock price moves up and down, no matter how strong the company’s financials are. Part of the reason for this is that no single stock is completely uncorrelated to the broader market movements or the movements of the sector and industry peers.

What it is

A long-short or market neutral strategy lowers a portfolio’s beta and focuses on capturing alpha, or excess returns, from the company-specific risk, that you take by being long or short the stock.

Some long-short strategies are based solely on fundamental analysis, while others are entirely quantitative and focus on statistical arbitrage.

For example

An example is this: you think that American Airlines is doing a better job than the rest of the airline sector. You buy AAL but also are concerned that the airline sector itself may go down, so you short an equal dollar amount of another airline stock that you do not like as much, for example, DAL (Delta Airlines). If the whole airline sector goes down, you profit from the DAL short position, while of course, you have some loss from AAL long position.

But if at the end of the day American performs better than Delta, you can profit from this pair no matter how the whole sector moves. The same thing can be done across sectors or asset classes over any time horizon.

Almost all assets have some degree of correlation, so whether you choose to focus on differences in the quality of companies’ fundamentals, or you just want to trade the correlation or cointegration of a pair or basket, you could apply a long-short strategy thought process.

For implementation

As you can see, in order to achieve this strategy, you may need to perform some statistical analysis. Consider using python’s statistics packages or R, along with research environment tools such as Jupyter Notebook. It takes work but if you can get it right, it works well.

There are many asset managers, quantitative and fundamental, long-term and short-term, who are trading long-short strategies today.

While Alpaca does not support short selling yet, it is on the roadmap. In the meantime, you can also make a quasi-short position using inverse ETFs in some cases.

Quantopian example code for long-short:

(13) HFT (High-Frequency Trading)

Background

The notion of HFT is very broad. The name just refers to the time horizon of trading strategies and does not mean much in terms of actual trading concepts. For example, some call minute-level trading as HFT, while others disagree and would not even call second-level trading as HFT.

In the US equity market, the battlefield of HFT can be in the microseconds (1/10^6 of a second) or nanoseconds (1/10^9 of a second, and opportunities disappear very quickly unless you are the very first to the market. In his famous book Flash Boys, Michael Lewis talks a lot about the hard wire (fiber), but as of today, HFT firms are utilizing microwaves since they can go straight at the minimum distance to the destination. Yes, that’s right, the real-life rocket science.

For individuals traders

The good news is that their battlefield is far away from any of the strategies we talk about here, and individual traders do not need to worry much about this.

As you can imagine, minute-level trading doesn’t affect long-term investors, and HFT does not have much impact on mid-frequency traders or longer time horizon base.

An interesting reddit post about microwave in HFT:

(14) Order Slicing (N/A for Alpaca)

Background

When you start talking about “algo trading”, many “industry” people start thinking about order slicing first.

Order slicing or order execution algorithm refers to a computer logic that executes large block orders in small pieces to try to minimize market impact and information leakage. Execution transaction costs are especially important to large asset managers, because they may suffer from significant return deterioration when trying to enter or exit a large position.

Smart order routing, which executes orders piece by piece, can reduce information leakage and can prevent others from panicking or front-running the large block order.

For individual traders

This is all about the large positions dealt by institutions and may not be applicable to individual traders. However, we wanted to mention this here because this is one of the oldest and most well-known areas of algorithmic trading and is something that many “industry” people think of when hearing the term “algo” or “algo trading.”

It’s a bit old, but this TED talk is quite helpfulto understand this:

(15) Synthetic Options Strategy (N/A for Alpaca)

Background

Not strictly algorithmic trading, but synthetic options strategies can benefit significantly from automation and the use of trading API.

The simplest and well-known method is to buy an in-the-money call and sell an in-the-money put with the same expiration for the same size, which makes a position that has the same profile as an underlying long position at a much lower cost. While it sounds easy, it can be tricky to determine the best combination of call and put options to use, and it requires tracking the full chains and calculating values for each option in the chain. But once you build your own model, it’s a matter of seconds to come up with the answer.

Options trading in the automated trading space can be much more diverse and interesting than just long or short trading of individual stocks, as you can build structures such as covered calls.

Please note that Alpaca Trading API currently does not support options, but it is on the roadmap.

More detailed explanation about synthetic long position:

Conclusion

This series composes a list of different styles in automated trading at a very high level. For us to write up a broad overview, some descriptions may have ended up to be vague and may need more details. We hope that this series gives you preliminary ideas on the automated trading space.

Some reference: