Introduction

There are two key features of financial markets:

We might consider these to be the gradual building of a bubble and the swift bursting of the bubble.

Technical analysis seeks to capture these two features.

Technical Analysis

Technical analysis is about understanding the information that is revealed by the evolution of prices. The building blocks to understand price information are bar charts or candlestick charts. These summarise the information about price action over a particular period. These provide information about the way that prices have evolved through the period (hour, day, week).

The quantmod package provides basic charting tools.

These technical tools are alternative ways to measure or present price performance. The tools come from the The technical trading rules package.

For example,

require(quantmod)
getSymbols('BAC')
## [1] "BAC"
chartSeries(BAC, subset = '2024-01::2024-03',
            theme = 'white')

You can change the theme and sub-set the data. You can add additional technical indicators by using the Add.xxx syntax.

require(quantmod)
getSymbols('BAC')
## [1] "BAC"
chartSeries(BAC, subset = '2024-01::2024-03',
            theme = 'white')
addSMA(n = 14, on = 1)
addSMA(n = 30, on = 1, col = 'red')

Moving averages are used to identify trends and changes in trend. While the price and the shorter moving average are above the longer moving average, the up trend remains. However, once the price moves below the shorter moving average there are doubts about the trend. These would be reinforced by a movement of the shorter moving average through the longer moving average and confirmed by the price moving below the longer moving average.

Exercise 1.0

  • Choose a stock and look at the latest candlestick chart. What do the candles say about recent price action?

  • Add one or two moving averages. What do they say about current and medium-term momentum?

Momentum

The key idea of technical analysis is the trend is your friend.

This is the relatively easy part. More challenging is deciding when the trend is going to start and when it is going to change. There are many measures of momentum that seek to use the change in prices to identfy changes.

Among the tools that are used to measure momentum are:

Bollinger bands

One standard way to identify an increased risk of a change in trend is to look for extreme moves. These are likely to have taken place when investors are excited, emotional and liable to over-react. One way to identify an extreme move is to compare it to the standard deviation of recent returns. Recall that only 5% of cases should come more than 2 standard deviations from the mean. Those outcomes can be called extreme and more likely to show reversal. The standard Bollinger Band will show a 20-day moving average of the typical price. The typical price is (high + low + close)/3, but the moving average of the close can be used instead. The upper and lower bands are two standard deviations above and below the moving average.

chartSeries(BAC, subset = '2024', theme = 'white')
addBBands()

Exercise 2.0

  • Add the Bollinger bands to the chart that you created.
  • What do the bands suggest for the immediate future?

MACD

MACD is an oscillator that was developed by Gerald Appel. It compares two moving average to try to understand trends. It can be used on price or volume.

chartSeries(BAC, subset = '2024', theme = 'white', TA = NULL)
addMACD()

You can see that the plot provides two moving aveages (one fast and one slow) and a histogram of the difference between the two.

If you read the RedTower Technical Analysis Handbook, you will see that momentum indicators are frequently trying to find where the market is overbought and oversold.

A market is said to be “overbought” when prices have been trending higher in a relatively steep fashion from some time, to the extent that the number of market participants “long” of the market significantly outweighs those on the sidelines or holding “short” positions. This means that there are fewer participants to jump onto the back of the trend. “Oversold” conditions exist where the opposite applies, the market has been trending lower for some time and is running out of “fuel” for further price declines. Overdone conditions are often the precursor to a correction in the market or in extreme cases a turn in trend.

Celaya, G. (2013), RedTower Technical Analysis Handbook, p15.

Exercise 3.0

  • Take a look at the MACD Oscillator documentation to understand how it works.

  • Add the MSCD Oscillator to your chart. What signals do you think that you can draw from it?

  • You can read about trading strategies here

Ichimoku Cloud

If you want to take comparison of moving average to an extreme, you might want to look at Ichimoku clouds. There is a R package devoted to this: