Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quantstrat add.rule arguments: orderqty vs tradeSize vs maxSize

Tags:

r

quantstrat

I can't find in the Quantstrat documentation the definition of the add.rule arguments. I'm interested in knowing what is the difference between orderqty, tradeSize and maxSize.

Found the following related material on quantstrattrader:

The orderqty argument applies only when there’s no osFUN specified. It can take a flat value (E.G. 1, 2), or, when the rule type is “exit”, a quantity of “all”, to flatten a position.

The osFUN specifies the order-sizing function to use. The osFUN argument is actually a function object that gets passed in as an argument. If you do not wish to use an osFUN, simply use a flat quantity, such as 100, or if using exit type orders, use “all” to flatten a position.

This is how an add.rule function looks like:

 add.rule(strategy.st, name = "ruleSignal",
          arguments = list(sigcol = "longsig",
                           sigval = TRUE,               
                           ordertype = "market",
                           prefer = "Open",            
                           orderside = "long",
                           orderqty = 100,
                           replace = FALSE,            
                           osFUN = osMaxPos,
                           tradeSize = 100,
                           maxSize = 100),
          type = "enter")

Thank you.

like image 544
Krug Avatar asked Sep 18 '25 23:09

Krug


1 Answers

@blackknight316 is right. Take a look at the code for ruleSignal (print ruleSignal). You'll see no formal arguments exist for tradeSize or maxSize.

Yet the ruleSignal function doesn't generate an error when it is called because it uses the ellipses argument (which is ...). Read about this special parameter in the official R language documentation.

Print ruleSignal and take a look at the source. This is one part:

orderqty <- osFUN(strategy = strategy, data = mktdata, 
                timestamp = timestamp, orderqty = orderqty, ordertype = ordertype, 
                orderside = orderside, portfolio = portfolio, 
                symbol = symbol, ... = ..., ruletype = ruletype, 
                orderprice = as.numeric(orderprice))

which uses ... (as does addOrder).

tradeSize and maxSize are included in add.rule in the linked code probably because they are passed through to the ordersizing function used in the example you link. See the argument osFUN=osDollarATR which is actually an object which is a function. osDollarATR is of course user defined by the author. You'll probably find the definition of that function in another blog post there and see tradeSize and maxSize are formal arguments to it.

like image 170
FXQuantTrader Avatar answered Sep 21 '25 16:09

FXQuantTrader