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

OpenTrades jan at opentrades.nl
Tue Nov 20 22:14:27 CET 2012


Your observations are totally correct Michael.

Using txnFees != 0 is in fact a hack to be able to discern individual 
trades, but of course it only works under the conditions mentioned. In 
my strategies I usually specify 0 for entry transaction costs, then 
double the transaction costs for exits, but that will only work in 
certain strategies, true.

I am not aware of any plans to fix this at this point; patches (as 
always) welcome :-)



On 20-11-12 21:44, Michael Newell wrote:
> I have recently come across an issue using the tradeStats() function
> which was exposed by setting txnFees.  Looking at the tradeStats()
> codes it attempts to determine the number of trades based on the
> following logic:
>
> PL.gt0 <- txn$Net.Txn.Realized.PL[txn$Net.Txn.Realized.PL > 0]
> PL.lt0 <- txn$Net.Txn.Realized.PL[txn$Net.Txn.Realized.PL < 0]
> PL.ne0 <- txn$Net.Txn.Realized.PL[txn$Net.Txn.Realized.PL != 0]
> ....
> NumberOfTrades <- nrow(PL.ne0)
>
> When not using txnFees your opening transaction of a trade have a PL
> of 0 and hence this number does indeed match up with the number of
> trades.  However as soon as you set a txnFees amount it means your
> opening transaction has a PL equal to your txnFees (e.g. spread cost
> of -0.0002).  This now doubles the "NumberOfTrades" as all opening
> transactions have a PNL != 0 as shown below under PL column.
>
>                      Txn.Qty Txn.Price Txn.Fees Txn.Value Txn.Avg.Cost
> Net.Txn.Realized.PL
> 1990-01-01 00:00:00       0   0.00000    0e+00   0.00000      0.00000
>             0.00000
> 2010-01-22 13:59:00       1   1.61112   -2e-04   1.61112      1.61112
>            -0.00020
> 2010-01-25 15:59:00      -1   1.61837    0e+00  -1.61837      1.61837
>             0.00725
> 2010-01-28 09:59:00      -1   1.62732   -2e-04  -1.62732      1.62732
>            -0.00020
> 2010-01-28 16:59:00       1   1.61347    0e+00   1.61347      1.61347
>             0.01385
>
>
> 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.
>
> --
>
> Regards,
>
> Michael Newell
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
>


-- 
Jan Humme - OpenTrades

WWW:     http://www.opentrades.nl
Email:   jan at opentrades.nl
Twitter: @opentrades



More information about the R-SIG-Finance mailing list