【问题标题】:Holding portfolios over a month/quarter/year in quantstrat在 quantstrat 中持有超过一个月/季度/年的投资组合
【发布时间】:2017-02-15 12:18:55
【问题描述】:

作为上一个问题的变体,我想知道如何使用 quantstrat 包实现持有期,该包可防止投资组合在多个股票的周期之间更新,尽管有信号(此处为跨越阈值)。

我尝试了两种方法,都失败了:

  • 在股票数据中添加了一个以 1 表示季度/学期/年的列,与 name="ruleSignal" 的 add.rule 一起使用,

  • 使用带有 type="rebalance" 和参数的 add.rule relabance_on="宿舍"。

这是 quantstrat 中的代码:

asda

  ## Signal 1: rank inferior to N 
  stratjt=add.signal(strategy=stratjt, name="sigThreshold",
                          arguments=list(threshold=N, column="Rank", 
                                         relationship="lte",cross=FALSE), 
                          label="Lower.dcl.thres")
  ## Signal 2: rank superior to N
  stratjt <- add.signal(strategy=stratjt, name="sigThreshold", 
                          arguments=list(threshold=N, column="Rank", 
                                         relationship="gt", cross=FALSE), 
                          label="Higher.dcl.thres")

  # Rule 1: First attempt to add rebalance rule based on extra signal column
  #stratjt <- add.rule(strategy=stratjt, name='ruleSignal', 
  #                   arguments = list(sigcol="Rebalance_on", sigval=TRUE, 
  #                                   orderqty=1, ordertype='market', 
  #                                  orderside='long', pricemethod='market', 
  #                                 replace=FALSE, osFUN=osMaxPos), 
  #                   type='enter', path.dep=TRUE)

  # Rule 1: Second attempt to add rebalance rule using the "rebalance" rule type
  stratjt <- add.rule(strategy=stratjt, name='ruleSignal', 
                      arguments = list(rebalance_on="quarters"), 
                      type='rebalance', path.dep=TRUE)

  # Rule 2: Enter rule when below threshold
  stratjt <- add.rule(strategy=stratjt, name='ruleSignal', 
                        arguments = list(sigcol="Lower.dcl.thres", sigval=TRUE, 
                                         orderqty=max.size, ordertype='market', 
                                         orderside='long', pricemethod='market', 
                                         replace=FALSE, osFUN=osMaxPos), 
                        type='enter', path.dep=TRUE)

   # Rule 3: add exit rule when above threshold
  stratjt <- add.rule(strategy = stratjt, name='ruleSignal', 
                        arguments = list(sigcol="Higher.dcl.thres", sigval=TRUE, 
                                         orderqty='all', ordertype='market', 
                                         orderside='long', pricemethod='market', 
                                         replace=FALSE), 
                        type='exit', path.dep=TRUE)

注意:我也使用了 applyStrategy.rebalance 函数。

这是输出的一部分:

[1] "2000-04-30 00:00:00 Vivendi -1 @ 99.2256"
[1] "2002-11-30 00:00:00 Vivendi 1 @ 16.2966"
[1] "2003-02-28 00:00:00 Vivendi -1 @ 14.0564"
[1] "2003-11-30 00:00:00 Vivendi 1 @ 22.9647"
[1] "2004-01-31 00:00:00 Vivendi -1 @ 26.3656"
[1] "2004-02-29 00:00:00 Vivendi 1 @ 28.7848"
[1] "2004-03-31 00:00:00 Vivendi -1 @ 26.2421"
[1] "2006-05-31 00:00:00 Vivendi 1 @ 35.8552"

如您所见,交易继续在季度之间进行,而我希望仅在新的季度或学期等中实施交易...... 任何帮助表示赞赏。

干杯, 迈克

【问题讨论】:

    标签: r quantitative-finance quantstrat


    【解决方案1】:

    您需要更改退出规则信号。目前它被设置为根据“Higher.dcl.thres”而不是时间段退出交易。

    创建另一个指标,它会在您指定的时间段后返回 TRUE 读数。当您收到入场信号时,让您的时间段开始。

    使用此指标创建另一个退出信号,并将该信号用于您的退出规则。我希望这是有道理的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-06
      • 2019-10-01
      • 2020-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      相关资源
      最近更新 更多