Krug
Krug

Reputation: 1013

Quantstrat add.rule arguments: orderqty vs tradeSize vs maxSize

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.

Upvotes: 4

Views: 1071

Answers (2)

FXQuantTrader
FXQuantTrader

Reputation: 6891

@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.

Upvotes: 5

boniface316
boniface316

Reputation: 499

I just finished reading that blog and saw this question. I will answer my best!

According to Guy Yollin's notes. orderqty is the main argument. I dont see him using any other arguments in his rule.

Hope this answers your question.

Upvotes: 3

Related Questions