We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cd4bc6c commit e1a86efCopy full SHA for e1a86ef
backtesting/backtesting.py
@@ -368,10 +368,8 @@ def pl(self) -> float:
368
@property
369
def pl_pct(self) -> float:
370
"""Profit (positive) or loss (negative) of the current position in percent."""
371
- weights = np.abs([trade.size for trade in self.__broker.trades])
372
- weights = weights / weights.sum()
373
- pl_pcts = np.array([trade.pl_pct for trade in self.__broker.trades])
374
- return (pl_pcts * weights).sum()
+ total_invested = sum(trade.entry_price * abs(trade.size) for trade in self.__broker.trades)
+ return (self.pl / total_invested) * 100 if total_invested else 0
375
376
377
def is_long(self) -> bool:
0 commit comments