MulaiMulai sekarang secara gratis

Specifying prefer in add.rule()

Lastly, of the basic rule arguments, there is the aspect of the prefer argument. In quantstrat, orders have a "next-bar" mechanism. That is, if you would gain a signal on Tuesday, the earliest that a position would actually fulfill itself would be on the Wednesday after. However, this can be solved by placing orders to execute on the next possible opening price, rather than wait for an entire day to pass before being able to actually purchase/sell the asset.

Latihan ini adalah bagian dari kursus

Financial Trading in R

Lihat Kursus

Petunjuk latihan

  • Set the prefer argument to "Open".

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Fill in the prefer argument in add.rule()
add.rule(strategy.st, name = "ruleSignal", 
         arguments = list(sigcol = "thresholdexit", sigval = TRUE, orderqty = "all", 
                        ordertype = "market", orderside = "long", 
                        replace = FALSE, prefer = "___"), 
         type = "exit")
Edit dan Jalankan Kode