mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 02:12:01 +00:00
Update remaining tests
This commit is contained in:
parent
a6050cb771
commit
c79b75ff9a
|
@ -508,31 +508,27 @@ def test_calculate_max_drawdown2():
|
|||
# sort by profit and reset index
|
||||
df = df.sort_values("profit").reset_index(drop=True)
|
||||
df1 = df.copy()
|
||||
drawdown, hdate, ldate, hval, lval, drawdown_rel = calculate_max_drawdown(
|
||||
df, date_col="open_date", value_col="profit"
|
||||
)
|
||||
drawdown = calc_max_drawdown(df, date_col="open_date", value_col="profit")
|
||||
# Ensure df has not been altered.
|
||||
assert df.equals(df1)
|
||||
|
||||
assert isinstance(drawdown, float)
|
||||
assert isinstance(drawdown_rel, float)
|
||||
assert isinstance(drawdown.drawdown_abs, float)
|
||||
assert isinstance(drawdown.relative_account_drawdown, float)
|
||||
# High must be before low
|
||||
assert hdate < ldate
|
||||
assert drawdown.high_date < drawdown.low_date
|
||||
# High value must be higher than low value
|
||||
assert hval > lval
|
||||
assert drawdown == 0.091755
|
||||
assert drawdown.high_value > drawdown.low_value
|
||||
assert drawdown.drawdown_abs == 0.091755
|
||||
|
||||
df = DataFrame(zip(values[:5], dates[:5]), columns=["profit", "open_date"])
|
||||
with pytest.raises(ValueError, match="No losing trade, therefore no drawdown."):
|
||||
calculate_max_drawdown(df, date_col="open_date", value_col="profit")
|
||||
calc_max_drawdown(df, date_col="open_date", value_col="profit")
|
||||
|
||||
df1 = DataFrame(zip(values[:5], dates[:5]), columns=["profit", "open_date"])
|
||||
df1.loc[:, "profit"] = df1["profit"] * -1
|
||||
# No winning trade ...
|
||||
drawdown, hdate, ldate, hval, lval, drawdown_rel = calculate_max_drawdown(
|
||||
df1, date_col="open_date", value_col="profit"
|
||||
)
|
||||
assert drawdown == 0.043965
|
||||
drawdown = calc_max_drawdown(df1, date_col="open_date", value_col="profit")
|
||||
assert drawdown.drawdown_abs == 0.043965
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -554,20 +550,18 @@ def test_calculate_max_drawdown_abs(profits, relative, highd, lowdays, result, r
|
|||
# sort by profit and reset index
|
||||
df = df.sort_values("profit_abs").reset_index(drop=True)
|
||||
df1 = df.copy()
|
||||
drawdown, hdate, ldate, hval, lval, drawdown_rel = calculate_max_drawdown(
|
||||
df, date_col="open_date", starting_balance=1000, relative=relative
|
||||
)
|
||||
drawdown = calc_max_drawdown(df, date_col="open_date", starting_balance=1000, relative=relative)
|
||||
# Ensure df has not been altered.
|
||||
assert df.equals(df1)
|
||||
|
||||
assert isinstance(drawdown, float)
|
||||
assert isinstance(drawdown_rel, float)
|
||||
assert hdate == init_date + timedelta(days=highd)
|
||||
assert ldate == init_date + timedelta(days=lowdays)
|
||||
assert isinstance(drawdown.drawdown_abs, float)
|
||||
assert isinstance(drawdown.relative_account_drawdown, float)
|
||||
assert drawdown.high_date == init_date + timedelta(days=highd)
|
||||
assert drawdown.low_date == init_date + timedelta(days=lowdays)
|
||||
|
||||
# High must be before low
|
||||
assert hdate < ldate
|
||||
assert drawdown.high_date < drawdown.low_date
|
||||
# High value must be higher than low value
|
||||
assert hval > lval
|
||||
assert drawdown == result
|
||||
assert pytest.approx(drawdown_rel) == result_rel
|
||||
assert drawdown.high_value > drawdown.low_value
|
||||
assert drawdown.drawdown_abs == result
|
||||
assert pytest.approx(drawdown.relative_account_drawdown) == result_rel
|
||||
|
|
Loading…
Reference in New Issue
Block a user