简体   繁体   English

获取特定时间段内的股票收益

[英]Get stock return over a specific time period

Does someone have a good idea how to get the return for a stock for a specific time period eg AAPL from 2000-01-01 to 2020-01-01.有人知道如何在特定时间段内获得股票的回报,例如 AAPL 从 2000-01-01 到 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:完全在 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

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.这对 2000 年从低点 3.63 到高点 4.01 的回报有一些影响。 Depending on your choice the return will be between 104 and 93.9 times your starting capital.根据您的选择,回报将在您的起始资本的 104 到 93.9 倍之间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM