Skip to content

Commit a70b3f5

Browse files
authored
BUG: Update Expectancy [%] formula (#181)
* Update Expectancy [%] formula * fix failing test
1 parent 2127b26 commit a70b3f5

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

backtesting/backtesting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ def geometric_mean(returns):
14431443
s.loc['Max. Trade Duration'] = _round_timedelta(durations.max())
14441444
s.loc['Avg. Trade Duration'] = _round_timedelta(durations.mean())
14451445
s.loc['Profit Factor'] = returns[returns > 0].sum() / (abs(returns[returns < 0].sum()) or np.nan) # noqa: E501
1446-
s.loc['Expectancy [%]'] = ((returns[returns > 0].mean() * win_rate -
1446+
s.loc['Expectancy [%]'] = ((returns[returns > 0].mean() * win_rate +
14471447
returns[returns < 0].mean() * (100 - win_rate)))
14481448
s.loc['SQN'] = np.sqrt(n_trades) * pl.mean() / (pl.std() or np.nan)
14491449

backtesting/test/_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def test_compute_stats(self):
266266
'End': pd.Timestamp('2013-03-01 00:00:00'),
267267
'Equity Final [$]': 51959.94999999997,
268268
'Equity Peak [$]': 75787.44,
269-
'Expectancy [%]': 8.791710931051735,
269+
'Expectancy [%]': 3.097629974370269,
270270
'Exposure Time [%]': 93.99441340782123,
271271
'Max. Drawdown Duration': pd.Timedelta('584 days 00:00:00'),
272272
'Max. Drawdown [%]': -47.98012705007589,

0 commit comments

Comments
 (0)