I am new to R and trying to develop a back testing strategy using MACD function from TTR package.
I am observing a wired behavior where I get different results for the same data set.
Here are the commands I am executing...
# Restarting R session...
library( quantmod )
getSymbols( c('INDRAMEDCO.BO'), from="2016-01-01" )
# [1] "INDRAMEDCO.BO"
macd <- MACD(INDRAMEDCO.BO[, "Adjusted"], 12, 26, 9, percent=FALSE)
last(macd)
# macd signal
# 2016-08-04 3.031666e-317 2.521193e-317
macd <- MACD(INDRAMEDCO.BO[, "Adjusted"], 12, 26, 9, percent=FALSE)
last(macd)
# macd signal
#2016-08-04 4.100941e-317 -2.366901e-318
macd <- MACD(INDRAMEDCO.BO[, "Adjusted"], 12, 26, 9, percent=FALSE)
last(macd)
# macd signal
#2016-08-04 -6.664617e-317 -4.561214e-317
Note how MACD and Signal values change on every execution on same data and same parameters to MACD function. I am not sure what I am doing wrong.
Note: I am using RStudio IDE. Not sure if it matters.
Use this:
macd <- MACD(INDRAMEDCO.BO[, "INDRAMEDCO.BO.Adjusted"], 12, 26, 9, percent=FALSE)
last(macd)
macd signal
2016-08-04 0.3242379 0.3371936
There is not "Adjusted"
column in the data.