addPosLimit: add position and level limits at timestamp

Description Usage Arguments Details See Also

Description

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

Usage

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

Arguments

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

timestamp

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

maxpos

numeric maximum long position for symbol

longlevels

numeric number of levels

minpos

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

shortlevels

numeric number of short levels, default longlevels

Details

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


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