I am trying to compute various technical indicators that will be used to predict the stock price movement of around 100 stocks. For example, I want to calculate the Average True Range (ATR) for each of the companies in my time series, which I am trying to do with the TTR package in R. However, the problem is that I can't figure out how to do it for each of the companies in my dataset. I have tried to use dplyr::group_by(company) which doesn't work.
data_ATR <- data_price %>%
dplyr::group_by(company) %>%
TTR::ATR(data_price[,c("PRICE HIGH", "PRICE LOW", "CLOSING PRICE")], n=14)
Any help would be greatly appreciated!
We may use
group_modify
hereUpdate
If there are NAs we may need to get the index of the first non-NA row among all the subset of columns
Using a reproducible example
data