有人对如何获得特定时间段的股票收益有一个好主意吗,例如从2000-01-01到2020-01-01的AAPL。我知道有类似的东西
periodReturn(AAPL,period='yearly',subset='2000::')
但这给了我每年的回报。我实际上只是想要整个回报。
完全具备quantmod功能:
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
或用简单的数学方法:
as.numeric(Cl(last(aapl))) / as.numeric(Cl(first(aapl))) - 1
[1] 94.39573
我以第一笔入账的收盘价为准。您可能会选择开放,一天中的高点或低点。这会对2000年的返回优先值产生影响,范围从低3.63到高4.01。根据您的选择,回报将是启动资金的104到93.9倍。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句