# Trading like the quants do — an introduction to beginner-friendly trading strategies

Interested in automated trading but not sure where to start? How about by building an indicator trading strategy? This is just one of the three examples we discuss. In this article, we cover the basics of signal trading, pairs trading and sentiment analysis trading. Maybe there’s a strategy in there that speaks to you.

Suppose you want to trade, just like the quant funds do. What do you need to know? In the United States in 2018, between70 to 80%of overall trading volume was generated through algorithmic trading. It’s a pretty safe bet to say that most big institutions are using algorithms to (at least partially) power their trades. And very often their algorithms are based on one or more well-known trading strategies. Familiarising yourself with some popular strategies is an excellent way to begin your automated strategy journey. Of course, keep in mind that there’s also a lot of additional ingredients that can make or break a trading strategy, such as trading venue, execution speed, market timing and insight about the market.

Broadly speaking, the core of a trading strategy will either be based on **momentum **or **mean reversion **(two very different concepts). Others say that this distinction can only be applied to technical trading strategies, but for simplicity’s sake, we’re going to assume that this classification holds. The former is the theory that, just like a particle, an asset has momentum — if it is going up, it will continue to go up due to momentum. If momentum slows down, then it’s probably time to exit your position. The latter refers to the theory that prices will reverse back to an average if they deviate from it. You might notice that these schools of thought seem to directly contradict each other. That observation would be correct. So, which one should you base your trading strategy on? This is entirely dependent on your trading goals and trading horizon: momentum-based strategies usually perform better in the long-run, whereas mean-reversion is more successful in the short run.

The strategies highlighted in this article are by no means the best, most profitable options out there. They were chosen because they can be widely applied with many different parameters. But, we highly recommend that you conduct your own research. Of the following strategies, one is momentum-based, one is mean-reversion based and one could be either. Can you figure out which is which? 🤔

### Signal Detection

Signal detection in trading is looking for certain pre-determined criteria that indicate whether a security should be bought or sold. **Signals trading** or **signal detection** is really an umbrella term, with many different types of approaches that fall under it. The main goal is to develop a methodology, with entry and exit thresholds, which can be defined by a variety of signals. For example, you might monitor the **volume** (i.e. how many shares are being traded) of a particular stock: if volume seems to be increasing along with price, this might indicate that investors believe in that stock. What do you think — momentum or mean reversion? This would probably be a case of momentum trading, as the reaction would be to hop onto the trend (because congruous price and volume increases usually signal more buying is going to occur in the future, along with higher prices). However, at some point, volume may dry up because e.g. investors are unwilling to pay above a certain price for a stock. This would be the perfect opportunity for a mean-reversion based strategy. Read more on the relation between price and volume, here.

#### What kind of trading signals can I use?

The ‘signal’ does not need to be related to volume. In fact, it can be anything that you as a trader deem important. Usually, they are based on some sort of technical analysis, like setting triggers based on the:

- Relative Strength Index (RSI),
- Moving Average (MA),
- Moving Average Convergence Divergence (MACD) or
- On-Balance Volume (OBV).

These are called **technicalindicators**, which are usually mathematical calculations based on an instrument’s characteristics (e.g. price or volume) to predict future performance. Perhaps you’ve heard of the terms ‘bullish’ and ‘bearish’ before: usually they are in relation to trading sentiment based on technical indicators.

The **relative strength index** (RSI) is a momentum indicator, which measures whether an instrument is overbought or oversold based on recent relative price changes. A **moving average** (MA) is the average price over a particular number of days in the past — for example, 15, 30, 100 or 200 days. A rising moving average might indicate an upwards trend in the price or momentum. It can’t be classified as purely momentum or mean-reversion based because it depends what you do with it. A mean-reversion based strategy might execute a buy order if a share’s price surpasses its 200-day MA (we’ll be publishing an article on this shortly).

The **moving average convergence divergence **(MACD) is another momentum indicator, which measures the relationship between two **exponential moving averages** (EMA), namely the 26-period EMA against the 12-period EMA. The EMA is different from the MA in that it gives increased importance to the price of a stock on recent days, making it more responsive to current information. When the MACD is positive, the short-term average is above the long-term average, which is an indicator of upward momentum (the opposite can be said about a negative MACD). The **on-balance volume** (OBV) is also an indicator of momentum, used to predict the movement of ‘smart money’, i.e. institutional investors.

These four indicators might give contradictory signals, therefore we encourage you to do further research. Some indicators might be more appropriate in particular markets or at particular points in time. There’s also plenty of other indicators. Have you heard of Fibonacci retracements or the Guppy Multiple Moving Average?

Signals can also be based on **fundamentals**, such as earnings reports or level of insider buying. Stefan Jansen has a book on Machine Learning for Algorithmic Trading and an extremely thorough public GitHub repository — he covers how predictive models can be used to extract trading signals from various sources, like earnings reports.

Look for signals that give the ‘green light’ for trading — see here our ‘Ampelmännchen’ or ‘little traffic light man’

Signals trading might be either momentum or mean-reversion based, depending on which signal(s) you decide to follow. Your strategy can incorporate both momentum and mean-reversion to cover all possibilities. 😉

#### Implementing using lemon.markets

A signals trading strategy is the perfect use-case for the lemon.markets API. You can retrieve historic market data on a per-minute (M1), per-hour (H1) or per-day (D1) basis and get the latest quotes for specific instruments. This information can be used as-is, or it can be processed with a relevant Python library, such as TA-Lib which can be used compute 200+ indicators. You can then use the **lemon.markets API** to automatically place your order, or you can opt to send the signal directly to the user. For example, through means of a push notification, email or even Telegram message to allow the user to confirm the trade before it is placed.

### Sentiment Analysis

If you’ve seen articles like ‘I wrote a bot that trades based on this celebrity’s tweets’ come by, chances are, it’s based on **sentiment analysis**. It’s become a very hot topic, especially with the increased spotlight on forums such as Reddit, which some claim contributed to the rapid price increase of GameStop (GME) stock. We would classify sentiment analysis as a momentum based strategy because you’re attempting to catch momentum or trends before they happen.

#### What to scrape?

Sentiment Analysis is especially interesting because you’re using user-generated data to determine the general opinion on a particular instrument. You gain direct access to investor emotions. Some popular sources to scrape include social media sites such as Reddit, Twitter and Facebook or news sites such as YahooFinance!, Bloomberg and FinViz.

#### How to analyse sentiment?

There are several ways to analyse sentiment. Perhaps you believe that frequency is a good indicator of stock popularity — if more people are talking about a stock, it must be a good sign, right? Not necessarily. The language used to describe the stock might be negative. Therefore, it’s often not enough to e.g. just collect the amount of times a stock ticker is tweeted out per day. Sentiment Analysis is based on **Natural Language Processing** (NLP), which scores texts based on the emotion they convey. At minimum, NLP can distinguish between positive, neutral and negative posts. However, more sophisticated applications can go beyond these three simple categories and also identify emotions such as anger, disgust, fear, hope, etc.

To make your life easier, there’s several Python libraries that can produce sentiment scores for you, like Vader — you don’t need to reinvent the wheel (unless you want to). Or you can choose to combine sentiment analysis and machine learning, as this tutorial does.

#### Implementing using lemon.markets

To begin implementing a sentiment analysis strategy, you need to determine from where you want to retrieve your data, perhaps this means choosing a Twitter account to scrape, or a particular ticker you want to follow on Twitter. You then need a way to collect the tweets, this can be done with the Twitter API and the Python library Tweepy or snscrape. Once you have your data, the actual sentiment analysis needs to happen. You can use Vader, like we mentioned above, or Textblob, among others. Again, a notification can be sent to the user or, using the** lemon.markets API**, the trade can immediately be placed depending on the sentiment score.

In this example we’re talking about Twitter, but note that the general process can be applied to any social media site.

### Pairs Trading

In the mid-1980s, Morgan Stanley set up a team of mathematicians, physicists and computer scientists (some of who weren’t even versed in trading) led by Gerry Bamberger and later Nunzio Tartaglia. Their goal? Building a mathematical model that would give Morgan Stanley an edge on Wall Street. And thus, the Pairs Trading strategy was born. On a high level, pairs trading involves choosing two securities whose prices have moved together in the past, and then when one of them diverges, to short the stronger one and buy the weaker one, with the expectation that the prices will converge again. This sounds like a theory we’ve covered before… perhaps, mean-reversion?

#### Why does pairs trading work?

In pairs trading, the assumption is that two financial instruments that were highly correlated in the past will remain correlated in the future. In the scenario that the correlation temporarily breaks down, i.e. one stock moves up while the other moves down, the pairs trade would be to short the ‘winning’ stock and to go long on the ‘losing’ one, betting that the prices will move towards each other again.

Pair trading allows room for profit in any kind of market — upwards, downwards, sideways. It’s market neutral, which means that you’re betting on the spread of the pair, not the direction of the market. However, as spreads (especially those of historically correlated pairs) move less than the market, for pairs trading to be efficient, trades very often need to be leveraged.

#### Which pairs should I trade?

Picking a good pair to trade is half of the work (the other half is timing, and some other factors). So, how do you make sure you have a winning pair? You might start thinking about it intuitively — for example, think Coca-Cola (KO) and Pepsi (PEP), which are two similar (although we know some might have very strong opinions about this) soda companies. In the past, they have moved together, but something like important news about one of the companies might cause a temporary divergence.

A more robust way of picking a pair is to calculate the correlation based on historical prices. Let’s calculate the correlation coefficient for KO and PEP to see if our assertion is true. The formula for Pearson’s correlation coefficient is:

where r is the correlation coefficient between x and y, xᵢ is observation i of x and x̅ is the average of x (y follows similar naming conventions). Pandas (if you haven’t heard of Pandas, read our articleon must-know resources for automated trading, it’s one of the most useful Python packages for data manipulation) has a built-in corr() method that can be called on DataFrames. In the following code snippet, we import closing prices for KO and PEP from the past five years from YahooFinance! and calculate their correlation.

```
1import pandas as pd
2pep_closing = pd.read_csv("PEP.csv")['Close']
3ko_closing = pd.read_csv("KO.csv")['Close']
4r = pep_closing.corr(ko_closing)
5print(f'The correlation coefficient is: {r}')
```

`1The correlation coefficient is: 0.879735664095373`

Correlation can take on values between -1 and 1, where -1 is perfect negative correlation, 0 is no correlation and 1 is perfect positive correlation. A correlation coefficient of 0.88 is fairly high and would indicate that KO and PEP might be good candidates for a pairs trade. To illustrate, the correlation coefficient of KO and General Motors (GM) is 0.48. This makes sense, as we wouldn’t expect these to move together and probably wouldn’t be our first pick for a pairs trade.

Instead of historical prices, maybe try a different valuation metric like the P/E ratio when calculating the correlation coefficient. If you want to get even more robust, cluster analysis on different stocks can be performed to find candidates for pairs trading.

#### lemon.markets

At the moment, lemon.markets does not support shorting shares, however the pairs strategy can still be implemented by buying warrants. A warrant gives you the right to buy or sell a certain security. Our API offers access to several warrants that represent short positions, such as UCI-HVB FAC.CERT. SHORT ATX (isin: DE000HZ4XD01). Sign up to lemon.markets if you want to find out more.

### Other interesting trading strategies

We recognise that this list is nowhere near complete, perhaps you want to consider the following trading strategies:

- Buy and Hold,
- Dividend Growth Investing or
- Dollar Cost Averaging (keep your eyes peeled for our upcoming blog post!).

Learning about the different pre-existing trading strategies is the first step in designing your own strategy. In fact, you could combine signals trading, sentiment analysis and pairs trading to construct your own ‘super-strategy’. It’s all about finding a market inefficiency and rolling with it.

We’re looking forward to seeing what strategies you implement. If you have any questions, do not hesitate to reach out to us via support@lemon.markets. And if you haven’tsigned upyet, do that now!

See you there! 🙌

Joanne

## You might also be interested in

#### Using Time Series Forecasting to predict stock prices 🔮

In this article you will learn what time series forecasting is and how its application in finance looks like. Then you'll also dive into Facebook's Prophet Model for Time Series Forecasting and use it together with the lemon.markets Market Data API to forecast the development of the Tesla Stock.

#### Dummies Guide to Trading with Machine Learning

Ever wonder how a trader with decades of experience on thousands of stocks and lightning fast reaction times might perform in the market? With some machine learning knowledge, you might be able to automate such a trader yourself! 💻 📈

#### 4 reasons why YOU should automate your trading strategy

In the current volatile market conditions, everyone is trying to find ways to minimise portfolio loss. In that context, have you ever thought about automating your trading strategy? In this article, we will dive into 4 reasons for doing so. Expect to learn how it can save you time, make your trading more efficient and lead to data-based decisions.

#### Find more resources to get started easily

Check out our documentation to find out more about our API structure, different endpoints and specific use cases.

#### Interested in building lemon.markets with us?

We are always looking for great additions to our team that help us build a brokerage infrastructure for the 21st century.