mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Adapt tests for new column names
This commit is contained in:
parent
b068e7c564
commit
2881718733
|
@ -47,7 +47,7 @@ def test_load_trades_from_db(default_conf, fee, mocker):
|
||||||
assert len(trades) == 3
|
assert len(trades) == 3
|
||||||
assert isinstance(trades, DataFrame)
|
assert isinstance(trades, DataFrame)
|
||||||
assert "pair" in trades.columns
|
assert "pair" in trades.columns
|
||||||
assert "open_time" in trades.columns
|
assert "open_date" in trades.columns
|
||||||
assert "profit_percent" in trades.columns
|
assert "profit_percent" in trades.columns
|
||||||
|
|
||||||
for col in BT_DATA_COLUMNS:
|
for col in BT_DATA_COLUMNS:
|
||||||
|
@ -67,13 +67,13 @@ def test_extract_trades_of_period(testdatadir):
|
||||||
{'pair': [pair, pair, pair, pair],
|
{'pair': [pair, pair, pair, pair],
|
||||||
'profit_percent': [0.0, 0.1, -0.2, -0.5],
|
'profit_percent': [0.0, 0.1, -0.2, -0.5],
|
||||||
'profit_abs': [0.0, 1, -2, -5],
|
'profit_abs': [0.0, 1, -2, -5],
|
||||||
'open_time': to_datetime([Arrow(2017, 11, 13, 15, 40, 0).datetime,
|
'open_date': to_datetime([Arrow(2017, 11, 13, 15, 40, 0).datetime,
|
||||||
Arrow(2017, 11, 14, 9, 41, 0).datetime,
|
Arrow(2017, 11, 14, 9, 41, 0).datetime,
|
||||||
Arrow(2017, 11, 14, 14, 20, 0).datetime,
|
Arrow(2017, 11, 14, 14, 20, 0).datetime,
|
||||||
Arrow(2017, 11, 15, 3, 40, 0).datetime,
|
Arrow(2017, 11, 15, 3, 40, 0).datetime,
|
||||||
], utc=True
|
], utc=True
|
||||||
),
|
),
|
||||||
'close_time': to_datetime([Arrow(2017, 11, 13, 16, 40, 0).datetime,
|
'close_date': to_datetime([Arrow(2017, 11, 13, 16, 40, 0).datetime,
|
||||||
Arrow(2017, 11, 14, 10, 41, 0).datetime,
|
Arrow(2017, 11, 14, 10, 41, 0).datetime,
|
||||||
Arrow(2017, 11, 14, 15, 25, 0).datetime,
|
Arrow(2017, 11, 14, 15, 25, 0).datetime,
|
||||||
Arrow(2017, 11, 15, 3, 55, 0).datetime,
|
Arrow(2017, 11, 15, 3, 55, 0).datetime,
|
||||||
|
@ -82,10 +82,10 @@ def test_extract_trades_of_period(testdatadir):
|
||||||
trades1 = extract_trades_of_period(data, trades)
|
trades1 = extract_trades_of_period(data, trades)
|
||||||
# First and last trade are dropped as they are out of range
|
# First and last trade are dropped as they are out of range
|
||||||
assert len(trades1) == 2
|
assert len(trades1) == 2
|
||||||
assert trades1.iloc[0].open_time == Arrow(2017, 11, 14, 9, 41, 0).datetime
|
assert trades1.iloc[0].open_date == Arrow(2017, 11, 14, 9, 41, 0).datetime
|
||||||
assert trades1.iloc[0].close_time == Arrow(2017, 11, 14, 10, 41, 0).datetime
|
assert trades1.iloc[0].close_date == Arrow(2017, 11, 14, 10, 41, 0).datetime
|
||||||
assert trades1.iloc[-1].open_time == Arrow(2017, 11, 14, 14, 20, 0).datetime
|
assert trades1.iloc[-1].open_date == Arrow(2017, 11, 14, 14, 20, 0).datetime
|
||||||
assert trades1.iloc[-1].close_time == Arrow(2017, 11, 14, 15, 25, 0).datetime
|
assert trades1.iloc[-1].close_date == Arrow(2017, 11, 14, 15, 25, 0).datetime
|
||||||
|
|
||||||
|
|
||||||
def test_analyze_trade_parallelism(default_conf, mocker, testdatadir):
|
def test_analyze_trade_parallelism(default_conf, mocker, testdatadir):
|
||||||
|
@ -174,7 +174,7 @@ def test_create_cum_profit1(testdatadir):
|
||||||
filename = testdatadir / "backtest-result_test.json"
|
filename = testdatadir / "backtest-result_test.json"
|
||||||
bt_data = load_backtest_data(filename)
|
bt_data = load_backtest_data(filename)
|
||||||
# Move close-time to "off" the candle, to make sure the logic still works
|
# Move close-time to "off" the candle, to make sure the logic still works
|
||||||
bt_data.loc[:, 'close_time'] = bt_data.loc[:, 'close_time'] + DateOffset(seconds=20)
|
bt_data.loc[:, 'close_date'] = bt_data.loc[:, 'close_date'] + DateOffset(seconds=20)
|
||||||
timerange = TimeRange.parse_timerange("20180110-20180112")
|
timerange = TimeRange.parse_timerange("20180110-20180112")
|
||||||
|
|
||||||
df = load_pair_history(pair="TRX/BTC", timeframe='5m',
|
df = load_pair_history(pair="TRX/BTC", timeframe='5m',
|
||||||
|
@ -213,11 +213,11 @@ def test_calculate_max_drawdown2():
|
||||||
-0.033961, 0.010680, 0.010886, -0.029274, 0.011178, 0.010693, 0.010711]
|
-0.033961, 0.010680, 0.010886, -0.029274, 0.011178, 0.010693, 0.010711]
|
||||||
|
|
||||||
dates = [Arrow(2020, 1, 1).shift(days=i) for i in range(len(values))]
|
dates = [Arrow(2020, 1, 1).shift(days=i) for i in range(len(values))]
|
||||||
df = DataFrame(zip(values, dates), columns=['profit', 'open_time'])
|
df = DataFrame(zip(values, dates), columns=['profit', 'open_date'])
|
||||||
# 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, h, low = calculate_max_drawdown(df, date_col='open_time', value_col='profit')
|
drawdown, h, low = calculate_max_drawdown(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)
|
||||||
|
|
||||||
|
@ -226,6 +226,6 @@ def test_calculate_max_drawdown2():
|
||||||
assert h < low
|
assert h < low
|
||||||
assert drawdown == 0.091755
|
assert drawdown == 0.091755
|
||||||
|
|
||||||
df = DataFrame(zip(values[:5], dates[:5]), columns=['profit', 'open_time'])
|
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_time', value_col='profit')
|
calculate_max_drawdown(df, date_col='open_date', value_col='profit')
|
||||||
|
|
|
@ -163,8 +163,8 @@ def test_edge_results(edge_conf, mocker, caplog, data) -> None:
|
||||||
for c, trade in enumerate(data.trades):
|
for c, trade in enumerate(data.trades):
|
||||||
res = results.iloc[c]
|
res = results.iloc[c]
|
||||||
assert res.exit_type == trade.sell_reason
|
assert res.exit_type == trade.sell_reason
|
||||||
assert res.open_time == _get_frame_time_from_offset(trade.open_tick).replace(tzinfo=None)
|
assert res.open_date == _get_frame_time_from_offset(trade.open_tick).replace(tzinfo=None)
|
||||||
assert res.close_time == _get_frame_time_from_offset(trade.close_tick).replace(tzinfo=None)
|
assert res.close_date == _get_frame_time_from_offset(trade.close_tick).replace(tzinfo=None)
|
||||||
|
|
||||||
|
|
||||||
def test_adjust(mocker, edge_conf):
|
def test_adjust(mocker, edge_conf):
|
||||||
|
@ -354,8 +354,8 @@ def test_process_expectancy(mocker, edge_conf, fee, risk_reward_ratio, expectanc
|
||||||
'stoploss': -0.9,
|
'stoploss': -0.9,
|
||||||
'profit_percent': '',
|
'profit_percent': '',
|
||||||
'profit_abs': '',
|
'profit_abs': '',
|
||||||
'open_time': np.datetime64('2018-10-03T00:05:00.000000000'),
|
'open_date': np.datetime64('2018-10-03T00:05:00.000000000'),
|
||||||
'close_time': np.datetime64('2018-10-03T00:10:00.000000000'),
|
'close_date': np.datetime64('2018-10-03T00:10:00.000000000'),
|
||||||
'open_index': 1,
|
'open_index': 1,
|
||||||
'close_index': 1,
|
'close_index': 1,
|
||||||
'trade_duration': '',
|
'trade_duration': '',
|
||||||
|
@ -367,8 +367,8 @@ def test_process_expectancy(mocker, edge_conf, fee, risk_reward_ratio, expectanc
|
||||||
'stoploss': -0.9,
|
'stoploss': -0.9,
|
||||||
'profit_percent': '',
|
'profit_percent': '',
|
||||||
'profit_abs': '',
|
'profit_abs': '',
|
||||||
'open_time': np.datetime64('2018-10-03T00:20:00.000000000'),
|
'open_date': np.datetime64('2018-10-03T00:20:00.000000000'),
|
||||||
'close_time': np.datetime64('2018-10-03T00:25:00.000000000'),
|
'close_date': np.datetime64('2018-10-03T00:25:00.000000000'),
|
||||||
'open_index': 4,
|
'open_index': 4,
|
||||||
'close_index': 4,
|
'close_index': 4,
|
||||||
'trade_duration': '',
|
'trade_duration': '',
|
||||||
|
@ -380,8 +380,8 @@ def test_process_expectancy(mocker, edge_conf, fee, risk_reward_ratio, expectanc
|
||||||
'stoploss': -0.9,
|
'stoploss': -0.9,
|
||||||
'profit_percent': '',
|
'profit_percent': '',
|
||||||
'profit_abs': '',
|
'profit_abs': '',
|
||||||
'open_time': np.datetime64('2018-10-03T00:30:00.000000000'),
|
'open_date': np.datetime64('2018-10-03T00:30:00.000000000'),
|
||||||
'close_time': np.datetime64('2018-10-03T00:40:00.000000000'),
|
'close_date': np.datetime64('2018-10-03T00:40:00.000000000'),
|
||||||
'open_index': 6,
|
'open_index': 6,
|
||||||
'close_index': 7,
|
'close_index': 7,
|
||||||
'trade_duration': '',
|
'trade_duration': '',
|
||||||
|
|
|
@ -395,5 +395,5 @@ def test_backtest_results(default_conf, fee, mocker, caplog, data) -> None:
|
||||||
for c, trade in enumerate(data.trades):
|
for c, trade in enumerate(data.trades):
|
||||||
res = results.iloc[c]
|
res = results.iloc[c]
|
||||||
assert res.sell_reason == trade.sell_reason
|
assert res.sell_reason == trade.sell_reason
|
||||||
assert res.open_time == _get_frame_time_from_offset(trade.open_tick)
|
assert res.open_date == _get_frame_time_from_offset(trade.open_tick)
|
||||||
assert res.close_time == _get_frame_time_from_offset(trade.close_tick)
|
assert res.close_date == _get_frame_time_from_offset(trade.close_tick)
|
||||||
|
|
|
@ -459,10 +459,10 @@ def test_backtest(default_conf, fee, mocker, testdatadir) -> None:
|
||||||
{'pair': [pair, pair],
|
{'pair': [pair, pair],
|
||||||
'profit_percent': [0.0, 0.0],
|
'profit_percent': [0.0, 0.0],
|
||||||
'profit_abs': [0.0, 0.0],
|
'profit_abs': [0.0, 0.0],
|
||||||
'open_time': pd.to_datetime([Arrow(2018, 1, 29, 18, 40, 0).datetime,
|
'open_date': pd.to_datetime([Arrow(2018, 1, 29, 18, 40, 0).datetime,
|
||||||
Arrow(2018, 1, 30, 3, 30, 0).datetime], utc=True
|
Arrow(2018, 1, 30, 3, 30, 0).datetime], utc=True
|
||||||
),
|
),
|
||||||
'close_time': pd.to_datetime([Arrow(2018, 1, 29, 22, 35, 0).datetime,
|
'close_date': pd.to_datetime([Arrow(2018, 1, 29, 22, 35, 0).datetime,
|
||||||
Arrow(2018, 1, 30, 4, 10, 0).datetime], utc=True),
|
Arrow(2018, 1, 30, 4, 10, 0).datetime], utc=True),
|
||||||
'open_index': [78, 184],
|
'open_index': [78, 184],
|
||||||
'close_index': [125, 192],
|
'close_index': [125, 192],
|
||||||
|
@ -475,12 +475,12 @@ def test_backtest(default_conf, fee, mocker, testdatadir) -> None:
|
||||||
pd.testing.assert_frame_equal(results, expected)
|
pd.testing.assert_frame_equal(results, expected)
|
||||||
data_pair = processed[pair]
|
data_pair = processed[pair]
|
||||||
for _, t in results.iterrows():
|
for _, t in results.iterrows():
|
||||||
ln = data_pair.loc[data_pair["date"] == t["open_time"]]
|
ln = data_pair.loc[data_pair["date"] == t["open_date"]]
|
||||||
# Check open trade rate alignes to open rate
|
# Check open trade rate alignes to open rate
|
||||||
assert ln is not None
|
assert ln is not None
|
||||||
assert round(ln.iloc[0]["open"], 6) == round(t["open_rate"], 6)
|
assert round(ln.iloc[0]["open"], 6) == round(t["open_rate"], 6)
|
||||||
# check close trade rate alignes to close rate or is between high and low
|
# check close trade rate alignes to close rate or is between high and low
|
||||||
ln = data_pair.loc[data_pair["date"] == t["close_time"]]
|
ln = data_pair.loc[data_pair["date"] == t["close_date"]]
|
||||||
assert (round(ln.iloc[0]["open"], 6) == round(t["close_rate"], 6) or
|
assert (round(ln.iloc[0]["open"], 6) == round(t["close_rate"], 6) or
|
||||||
round(ln.iloc[0]["low"], 6) < round(
|
round(ln.iloc[0]["low"], 6) < round(
|
||||||
t["close_rate"], 6) < round(ln.iloc[0]["high"], 6))
|
t["close_rate"], 6) < round(ln.iloc[0]["high"], 6))
|
||||||
|
@ -756,10 +756,10 @@ def test_backtest_start_multi_strat_nomock(default_conf, mocker, caplog, testdat
|
||||||
pd.DataFrame({'pair': ['XRP/BTC', 'LTC/BTC'],
|
pd.DataFrame({'pair': ['XRP/BTC', 'LTC/BTC'],
|
||||||
'profit_percent': [0.0, 0.0],
|
'profit_percent': [0.0, 0.0],
|
||||||
'profit_abs': [0.0, 0.0],
|
'profit_abs': [0.0, 0.0],
|
||||||
'open_time': pd.to_datetime(['2018-01-29 18:40:00',
|
'open_date': pd.to_datetime(['2018-01-29 18:40:00',
|
||||||
'2018-01-30 03:30:00', ], utc=True
|
'2018-01-30 03:30:00', ], utc=True
|
||||||
),
|
),
|
||||||
'close_time': pd.to_datetime(['2018-01-29 20:45:00',
|
'close_date': pd.to_datetime(['2018-01-29 20:45:00',
|
||||||
'2018-01-30 05:35:00', ], utc=True),
|
'2018-01-30 05:35:00', ], utc=True),
|
||||||
'open_index': [78, 184],
|
'open_index': [78, 184],
|
||||||
'close_index': [125, 192],
|
'close_index': [125, 192],
|
||||||
|
@ -772,11 +772,11 @@ def test_backtest_start_multi_strat_nomock(default_conf, mocker, caplog, testdat
|
||||||
pd.DataFrame({'pair': ['XRP/BTC', 'LTC/BTC', 'ETH/BTC'],
|
pd.DataFrame({'pair': ['XRP/BTC', 'LTC/BTC', 'ETH/BTC'],
|
||||||
'profit_percent': [0.03, 0.01, 0.1],
|
'profit_percent': [0.03, 0.01, 0.1],
|
||||||
'profit_abs': [0.01, 0.02, 0.2],
|
'profit_abs': [0.01, 0.02, 0.2],
|
||||||
'open_time': pd.to_datetime(['2018-01-29 18:40:00',
|
'open_date': pd.to_datetime(['2018-01-29 18:40:00',
|
||||||
'2018-01-30 03:30:00',
|
'2018-01-30 03:30:00',
|
||||||
'2018-01-30 05:30:00'], utc=True
|
'2018-01-30 05:30:00'], utc=True
|
||||||
),
|
),
|
||||||
'close_time': pd.to_datetime(['2018-01-29 20:45:00',
|
'close_date': pd.to_datetime(['2018-01-29 20:45:00',
|
||||||
'2018-01-30 05:35:00',
|
'2018-01-30 05:35:00',
|
||||||
'2018-01-30 08:30:00'], utc=True),
|
'2018-01-30 08:30:00'], utc=True),
|
||||||
'open_index': [78, 184, 185],
|
'open_index': [78, 184, 185],
|
||||||
|
|
|
@ -46,7 +46,7 @@ def hyperopt_results():
|
||||||
'profit_abs': [-0.2, 0.4, 0.6],
|
'profit_abs': [-0.2, 0.4, 0.6],
|
||||||
'trade_duration': [10, 30, 10],
|
'trade_duration': [10, 30, 10],
|
||||||
'sell_reason': [SellType.STOP_LOSS, SellType.ROI, SellType.ROI],
|
'sell_reason': [SellType.STOP_LOSS, SellType.ROI, SellType.ROI],
|
||||||
'close_time':
|
'close_date':
|
||||||
[
|
[
|
||||||
datetime(2019, 1, 1, 9, 26, 3, 478039),
|
datetime(2019, 1, 1, 9, 26, 3, 478039),
|
||||||
datetime(2019, 2, 1, 9, 26, 3, 478039),
|
datetime(2019, 2, 1, 9, 26, 3, 478039),
|
||||||
|
|
|
@ -204,11 +204,11 @@ def test_backtest_record(default_conf, fee, mocker):
|
||||||
"UNITTEST/BTC", "UNITTEST/BTC"],
|
"UNITTEST/BTC", "UNITTEST/BTC"],
|
||||||
"profit_percent": [0.003312, 0.010801, 0.013803, 0.002780],
|
"profit_percent": [0.003312, 0.010801, 0.013803, 0.002780],
|
||||||
"profit_abs": [0.000003, 0.000011, 0.000014, 0.000003],
|
"profit_abs": [0.000003, 0.000011, 0.000014, 0.000003],
|
||||||
"open_time": [Arrow(2017, 11, 14, 19, 32, 00).datetime,
|
"open_date": [Arrow(2017, 11, 14, 19, 32, 00).datetime,
|
||||||
Arrow(2017, 11, 14, 21, 36, 00).datetime,
|
Arrow(2017, 11, 14, 21, 36, 00).datetime,
|
||||||
Arrow(2017, 11, 14, 22, 12, 00).datetime,
|
Arrow(2017, 11, 14, 22, 12, 00).datetime,
|
||||||
Arrow(2017, 11, 14, 22, 44, 00).datetime],
|
Arrow(2017, 11, 14, 22, 44, 00).datetime],
|
||||||
"close_time": [Arrow(2017, 11, 14, 21, 35, 00).datetime,
|
"close_date": [Arrow(2017, 11, 14, 21, 35, 00).datetime,
|
||||||
Arrow(2017, 11, 14, 22, 10, 00).datetime,
|
Arrow(2017, 11, 14, 22, 10, 00).datetime,
|
||||||
Arrow(2017, 11, 14, 22, 43, 00).datetime,
|
Arrow(2017, 11, 14, 22, 43, 00).datetime,
|
||||||
Arrow(2017, 11, 14, 22, 58, 00).datetime],
|
Arrow(2017, 11, 14, 22, 58, 00).datetime],
|
||||||
|
|
|
@ -267,7 +267,7 @@ def test_generate_profit_graph(testdatadir):
|
||||||
trades = load_backtest_data(filename)
|
trades = load_backtest_data(filename)
|
||||||
timerange = TimeRange.parse_timerange("20180110-20180112")
|
timerange = TimeRange.parse_timerange("20180110-20180112")
|
||||||
pairs = ["TRX/BTC", "XLM/BTC"]
|
pairs = ["TRX/BTC", "XLM/BTC"]
|
||||||
trades = trades[trades['close_time'] < pd.Timestamp('2018-01-12', tz='UTC')]
|
trades = trades[trades['close_date'] < pd.Timestamp('2018-01-12', tz='UTC')]
|
||||||
|
|
||||||
data = history.load_data(datadir=testdatadir,
|
data = history.load_data(datadir=testdatadir,
|
||||||
pairs=pairs,
|
pairs=pairs,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user