addPosLimit: add position and level limits at timestamp

Description Usage Arguments Details See Also

View source: R/osFUNs.R


Many strategies will not be allowed to trade unconstrained. Typically, constraints will include position sizing limits.


addPosLimit(portfolio, symbol, timestamp, maxpos, longlevels = 1,
  minpos = -maxpos, shortlevels = longlevels)



text name of the portfolio to place orders in


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


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


numeric maximum long position for symbol


numeric number of levels


numeric minimum position, default -minpos (short allowed use negative number)


numeric number of short levels, default longlevels


addPosLimit works with osMaxPos to set and enforce position sizing limits. If levels=1, then all order sizing will be in the complete control of the strategy rules, up to the maximum position specified using addPosLimit's maxpos and minpos arguments.

Simply setting a position limit will not do anything. The strategy entry rules also need to specify an the use of order sizing function osMaxPos, most typically as an argument to ruleSignal.

levels are a simplification of more complex (proprietary) techniques sometimes used for order sizing. the max orderqty returned will be the limit/levels. Obviously the strategy rules could ask for smaller order sizes, but this is the default. If you don't want to use levels, set them to 1.

It is also important to note that position limits may be time-varying. If you only want one static maximum position limit, then call addPosLimit with a timestamp argument before your first trade. If you want time varying limits, typically in response to some rebalancing rule or risk rule, set the timestamp at the time which you wish the limit to take effect.

See Also

osMaxPos getPosLimit

quantstrat documentation built on May 31, 2017, 2:35 a.m.