-2

I am confused about these quantmod functions. If I make an OpCl column and manually create another by Diff <- (GBPUSD$Close - GBPUSD$Open) the two columns are different. How is OpCl calculated?

1 Answers1

3

According to the source code of OpCl

OpCl
function (x) 
{
    xx <- Delt(Op(x), Cl(x))
...

where Delt is

> Delt
function (x1, x2 = NULL, k = 0, type = c("arithmetic", "log")) 
...

 else {
        xx <- lapply(k, function(K.) {
            unclass(x2)/Lag(x1, K.) - 1
        })
    }
...

If we try a reproducible example

library(quantmod)
getSymbols('IBM',src='yahoo')
test <- as.data.frame(head(IBM))
> with(test, lapply(0, function(K.) unclass(IBM.Close)/Lag(IBM.Open, K.)-1)[[1]])
             Lag.0
[1,]  0.0009261373
[2,]  0.0108998044
[3,] -0.0018442288
[4,]  0.0040609012
[5,]  0.0099918652
[6,]  0.0039593808

> OpCl(head(IBM))
           OpCl.head(IBM)
2007-01-03   0.0009261373
2007-01-04   0.0108998044
2007-01-05  -0.0018442288
2007-01-08   0.0040609012
2007-01-09   0.0099918652
2007-01-10   0.0039593808
akrun
  • 874,273
  • 37
  • 540
  • 662