How i get automatically n(Number of periods) in a exponential moving average

rstudio

#1

hi, i need help, can you help me ?
I make this code:
library(TTR)
library(pracma)
library(zoo)

#EMA
ema <- EMA(dataset$um, n = 10, wilder = FALSE, ratio = NULL)
dataset$EXPMEDIA=coredata(ema)

But i want the better n, How can I get the best value automatically?


#2
n = 10

is the EMA default argument. See

help(SMA)

The best n depends on what you want to do. In EMA, it is used to calculate the number of periods in the moving average, and the help page indicates possible instability for small values.

If your number of rows is, say, 1000, I'd try n= 25, 250, and 500 to see how your result changes.