[R-SIG-Finance] quantstrat- adding transaction fee to rule

Brian G. Peterson brian at braverock.com
Sun Sep 12 19:37:56 CEST 2010


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:
> Dear Brian,
> 
> Thanks for the prompt reply. Unfortunately both approaches you suggested
> were also ineffective. A peek via getPortfolio('faber') shows all
> transaction fees set to zero.
> 
> Cheers,
> 
> Andre
> 
> On Sun, Sep 12, 2010 at 12:28 AM, Brian G. Peterson
> <brian at braverock.com>wrote:
> 
>> On Sat, 11 Sep 2010 23:44:09 +0200, Andre Barroso
>> <andre.barroso at gmail.com>
>> wrote:
>> > Dear all,
>> >
>> > I  tried to change the Faber demo from quantstrat to include
>> > transaction
>> > fees but without success. The original rule is:
>> >
>> > stratFaber <- add.rule(stratFaber, name='ruleSignal',arguments =
>> > list(sigcol="Cl.gt.SMA", sigval=TRUE,
orderqty=1000,ordertype='market',
>> > orderside='long', pricemethod='market'), type='enter',path.dep=TRUE)
>> >
>> > my idea was just to include TxnFees as an argument, but this was
>> > ineffective:
>> >
>> > 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)
>> >
>> > Any ideas of how this work?
>>
>> 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

-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-SIG-Finance mailing list