Machine Learning for Trading--2-6 Technical Analysis

  • Technical vs. Fundamental Analysis
  • Characteristics of Technical Analysis
  • When is Technical Analysis Effective
  • A Few Good Indicators
  • Normalization

Technical vs. Fundamental Analysis

There are two broad categories of approaches to use when choosing stocks to buy or sell: fundamental analysis and technical analysis.

  • Fundamental analysis involves looking at aspects of a company in order to estimate its value. Fundamental investors typically look for situations where the price of a company is below its value.
  • Technical analysis, on the other hand, isn’t concerned with the underlying value of a company; instead, technicians look for patterns or trends in a stock’s price.

Characteristics of Technical Analysis

What it is?

  • One of the most important things to remember about technical analysis is that it considers only price and volume data, as opposed to fundamental analysis, which looks at factors such as earnings, dividends, cash flows, book value, and more.
  • We look back at historical price and volume data to compute statistics, also known as indicators. These indicators serve as heuristics that might hint at buying or selling opportunities.

Why it might work?

  • There is significant criticism of the technical approach, and many people consider it an inappropriate method for investing because it doesn’t consider the value of the company. Instead, we might think of technical analysis as a trading approach, rather than an investing approach.
  • However, there are reasons to believe that technical analysis might have value. There is information in price and price change, as these data points reflect sentiments of buyers and sellers. Especially when the price for a particular stock is moving against the overall market, pricing data and volume can present trading opportunities.
  • Additionally, while we know that heuristics cannot guarantee outcomes, we also know, from other domains of artificial intelligence, that heuristics are valuable and are frequently used to inform critical decisions.

characteristics

Potential Indicator Quiz

Let’s look at the following four factors. Which of these are fundamental, and which are technical?

quiz

P/E ratio considers both price and earnings, making it a fundamental factor, as well as intrinsic value, which is based on dividends.

When is Technical Analysis Effective?

Back in the 1980s and 1990s, when many of the well-known indicators were developed, they may have had reliable predictive power. Since that time, however, more people have been trading according to these indicators. Generally, the more people that follow a particular investing approach, the less value any one investor realizes. As a result, individual indicators are only weakly predictive today.

That being said, combining multiple indicators still adds value. Combinations of three to five technical indicators, in a machine learning context, may provide a much stronger predictive system than just a single indicator.

Technical analysis can also be useful at highlighting contrast; in other words, revealing when two stocks - or one stock and the market - have widely different values for a particular indicator. Such a contrast might be indicative of an actionable opportunity.

Finally, technical analysis generally works better over the short term than over the long term.

effective

To understand the value of technical analysis as compared to fundamental analysis, we need to consider the trading horizon: the amount of time that elapses between buying and selling a stock. Trading horizons can vary from milliseconds to years.

When we are rapidly executing trade orders, the only factors that matter are those present on the stock exchange, such as price movement and trading volume. For these very short trading horizons, fundamental factors have quite low value.

For a trading horizon of days, fundamental factors may have some value; in general, the longer the trading horizon, the more valuable fundamental factors are.

Let’s now consider technical factors. How valuable is a technical indicator, such as a 20-day momentum, in determining the price of a stock years later? Such indicators have little value when considering a trading horizon of years.

For a very short trading horizon, however, technical analysis can shine. In the span of a few milliseconds, the only factors about a stock that have changed are technical factors, and, as a result, technical analysis can potentially have high value over trading horizons of this size.

For a trading horizon of days, technical factors may have some value; in general, the longer the trading horizon, the less valuable technical factors are.

Let’s consider the value of decision complexity and decision speed across the range of trading horizons.

Over a period of years, a lot can happen to a company, and, correspondingly, its stock price. As a result, we can appreciate a complex decision-making process for investments with a trading horizon of this length.

Decision speed is not as important when considering investments that we plan to hold for years. Relative to this investment horizon, it doesn’t so much matter if it takes us a minute or a day to make an investment decision.

When considering a much shorter trading horizon, decision speed is of utmost importance. If we want to buy and sell stock over the period of milliseconds, we can’t take seconds to make decisions. Correspondingly, we also value decision complexity less at a trading horizon of this size.

When trading at very high frequencies, we need to leverage technical analysis to make many simple decisions very quickly. Thankfully, these decisions are often simple enough to capture in computer code. As a result, we often see computers trading over these shorter trading horizons.

Let’s think about the different types of hedge funds we might find in the wild. On the one hand, we might see an HFT-based fund using technical analysis to trade over a millisecond horizon. On the other hand, we might find an insight-driven, human-based hedge fund holding positions for much longer. In between, we often see humans and computers working together.

value

A Few Good Indicators

Momentum

Momentum refers to the relative change in price for a stock over a certain number of days.

The slope of the line connecting the two points indicates the strength of the momentum, either positive or negative.

Generally, if we want to quantitatively calculate the n-day momentum,at day t, using a sequence of prices, we can use the following formula.

1
momentum[t] = (price[t] / price[t-n]) - 1

This formula gives us a number indicating how much the price of a stock has risen or fallen between day t−n and day t. We typically see numbers for momentum between -0.5, for a significant price drop, and 0.5, for a significant price jump.

indicators

Simple Moving Average

Our next indicator is simple moving average (SMA), which, given n, computes the average price over the previous n days, known as an n-day window.We don’t have to compute the SMA for only a single day. Instead, we can repeatedly slide our window forward one day to compute the n-day SMA for every day from n to today. The plot of such an SMA (red line) is shown below.

indicators

There are at least two different ways that technicians use simple moving averages in their trading strategies. First, they look for places where the current price crosses through the SMA, as seen below.

indicators

Such crossovers tend to be significant events, especially when n is quite large. Coupled with supporting momentum, a crossover might constitute a strong buy or sell signal.

Technicians might also use simple moving average as a proxy for underlying value. In other words, if we calculate the average price over a large enough window, we might be able to estimate the true value of the company.

If we see a large excursion from such a simple moving average, we should expect that the price is going to regress toward that average. Given that knowledge, excursions may present trading opportunities.

Generally, if we want to quantitatively calculate the n-day simple moving average, SMA, at day t, using a sequence of prices, p, we can use the following formula.

1
SMA[t] = (price[t] / price[t-n:t].mean()) - 1

We can also quantify buy and sell signals. If SMA[t] > 0, it is a buy signal, and if SMA[t] < 0, it is a sell signal.

Similar to momentum, values for SMA typically range from -0.5 to 0.5.

Bollinger Bands

John Bollinger observed that, for a stock experiencing low volatility, we should use a relatively smaller value for our signal, and, for a stock experiencing high volatility, we should use a relatively larger value.

We can accomplish such dynamic signaling using a statistic, derived from the pricing data itself, that captures volatility. Specifically, that statistic is standard deviation. For each day, we can take the standard deviation of the prices that constitute the simple moving average for that day. Given this standard deviation, we typically create Bollinger Bands two standard deviations above and below the simple moving average.

The bands are tighter for periods of low volatility, and a relatively smaller excursion is enough to break out of the bands. In periods of higher volatility, the bands are much wider, and we only see crossovers for more aggressive deviations.

We can use Bollinger Bands in our trading strategies. A general rule of thumb is: look for times when the price crosses from the outside of a band to the inside.

Conversely, when we see price crossing over from the outside to the inside of the bottom band, we might consider buying.

Generally, if we want to quantitatively calculate the Bollinger Bands, BB, on a given day, t, from a sequence of prices, using an n-day moving average, SMA, we can use the following formula.

1
BB[t] = (price[t] - SMA[t]) / (2 * std[t])

We typically see values for BB[t] between -1.0 and 1.0. In other words, the price rarely breaks out of the Bollinger Bands. Of course, this makes sense, as they are placed two standard deviations outside of the mean.

By comparing the value of BB over two consecutive days, B[t] and B[t-1], we can quantify buy and sell signals. Specifically, if B[t-1] < -1.0 & B[t] > -1.0, it is a buy signal. Conversely, when B[t-1] > 1.0 & B[t] < 1.0, it is a sell signal.

indicators

Buy or Sell Quiz

Let’s consider how we might trade using Bollinger Bands. Consider the four events below, each of which involves the price of a stock crossing over a Bollinger Band. For each event, determine if the event demonstrates a buying opportunity, a selling opportunity, or no opportunity at all.

quiz

Normalization

The technical indicators that we have discussed so far - simple moving averages, momentum, and Bollinger Bands - each have ranges of values over which they typically operate. For example, we might expect to see values between -0.5 and 0.5 for both simple moving averages and momentum, while we typically see values for Bollinger bands between -1.0 to 1.0.

If we were to plug these indicators into a machine learning algorithm, we might see the algorithm placing more importance on the Bollinger Bands because this indicator can take on values of a larger magnitude than the other indicators.

This undue overweighting of a particular factor might be even more visible if we include a fundamental indicator, like P/E ratio, which can range from 1 to 300.

The solution to this problem is normalization, which takes each of these parameters and compresses or stretches them so that they vary, on average, from -1 to 1, with a mean of 0.

Normalizing values is simple. Given a set of original values, we can calculate the normalized values as follows.

1
normed = (values - mean) / values.std()

Normalization

您的支持将鼓励我继续创作