mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
add test for expectancy
This commit is contained in:
parent
8621dc96e7
commit
cfd8b068e7
|
@ -209,8 +209,8 @@ def calculate_expectancy(trades: pd.DataFrame) -> float:
|
|||
|
||||
average_win = (profit_sum / nb_win_trades) if nb_win_trades > 0 else 0
|
||||
average_loss = (loss_sum / nb_loss_trades) if nb_loss_trades > 0 else 0
|
||||
winrate = nb_win_trades / len(trades)
|
||||
loserate = nb_loss_trades / len(trades)
|
||||
winrate = (nb_win_trades / len(trades)) if len(trades) > 0 else 0
|
||||
loserate = (nb_loss_trades / len(trades)) if len(trades) > 0 else 0
|
||||
expectancy = (winrate * average_win) - (loserate * average_loss)
|
||||
|
||||
return expectancy
|
||||
|
|
|
@ -338,6 +338,16 @@ def test_calculate_csum(testdatadir):
|
|||
with pytest.raises(ValueError, match='Trade dataframe empty.'):
|
||||
csum_min, csum_max = calculate_csum(DataFrame())
|
||||
|
||||
def test_calculate_expectancy(testdatadir):
|
||||
filename = testdatadir / "backtest_results/backtest-result.json"
|
||||
bt_data = load_backtest_data(filename)
|
||||
|
||||
expectancy = calculate_expectancy(DataFrame())
|
||||
assert expectancy == 0.0
|
||||
|
||||
expectancy = calculate_expectancy(bt_data)
|
||||
assert isinstance(expectancy, float)
|
||||
assert pytest.approx(expectancy) == 0.07151374226574791
|
||||
|
||||
def test_calculate_expectancy_ratio(testdatadir):
|
||||
filename = testdatadir / "backtest_results/backtest-result.json"
|
||||
|
|
Loading…
Reference in New Issue
Block a user