【问题标题】:How can I get exactly date that has highest Close price each weeks? I use quantmod package in r我怎样才能获得每周最高收盘价的确切日期?我在 r 中使用 quantmod 包
【发布时间】:2015-09-19 04:45:11
【问题描述】:

我是 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

你能给我一些建议吗?

【问题讨论】:

    标签: r quantmod stock


    【解决方案1】:

    您可以使用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))
    

    【讨论】:

      猜你喜欢
      • 2021-10-26
      • 1970-01-01
      • 1970-01-01
      • 2018-04-05
      • 2018-04-05
      • 2022-12-09
      相关资源
      最近更新 更多