I am new in R and I try to use apply function on the xts zoo class, however it shows error. I have a formula: ((2*Close-High-Low)/(High-Low)) * Volume
Input:
y <- getSymbols("0005.HK", auto.assign = FALSE, src = "yahoo")
Error:
y$II <- apply(y,2,function(x) (2Cl(x) - Hi(x) - Lo(x)) / ((Hi(x) - Lo(x)) * Vo(stk)))
Error: unexpected symbol in "apply(y,2,function(x) (2Cl"
and then I tried another one:
Error:
y$II <- apply(y,2,function(x) (2(x[,4]) - x[,2] - x[,3]) / (x[,2] - x[,3]) * x[,5])
Error in FUN(newX[, i], ...) : attempt to apply non-function
After that, I would like to sum the y$II 21 days but I don't know how to do apply function to sum 21 days between every 21 days
IIstd = Sum of 21 ((2*C-H-L)/(H-L)) * V
IInorm = (IIstd / Sum 21 day V) * 100
Anyone can help me ? Please advice, thanks.