Improve commenting on backtsting and backtest_multi_tst
This commit is contained in:
parent
0307ba7883
commit
32cbb714f9
@ -329,6 +329,8 @@ class Backtesting(object):
|
|||||||
end_date = args['end_date']
|
end_date = args['end_date']
|
||||||
trades = []
|
trades = []
|
||||||
trade_count_lock: Dict = {}
|
trade_count_lock: Dict = {}
|
||||||
|
|
||||||
|
# Dict of ticker-lists for performance (looping lists is a lot faster than dataframes)
|
||||||
ticker: Dict = self._get_ticker_list(processed)
|
ticker: Dict = self._get_ticker_list(processed)
|
||||||
|
|
||||||
lock_pair_until: Dict = {}
|
lock_pair_until: Dict = {}
|
||||||
@ -345,10 +347,11 @@ class Backtesting(object):
|
|||||||
try:
|
try:
|
||||||
row = ticker[pair][indexes[pair]]
|
row = ticker[pair][indexes[pair]]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
# missing Data for one pair ...
|
# missing Data for one pair at the end.
|
||||||
# Warnings for this are shown by `validate_backtest_data`
|
# Warnings for this are shown by `validate_backtest_data`
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Waits until the time-counter reaches the start of the data for this pair.
|
||||||
if row.date > tmp.datetime:
|
if row.date > tmp.datetime:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -359,12 +362,13 @@ class Backtesting(object):
|
|||||||
|
|
||||||
if (not position_stacking and pair in lock_pair_until
|
if (not position_stacking and pair in lock_pair_until
|
||||||
and row.date <= lock_pair_until[pair]):
|
and row.date <= lock_pair_until[pair]):
|
||||||
|
# without positionstacking, we can only have one open trade per pair.
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if max_open_trades > 0:
|
if max_open_trades > 0:
|
||||||
# Check if max_open_trades has already been reached for the given date
|
# Check if max_open_trades has already been reached for the given date
|
||||||
if not trade_count_lock.get(row.date, 0) < max_open_trades:
|
if not trade_count_lock.get(row.date, 0) < max_open_trades:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
trade_count_lock[row.date] = trade_count_lock.get(row.date, 0) + 1
|
trade_count_lock[row.date] = trade_count_lock.get(row.date, 0) + 1
|
||||||
|
|
||||||
trade_entry = self._get_sell_trade_entry(pair, row, ticker[pair][indexes[pair]:],
|
trade_entry = self._get_sell_trade_entry(pair, row, ticker[pair][indexes[pair]:],
|
||||||
@ -377,6 +381,7 @@ class Backtesting(object):
|
|||||||
# Set lock_pair_until to end of testing period if trade could not be closed
|
# Set lock_pair_until to end of testing period if trade could not be closed
|
||||||
lock_pair_until[pair] = end_date.datetime
|
lock_pair_until[pair] = end_date.datetime
|
||||||
|
|
||||||
|
# Move time one configured time_interval ahead.
|
||||||
tmp += timedelta(minutes=self.ticker_interval_mins)
|
tmp += timedelta(minutes=self.ticker_interval_mins)
|
||||||
return DataFrame.from_records(trades, columns=BacktestResult._fields)
|
return DataFrame.from_records(trades, columns=BacktestResult._fields)
|
||||||
|
|
||||||
|
@ -701,9 +701,13 @@ def test_backtest_multi_pair(default_conf, fee, mocker, tres, pair):
|
|||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
|
|
||||||
pairs = ['ADA/BTC', 'DASH/BTC', 'ETH/BTC', 'LTC/BTC', 'NXT/BTC']
|
pairs = ['ADA/BTC', 'DASH/BTC', 'ETH/BTC', 'LTC/BTC', 'NXT/BTC']
|
||||||
data = history.load_data(datadir=None, ticker_interval='5m', pairs=pairs)
|
data = history.load_data(datadir=None, ticker_interval='5m', pairs=pairs)
|
||||||
|
# Only use 500 lines to increase performance
|
||||||
data = trim_dictlist(data, -500)
|
data = trim_dictlist(data, -500)
|
||||||
|
|
||||||
|
# Remove data for one pair from the beginning of the data
|
||||||
data[pair] = data[pair][tres:]
|
data[pair] = data[pair][tres:]
|
||||||
# We need to enable sell-signal - otherwise it sells on ROI!!
|
# We need to enable sell-signal - otherwise it sells on ROI!!
|
||||||
default_conf['experimental'] = {"use_sell_signal": True}
|
default_conf['experimental'] = {"use_sell_signal": True}
|
||||||
|
Loading…
Reference in New Issue
Block a user