braverock / blotter

blotter provides transaction infrastructure for defining transactions, portfolios and accounts for trading systems and simulation. Provides portfolio support for multi-asset class and multi-currency portfolios. Actively maintained and developed.
114 stars 50 forks source link

perTradeStats incorrect summary data for flat.to.reduced and increased.to.reduced #46

Closed braverock closed 7 years ago

braverock commented 7 years ago

perTradeStats correctly segments the start, end, and quantity of round turn trades using three mechanisms: flat.to.flat, flat.to.reduced, and increased.to.reduced (also available as acfifo).

There are problems with some of the statistics for flat.to.reduced, and increased.to.reduced.

Net.Trading.PL

Net.Trading.PL is calculated using trade[,"Pos.Value"]-Pos.Cost.Basis

from the PosPL slot of the portfolio for the time of the end of the round turn trade.

I believe this is correct for flat.to.flat, but incorrect for the other round turn trade segmentation mechanisms.

The correct method for flat.to.reduced, and increased.to.reduced should use the Period.Realized.PL column.

In the simplest case, Period.Realized.PL will be for a single transaction, and that transaction size will match the transaction size of the round turn trade. In this case, the entire Period.Realized.PL may be applied to the round turn trade.

If the quantity of the round turn trade is smaller than the quantity of the closing transaction, then Period.Realized.PL will need to be pro-rated to reflect the round turn trade quantity.

It should be noted that Period.Realized.PL could be used for flat.to.flat as well, but it would then need to be the cumsum of all Period.Realized.PL's during the course of the flat.to.flat round turn. It may make sense to use Period.Realized.PL for all methods, just for consistency.

MAE and MFE

MAE and MFE are currently specified as the min or max of:

Pos.PL <- trade[,"Pos.Value"]-Pos.Cost.Basis

during the duration of the round turn trade. These (and their percent and tick equivalents) need to be pro-rated for position.