簡體   English   中英

我怎樣才能准確地獲得每周最高收盤價的日期? 我在r中使用quantmod包

[英]How can I get exactly date that has highest Close price each weeks? I use quantmod package in r

我是R的新手,因此嘗試獲取了最高收盤價的日期。 我在quantmod包中使用了功能period.max 這是我的代碼。

library(quantmod)
getSymbols("GE")
period.max(Cl(GE),endpoints(GE,on='weeks'))

但是結果返回了最高收盤價,但這不是相關日期,而不是幾周的最后一天。

2007-01-05 37.97
2007-01-12 37.92
2007-01-19 38.11
2007-01-26 36.75
2007-01-26 36.75
2007-02-09 36.37
2007-02-16 36.47

你能給我一些建議嗎?

您可以使用splitlapplydo.call方法執行此操作:

# helper function to return the maximum row
get.max <- function(x) x[which.max(x),]
# split on weeks, loop over each week and get max, rbind back together
week.max <- do.call(rbind, lapply(split(Cl(GE), "weeks"), get.max))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM