ruleSignal: default rule to generate a trade order on a signal

Description Usage Arguments Details See Also

Description

As described elsewhere in the documentation, quantstrat models orders. This function is the default provided rule function to generate those orders, which will be acted on later as they interact with your market data.

Usage

1
2
3
4
5
6
ruleSignal(mktdata = mktdata, timestamp, sigcol, sigval, orderqty = 0,
  ordertype, orderside = NULL, orderset = NULL, threshold = NULL,
  tmult = FALSE, replace = TRUE, delay = 0.0001, osFUN = "osNoOp",
  pricemethod = c("market", "opside", "active"), portfolio, symbol, ...,
  ruletype, TxnFees = 0, prefer = NULL, sethold = FALSE, label = "",
  order.price = NULL, chain.price = NULL, time.in.force = "")

Arguments

mktdata

an xts object containing market data. depending on rules, may need to be in OHLCV or BBO formats, and may include indicator and signal information

timestamp

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

sigcol

column name to check for signal

sigval

signal value to match against

orderqty

numeric quantity of the desired order, or one of 'all'/'trigger', modified by osFUN

ordertype

one of "market","limit","stoplimit", "stoptrailing", or "iceberg"

orderside

one of either "long" or "short", default NULL, see details

orderset

tag to identify an orderset; if one order of the set is filled, all others are canceled

threshold

numeric or name of indicator column in mktdata, default NULL, see Details

tmult

if TRUE, threshold is a percent multiplier for price, not a scalar. Threshold is converted to a scalar by multiplying it with the price at the time of order entry (i.e. the scalar will not change if the order is updated, as in the case of a trailing stop), then it is added to the price just like a scalar threshold.

replace

TRUE/FALSE, whether to replace any other open order(s) on this portfolio symbol, default TRUE

delay

what delay to add to timestamp when inserting the order into the order book, in seconds

osFUN

function or text descriptor of function to use for order sizing, default osNoOp

pricemethod

determines how the order price will be calculated, see Details

portfolio

text name of the portfolio to place orders in

symbol

identifier of the instrument to place orders for. The name of any associated price objects (xts prices, usually OHLC) should match these

...

any other passthru parameters

ruletype

one of "risk","order","rebalance","exit","entry", see add.rule

TxnFees

numeric fees (usually negative) or function name for calculating TxnFees (processing happens later, not in this function)

prefer

price method for getPrice

sethold

boolean, puts entry Rule processing on hold, default FALSE

label

rule label, default ”, added by applyRules

order.price

the order price to use, will overrule any mktdata lookup as well as chain.price (see below), meant to specify eg. a stop-loss price that is unrelated to the fill price (see chain.price)

chain.price

the price that the parent order got filled for, used to pass to children in the order chain, will overrule all mktdata lookup, only meant for internal use really, default NULL

time.in.force

timestamp time-in-force; either a time stamp, or a number of seconds, or 'GTC' / ”, 'GTC' and ” both meaning 'Good Till Canceled'; order expires if still 'open' at this timestamp, default is ”

Details

pricemethod may be one of

'market', 'opside', or 'active'

will use the 'ask' price if you're buying and the 'bid' price if you're selling, crossing the market at the time of order entry to attempt to set an aggressive price to get the trade.

'passive', 'work' or 'join'

which will join the 'bid' price if you are buying or join the 'ask' price if you are selling, passively working to make liquidity at the prevailing market price without crossing the market at time of order entry

'maker'

will create a pair of orders for both bid and offer, modeling market making activities by having orders on both sides. This will then create an Order.Set, and use the threshold to set the prices for these orders.

orderqty should be either numeric, or one of 'all'/'trigger'. 'all' can only be used with order of ruletype='exit' or 'risk', and will close the entire position. 'trigger' can only be used with ruletype='chain' and is exactly identical to 'all', except that the actual transaction is suppressed, and can be used to kick in a new order chain.

If threshold is not numeric or NULL it should be the name of an indicator mktdata column holding the threshold values.

If orderside is NULL, the function will attempt to calculate the side from the current position (if any), the order quantity, and the order type.

See Also

osNoOp , add.rule


redmode/quantstrat documentation built on May 27, 2019, 4:04 a.m.