【问题标题】:Adding Indicator Quantstrat R添加指标 Quantstrat R
【发布时间】:2016-10-25 12:14:27
【问题描述】:

我想在 quantstrat 中添加自定义指标,但该指标不是根据价格序列计算得出的。例如:

# Get SPY from Yahoo Finance
getSymbols("SPY", from = "2016-01-01", to = "2016-01-31", src =  "yahoo", adjust =  TRUE)
SPY <- SPY[,1:4]

#Create Indicator
set.seed(123)
indicator <- sample(seq(from = 0, to = 100, by = 5), size = nrow(SPY), replace = TRUE)

如何将该指标添加到我的策略中并从中产生信号?我所发现的只是添加指标的基本符号,但是是否可以添加已经计算的指标?

# Add a 5-day simple moving average indicator to your strategy
add.indicator(strategy = strategy.st,
              # Add the SMA function
              name = "SMA",
              # Create a lookback period
              arguments = list(x = quote(Cl(mktdata)), n = 5),
              # Label your indicator SMA5
              label = "SMA5")

【问题讨论】:

    标签: r indicator quantstrat


    【解决方案1】:

    我喜欢使用“ifelse”功能

       Rule1<-function(price,SMA,...)
      {ifelse(price>SMA,1,-1)}
    add.indicator(strategy=strategyname,name="SMA",
              arguments=list(x=quote(mktdata$Close),n=5),label="SMA40")
    add.indicator(strategyname, name="Rule1", arguments=list(price = quote(mktdata$Close), SMA=quote(mktdata$SMA.SMA5)), label="Rule1Signal")
    

    这将为您提供 SMA 和一列,其中 1 可用作买入信号或 -1 可用作卖出信号。

    【讨论】:

    • #camerongiles 你的解决方案不是仍然依赖间谍价格吗?与 #Viitama 一样,我们有外部数据数据,并且正在努力在 quantstrat 中使用它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-13
    • 1970-01-01
    相关资源
    最近更新 更多