Does someone have a good idea how to get the return for a stock for a specific time period e.g. AAPL from 2000-01-01 to 2020-01-01. I know there is something like
periodReturn(AAPL,period='yearly',subset='2000::')
But this is giving me the yearly returns. I actually just want the whole return.
Fully in quantmod functions:
library(quantmod)
aapl <- getSymbols("AAPL", from = "2000-01-01", auto.assign = F)
# first and last get the first and last entry in the timeseries.
# select the close values
# Delt calculates the percent difference
Delt(Cl(first(aapl)), Cl(last(aapl)))
Delt.0.arithmetic
2020-07-08 94.39573
Or in simple maths:
as.numeric(Cl(last(aapl))) / as.numeric(Cl(first(aapl))) - 1
[1] 94.39573
I'm taking the close value of the fist entry. You might take the open, high or low of the day. This has some effect on the return first values in 2000 range from the low 3.63 to the high of 4.01. Depending on your choice the return will be between 104 and 93.9 times your starting capital.