I'm playing with R and xts to create a theoretical scenario where 10k was invested into a stock, and see how it would have grown. I can do everything up to calculating stock returns, but I don't know how to add a new column to an xts that would take the 10k and estimate growth over time.
Put simply, how do I have xts make a new column where x (10K) is the starting value, and every point after is the previous month's x*returns?
My code so far:
quantmod::getSymbols("^GSPC", src="yahoo")
GSPC.Returns <- quantmod::periodReturn(GSPC)
GSPC.Returns <- GSPC.Returns*100+100
y <- GSPC.Returns["2019/"]
x <- 10000
y$blargh <- x*y[,"monthly.returns"] # This is the problematic line