[R-SIG-Finance] Possible tradeStats() issue

Brian G. Peterson brian at braverock.com
Tue Nov 20 22:20:47 CET 2012


On 11/20/2012 02:44 PM, Michael Newell wrote:
> There are a number of statistics in tradeStats() which use the PL.gt0,
> PL.lt0 and PL.ne0 variables and therefore produce incorrect results
> when txnFees>0.  This is easily recreated using any demo with txnFees
> present and not present and reviewing the tradeStats() results.
In the presence of transaction fees, you cannot really have a 
transaction with no P&L, can you?  (leaving aside a gain that precisely 
offsets the fees) so the count of transactions is indeed true.

There are three ways I can think of around this:
- one is to place the fees only on your flattening transactions, 
pretending that you only realize the fees when you exit the position...  
this isn't exactly true, but gets you what you seem to want.
- another would be to patch the function to allow a user-specified 
option to to use Gross rather than Net.
- or use perTradeStats instead, which uses position rather than P&L to 
separate 'trades'.  This function is newer than tradeStats, so perhaps 
the tradeStats function could be modified to use these instead of the 
simple PL>0 method.

Either of the latter two options shouldn't be a large change to the 
code, but I'm not likely to get to it any time soon. Patches Welcome.

Regards,

     - Brian



More information about the R-SIG-Finance mailing list