【问题标题】:Quantmod add indicators and save as csv (no chart)Quantmod 添加指标并保存为 csv(无图表)
【发布时间】:2012-02-23 21:57:00
【问题描述】:

我对 R 和 Quantmod 非常陌生。

是否可以添加像 MACD 这样的指标并将时间序列保存为 csv?

显示图表非常简单:

getSymbols("AAPL",src="yahoo") 
barChart(AAPL)
addMACD()

但我想将指标添加到时间序列中(将其保存为 csv)并且不想显示它:)

谢谢!

如何告诉移动平均线使用收盘? e

以及如何向 csv 添加其他列?

【问题讨论】:

    标签: r quantmod


    【解决方案1】:

    您可以使用cbind 来添加信号。

    library(quantmod)
    getSymbols("AAPL",src="yahoo")
    d <- cbind( AAPL, MACD( AAPL ) )
    write.csv(
      data.frame( date=index(d), coredata(d) ),
      row.names=FALSE,
      file="tmp.csv"
    )
    

    【讨论】:

    • 谢谢 :) 我会在家里检查一下
    • +1,虽然我建议使用write.zoo 而不是write.csv
    【解决方案2】:
    library(quantmod)
    foo=getSymbols("AAPL",src="yahoo") 
    # tip: use ?barChart to see usage. The option plot=FALSE turns off plotting
    x=barChart(foo,plot=FALSE)
    # Look up ?MACD for a reference.
    # x is a S4 object (https://github.com/hadley/devtools/wiki/S4) 
    ts_data=data.frame(cbind(x@xdata),MACD(x@xdata))
    # ?write.csv is a function that will write this data frame to your current directory
    write.csv(ts_data,file="my_data.csv")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-04
      • 1970-01-01
      • 2020-09-26
      相关资源
      最近更新 更多