:Merge branch 'develop' into add-metric-tracker

This commit is contained in:
robcaulk 2022-10-15 15:54:41 +02:00
commit 9135e631c0
3 changed files with 10 additions and 15 deletions

View File

@ -919,11 +919,10 @@ class Backtesting:
return trade return trade
def handle_left_open(self, open_trades: Dict[str, List[LocalTrade]], def handle_left_open(self, open_trades: Dict[str, List[LocalTrade]],
data: Dict[str, List[Tuple]]) -> List[LocalTrade]: data: Dict[str, List[Tuple]]) -> None:
""" """
Handling of left open trades at the end of backtesting Handling of left open trades at the end of backtesting
""" """
trades = []
for pair in open_trades.keys(): for pair in open_trades.keys():
if len(open_trades[pair]) > 0: if len(open_trades[pair]) > 0:
for trade in open_trades[pair]: for trade in open_trades[pair]:
@ -938,11 +937,6 @@ class Backtesting:
trade.exit_reason = ExitType.FORCE_EXIT.value trade.exit_reason = ExitType.FORCE_EXIT.value
trade.close(exit_row[OPEN_IDX], show_msg=False) trade.close(exit_row[OPEN_IDX], show_msg=False)
LocalTrade.close_bt_trade(trade) LocalTrade.close_bt_trade(trade)
# Deepcopy object to have wallets update correctly
trade1 = deepcopy(trade)
trade1.is_open = True
trades.append(trade1)
return trades
def trade_slot_available(self, max_open_trades: int, open_trade_count: int) -> bool: def trade_slot_available(self, max_open_trades: int, open_trade_count: int) -> bool:
# Always allow trades when max_open_trades is enabled. # Always allow trades when max_open_trades is enabled.
@ -1094,7 +1088,6 @@ class Backtesting:
:param enable_protections: Should protections be enabled? :param enable_protections: Should protections be enabled?
:return: DataFrame with trades (results of backtesting) :return: DataFrame with trades (results of backtesting)
""" """
trades: List[LocalTrade] = []
self.prepare_backtest(enable_protections) self.prepare_backtest(enable_protections)
# Ensure wallets are uptodate (important for --strategy-list) # Ensure wallets are uptodate (important for --strategy-list)
self.wallets.update() self.wallets.update()
@ -1188,7 +1181,6 @@ class Backtesting:
open_trade_count -= 1 open_trade_count -= 1
open_trades[pair].remove(trade) open_trades[pair].remove(trade)
LocalTrade.close_bt_trade(trade) LocalTrade.close_bt_trade(trade)
trades.append(trade)
self.wallets.update() self.wallets.update()
self.run_protections( self.run_protections(
enable_protections, pair, current_time, trade.trade_direction) enable_protections, pair, current_time, trade.trade_direction)
@ -1197,10 +1189,10 @@ class Backtesting:
self.progress.increment() self.progress.increment()
current_time += timedelta(minutes=self.timeframe_min) current_time += timedelta(minutes=self.timeframe_min)
trades += self.handle_left_open(open_trades, data=data) self.handle_left_open(open_trades, data=data)
self.wallets.update() self.wallets.update()
results = trade_list_to_dataframe(trades) results = trade_list_to_dataframe(LocalTrade.trades)
return { return {
'results': results, 'results': results,
'config': self.strategy.config, 'config': self.strategy.config,

View File

@ -408,10 +408,10 @@ def generate_strategy_stats(pairlist: List[str],
exit_reason_stats = generate_exit_reason_stats(max_open_trades=max_open_trades, exit_reason_stats = generate_exit_reason_stats(max_open_trades=max_open_trades,
results=results) results=results)
left_open_results = generate_pair_metrics(pairlist, stake_currency=stake_currency, left_open_results = generate_pair_metrics(
starting_balance=start_balance, pairlist, stake_currency=stake_currency, starting_balance=start_balance,
results=results.loc[results['is_open']], results=results.loc[results['exit_reason'] == 'force_exit'], skip_nan=True)
skip_nan=True)
daily_stats = generate_daily_stats(results) daily_stats = generate_daily_stats(results)
trade_stats = generate_trading_stats(results) trade_stats = generate_trading_stats(results)
best_pair = max([pair for pair in pair_results if pair['key'] != 'TOTAL'], best_pair = max([pair for pair in pair_results if pair['key'] != 'TOTAL'],

View File

@ -55,6 +55,7 @@ def test_extract_data_and_train_model_Standard(mocker, freqai_conf, model):
data_load_timerange = TimeRange.parse_timerange("20180125-20180130") data_load_timerange = TimeRange.parse_timerange("20180125-20180130")
new_timerange = TimeRange.parse_timerange("20180127-20180130") new_timerange = TimeRange.parse_timerange("20180127-20180130")
freqai.dk.set_paths('ADA/BTC', None)
freqai.train_timer("start", "ADA/BTC") freqai.train_timer("start", "ADA/BTC")
freqai.extract_data_and_train_model( freqai.extract_data_and_train_model(
@ -99,6 +100,7 @@ def test_extract_data_and_train_model_MultiTargets(mocker, freqai_conf, model):
data_load_timerange = TimeRange.parse_timerange("20180110-20180130") data_load_timerange = TimeRange.parse_timerange("20180110-20180130")
new_timerange = TimeRange.parse_timerange("20180120-20180130") new_timerange = TimeRange.parse_timerange("20180120-20180130")
freqai.dk.set_paths('ADA/BTC', None)
freqai.extract_data_and_train_model( freqai.extract_data_and_train_model(
new_timerange, "ADA/BTC", strategy, freqai.dk, data_load_timerange) new_timerange, "ADA/BTC", strategy, freqai.dk, data_load_timerange)
@ -140,6 +142,7 @@ def test_extract_data_and_train_model_Classifiers(mocker, freqai_conf, model):
data_load_timerange = TimeRange.parse_timerange("20180110-20180130") data_load_timerange = TimeRange.parse_timerange("20180110-20180130")
new_timerange = TimeRange.parse_timerange("20180120-20180130") new_timerange = TimeRange.parse_timerange("20180120-20180130")
freqai.dk.set_paths('ADA/BTC', None)
freqai.extract_data_and_train_model(new_timerange, "ADA/BTC", freqai.extract_data_and_train_model(new_timerange, "ADA/BTC",
strategy, freqai.dk, data_load_timerange) strategy, freqai.dk, data_load_timerange)