![](/img/trans.png)
[英]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.