Skip to content

quantstrat- adding transaction fee to rule

5 messages · Andre Barroso, Brian G. Peterson

#
On Sat, 11 Sep 2010 23:44:09 +0200, Andre Barroso
<andre.barroso at gmail.com>
wrote:
I'm not at a machine that has quantstrat installed right this moment to
test it, but I believe that you should be able to put TxnFees into the
arguments=list(...) for ruleSignal.  if that doesn't work, try adding it as


parameters=list(TxnFees=-5)

The relevant code files, I think, are traderules.R and orders.R  The
function ruleOrderProc (and its documentation) might say more about the
precise method of calling addTxn.  

I suppose it's possible we're not passing dots correctly somewhere, but I
hope one of my suggestions works. Let us know if/which one works.  

Otherwise, I'll test tomorrow or Monday.

Regards,

   - Brian
#
Andre,

I was able to replicate the problem.  While it was true that we were not
passing dots properly in all places (this is now fixed), the problem turned
out to be a little more complicated than that because the order book is
stored as a character xts time series, so the TxnFees also needed to be
converted to numeric.

You may now specify TxnFees a a parameter in the arguments=list() for
ruleSignal.  In the Faber demo, to set TxnFees to -5 as you requested, this
looks like:

####

# There are two rules:
# The first is to buy when the price crosses above the SMA
stratFaber <- add.rule(stratFaber, name='ruleSignal', arguments =
list(sigcol="Cl.gt.SMA", sigval=TRUE, orderqty=1000, ordertype='market',
orderside='long', pricemethod='market',TxnFees=-5), type='enter',
path.dep=TRUE)
# The second is to sell when the price crosses below the SMA
stratFaber <- add.rule(stratFaber, name='ruleSignal', arguments =
list(sigcol="Cl.lt.SMA", sigval=TRUE, orderqty='all', ordertype='market',
orderside='long', pricemethod='market',TxnFees=-5), type='exit',
path.dep=TRUE)

####

Thanks for reporting the bug.  It is fixed in SVN r393 (quantstrat) and
r394 (blotter).  It is available either from SVN now, or should be
available as binaries on R-Forge tomorrow.

Thanks for the detailed report, it made replicating the bug much easier.

Regards,

    - Brian

On Sun, 12 Sep 2010 12:22:36 +0200, Andre Barroso
<andre.barroso at gmail.com>
wrote:
orderqty=1000,ordertype='market',
orderqty=1000,ordertype='market',
it
I