[英]Is there a way to create a column based on a stock's return over a user-defined period?
[英]Get stock return over a specific time period
有人知道如何在特定时间段内获得股票的回报,例如 AAPL 从 2000-01-01 到 2020-01-01。 我知道有类似的东西
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 倍之间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.