开始使用免费开始使用

Specifying orderside in add.rule()

The next critical argument to specify in your order is orderside, which can take two values: either long or short. In quantstrat, long and short side trades are siloed off separately so that quantstrat knows whether a trade is a long trade or a short trade. A long trade is one that profits by buying an asset in the hopes that the asset's price will rise. A short trade is one that sells an asset before owning it, hoping to buy it back later at a lower price.

For your strategy, you will want to take only long orders.

本练习是课程的一部分

Financial Trading in R

查看课程

练习说明

  • The add.rule() command from the previous exercise has been loaded into your workspace.
  • Define your order side as long by specifying the orderside argument.

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Fill in the orderside argument in add.rule()
add.rule(strategy.st, name = "ruleSignal", 
         arguments = list(sigcol = "filterexit", sigval = TRUE, orderqty = "all", 
                        ordertype = "market", orderside = "___", 
                        replace = FALSE, prefer = "Open"), 
         type = "exit")
编辑并运行代码