mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-14 04:03:55 +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
|
# sort by profit and reset index
|
||||||
df = df.sort_values("profit").reset_index(drop=True)
|
df = df.sort_values("profit").reset_index(drop=True)
|
||||||
df1 = df.copy()
|
df1 = df.copy()
|
||||||
drawdown, hdate, ldate, hval, lval, drawdown_rel = calculate_max_drawdown(
|
drawdown = calc_max_drawdown(df, date_col="open_date", value_col="profit")
|
||||||
df, date_col="open_date", value_col="profit"
|
|
||||||
)
|
|
||||||
# Ensure df has not been altered.
|
# Ensure df has not been altered.
|
||||||
assert df.equals(df1)
|
assert df.equals(df1)
|
||||||
|
|
||||||
assert isinstance(drawdown, float)
|
assert isinstance(drawdown.drawdown_abs, float)
|
||||||
assert isinstance(drawdown_rel, float)
|
assert isinstance(drawdown.relative_account_drawdown, float)
|
||||||
# High must be before low
|
# High must be before low
|
||||||
assert hdate < ldate
|
assert drawdown.high_date < drawdown.low_date
|
||||||
# High value must be higher than low value
|
# High value must be higher than low value
|
||||||
assert hval > lval
|
assert drawdown.high_value > drawdown.low_value
|
||||||
assert drawdown == 0.091755
|
assert drawdown.drawdown_abs == 0.091755
|
||||||
|
|
||||||
df = DataFrame(zip(values[:5], dates[:5]), columns=["profit", "open_date"])
|
df = DataFrame(zip(values[:5], dates[:5]), columns=["profit", "open_date"])
|
||||||
with pytest.raises(ValueError, match="No losing trade, therefore no drawdown."):
|
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 = DataFrame(zip(values[:5], dates[:5]), columns=["profit", "open_date"])
|
||||||
df1.loc[:, "profit"] = df1["profit"] * -1
|
df1.loc[:, "profit"] = df1["profit"] * -1
|
||||||
# No winning trade ...
|
# No winning trade ...
|
||||||
drawdown, hdate, ldate, hval, lval, drawdown_rel = calculate_max_drawdown(
|
drawdown = calc_max_drawdown(df1, date_col="open_date", value_col="profit")
|
||||||
df1, date_col="open_date", value_col="profit"
|
assert drawdown.drawdown_abs == 0.043965
|
||||||
)
|
|
||||||
assert drawdown == 0.043965
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@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
|
# sort by profit and reset index
|
||||||
df = df.sort_values("profit_abs").reset_index(drop=True)
|
df = df.sort_values("profit_abs").reset_index(drop=True)
|
||||||
df1 = df.copy()
|
df1 = df.copy()
|
||||||
drawdown, hdate, ldate, hval, lval, drawdown_rel = calculate_max_drawdown(
|
drawdown = calc_max_drawdown(df, date_col="open_date", starting_balance=1000, relative=relative)
|
||||||
df, date_col="open_date", starting_balance=1000, relative=relative
|
|
||||||
)
|
|
||||||
# Ensure df has not been altered.
|
# Ensure df has not been altered.
|
||||||
assert df.equals(df1)
|
assert df.equals(df1)
|
||||||
|
|
||||||
assert isinstance(drawdown, float)
|
assert isinstance(drawdown.drawdown_abs, float)
|
||||||
assert isinstance(drawdown_rel, float)
|
assert isinstance(drawdown.relative_account_drawdown, float)
|
||||||
assert hdate == init_date + timedelta(days=highd)
|
assert drawdown.high_date == init_date + timedelta(days=highd)
|
||||||
assert ldate == init_date + timedelta(days=lowdays)
|
assert drawdown.low_date == init_date + timedelta(days=lowdays)
|
||||||
|
|
||||||
# High must be before low
|
# High must be before low
|
||||||
assert hdate < ldate
|
assert drawdown.high_date < drawdown.low_date
|
||||||
# High value must be higher than low value
|
# High value must be higher than low value
|
||||||
assert hval > lval
|
assert drawdown.high_value > drawdown.low_value
|
||||||
assert drawdown == result
|
assert drawdown.drawdown_abs == result
|
||||||
assert pytest.approx(drawdown_rel) == result_rel
|
assert pytest.approx(drawdown.relative_account_drawdown) == result_rel
|
||||||
|
|
Loading…
Reference in New Issue
Block a user