ComeçarComece de graça

The SMA and RSI functions

Welcome to the chapter on indicators! An indicator is a transformation of market data that is used to generate signals or filter noise. Indicators form the backbone of many trading systems, and the system you will build in this course uses several of them.

The simple moving average (SMA) and relative strength index (RSI) are two classic indicators. As you saw in Chapter 1, the SMA is an arithmetic moving average of past prices, while the RSI is a bounded oscillating indicator that ranges from 0 to 100. Their respective functions SMA() and RSI() both take in a series of prices, denoted by x and price respectively, and a lookback period n, for example:

SMA(x = Cl(GDX), n = 50)
RSI(price = Cl(GDX), n = 50)

In this exercise, you will practice calling the base functions for these indicators. The quantmod and TTR packages and SPY data have been loaded for you.

Este exercício faz parte do curso

Financial Trading in R

Ver curso

Instruções do exercício

  • Create a 200-day SMA of the closing price of SPY. Call this spy_sma.
  • Create an RSI with a lookback period n of 3 days using the closing price of SPY. Call this spy_rsi.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Create a 200-day SMA
spy_sma <- SMA(___)

# Create an RSI with a 3-day lookback period
spy_rsi <- RSI(___)
Editar e executar o código