Skip to content

Commit cecb18e

Browse files
Account for Commissions in Trade.pl_pct.
1 parent c163803 commit cecb18e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

backtesting/backtesting.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,11 @@ def pl(self):
682682
def pl_pct(self):
683683
"""Trade profit (positive) or loss (negative) in percent."""
684684
price = self.__exit_price or self.__broker.last_price
685-
return copysign(1, self.__size) * (price / self.__entry_price - 1)
685+
gross_pl_pct = copysign(1, self.__size) * (price / self.__entry_price - 1)
686+
687+
# Total commission across the entire trade size to individual units
688+
commission_pct = self._commissions / (abs(self.__size) * self.__entry_price)
689+
return gross_pl_pct - commission_pct
686690

687691
@property
688692
def value(self):

0 commit comments

Comments
 (0)