R 获取特定时间段内的股票回报
是否有人知道如何获得特定时间段的股票回报,例如2000-01-01至2020-01-01的AAPL。我知道有点像R 获取特定时间段内的股票回报,r,quantmod,R,Quantmod,是否有人知道如何获得特定时间段的股票回报,例如2000-01-01至2020-01-01的AAPL。我知道有点像 periodReturn(AAPL,period='yearly',subset='2000::') 但这是给我的年度回报。实际上,我只想要全部退货。完全使用quantmod函数: library(quantmod) aapl <- getSymbols("AAPL", from = "2000-01-01", auto.assig
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
我取第一次进入的接近值。你可以采取开放的,高或低的一天。这对2000年从低3.63到高4.01的首次返回值范围有一定影响。根据您的选择,回报率将在起始资本的104到93.9倍之间。您是否需要
period='daily'
Hmm。。。我只想知道我的总回报是多少。。。假设我在2000年1月1日花一美元购买AAPL,那么今天的价格是多少
as.numeric(Cl(last(aapl))) / as.numeric(Cl(first(aapl))) - 1
[1] 94.39573