ruleOrderProc: process open orders at time _t_, generating transactions or...

Description Usage Arguments Details See Also

View source: R/ruleOrderProc.R

Description

The ruleOrderProc function is effectively the default fill simulator for quantstrat. This function is meant to be sufficient for backtesting most strategies, but would need to be replaced for production use. It provides the interface for taking the order book and determining when orders become trades.

In this version, in contrast with an earlier version, this function will allow a transaction to cross your current position through zero. The accounting rules for realizing gains in such cases are quite complicated, so blotter will split this transaction into two transactions. Many brokers will break, revise, or split such transactions for the same reason.

Usage

1
2
ruleOrderProc(portfolio, symbol, mktdata, timestamp = NULL,
  ordertype = NULL, ..., slippageFUN = NULL)

Arguments

portfolio

text name of the portfolio to associate the order book with

symbol

identfier of the instrument to find orders for. The name of any associated price objects (xts prices, usually OHLC or BBO) should match these

mktdata

an xts object containing market data. depending on indicators, may need to be in OHLCV or BBO formats, default NULL

timestamp

timestamp coercible to POSIXct that will be the time the order will be processed on

ordertype

one of NULL, "market","limit","stoplimit", or "stoptrailing" default NULL

...

any other passthru parameters

slippageFUN

default NULL, not yet implemented

Details

This function would need to be revised or replaced for connection to a live trading infrastructure. In a production mode, you would replace the addOrder function with a custom function to connect to your market infrastructure. In that case, you might need to add additional code to your strategy, or overload functions for checking position.

Note that this function is called by default in the 'orders' slot of the applyRules processing. If you have defined another order processing rule, it will replace this function. If you want your custom order rule and ruleOrderProc to both be called, you will need explicitly add a rule to call ruleOrderProc either before or after your custom order processing function.

We would like to model slippage here via slippageFUN. Code contributions, suggestions, and requests appreciated.

See Also

add.rule

applyRules

getOrderBook

addOrder

updateOrders


cloudcell/quantstrat documentation built on May 13, 2019, 8:03 p.m.