rulePctEquity: rule to base trade size on a percentage of available equity.

Description Usage Arguments Details See Also Examples

Description

This rule works with applyStrategy.rebalancing to set the maximum trade size by calling addPosLimit.

Usage

1
2
3
rulePctEquity(trade.percent = 0.02, ..., longlevels = 1,
  shortlevels = 1, digits = NULL, refprice = NULL, portfolio,
  account = NULL, symbol, timestamp)

Arguments

trade.percent

max percentage of equity to allow the strategy to trade in this symbol

...

any other passthrough parameters

longlevels

numeric number of levels

shortlevels

numeric number of short levels, default longlevels

digits

if not NULL(the default), will call round with specified number of digits

refprice

if not NULL(the default), will divide the calculated trade size by the reference price

portfolio

text name of the portfolio to place orders in, typically set automatically

account

text name of the account to fetch initial equity from, defaults to initEq in the search path

symbol

identifier of the instrument to cancel orders for, typically set automatically

timestamp

timestamp coercible to POSIXct that will be the time the order will be inserted on, typically set automatically

Details

To use it, you need to specify it as (part of) a rule of type 'rebalance'. note that applyStrategy.rebalancing will expect a 'rebalance_on' argument to be included in the arguments=list(...) of the rule definition.

See Also

osMaxPos , applyStrategy.rebalancing, addPosLimit, add.rule

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# example rule definition
## Not run: 
add.rule(strategy.name, 'rulePctEquity',
        arguments=list(rebalance_on='months',
                       trade.percent=.02,
                       refprice=quote(last(getPrice(mktdata)[paste('::',curIndex,sep='')])[,1]),
                       digits=0
        ),
        type='rebalance',
        label='rebalance')

## End(Not run)

braverock/quantstrat documentation built on Nov. 7, 2019, 1:19 p.m.