I'm working with some financial data from Yahoo.
My code is
library(forecast)
library(tseries)
library(astsa)
library(fGarch)
library(quantmod)
getSymbols("^gspc",src='yahoo')
adj <- GSPC[, "GSPC.Adjusted", drop = FALSE]
n <- nrow(adj)
simpleReturn <- (adj[2:n,1] - adj[1:(n-1),1]) / adj[1:(n-1),1]
simpleReturn is a table full of zeros I checked and even adj[2,1] - adj[1,1] results in zero, while it should be 1.74
I expected the code to return the simple rate of return for all data-points past the first one
I feel like there is something weird with the class/data type such that simple subtraction does not work as expected. I converted to a tibble and calculated everything just fine: