- add a profit/loss counter
- the use of the sell_signal is conditional now (taken from the config)
This commit is contained in:
parent
c176ace889
commit
45f2d01895
@ -41,7 +41,7 @@ def generate_text_table(
|
|||||||
floatfmt = ('s', 'd', '.2f', '.8f', '.1f')
|
floatfmt = ('s', 'd', '.2f', '.8f', '.1f')
|
||||||
tabular_data = []
|
tabular_data = []
|
||||||
headers = ['pair', 'buy count', 'avg profit %',
|
headers = ['pair', 'buy count', 'avg profit %',
|
||||||
'total profit ' + stake_currency, 'avg duration']
|
'total profit ' + stake_currency, 'avg duration', 'profit','loss']
|
||||||
for pair in data:
|
for pair in data:
|
||||||
result = results[results.currency == pair]
|
result = results[results.currency == pair]
|
||||||
tabular_data.append([
|
tabular_data.append([
|
||||||
@ -50,6 +50,8 @@ def generate_text_table(
|
|||||||
result.profit_percent.mean() * 100.0,
|
result.profit_percent.mean() * 100.0,
|
||||||
result.profit_BTC.sum(),
|
result.profit_BTC.sum(),
|
||||||
result.duration.mean() * ticker_interval,
|
result.duration.mean() * ticker_interval,
|
||||||
|
result.profit.sum(),
|
||||||
|
result.loss.sum()
|
||||||
])
|
])
|
||||||
|
|
||||||
# Append Total
|
# Append Total
|
||||||
@ -59,12 +61,15 @@ def generate_text_table(
|
|||||||
results.profit_percent.mean() * 100.0,
|
results.profit_percent.mean() * 100.0,
|
||||||
results.profit_BTC.sum(),
|
results.profit_BTC.sum(),
|
||||||
results.duration.mean() * ticker_interval,
|
results.duration.mean() * ticker_interval,
|
||||||
|
results.profit.sum(),
|
||||||
|
results.loss.sum(),
|
||||||
|
|
||||||
])
|
])
|
||||||
return tabulate(tabular_data, headers=headers, floatfmt=floatfmt)
|
return tabulate(tabular_data, headers=headers, floatfmt=floatfmt)
|
||||||
|
|
||||||
|
|
||||||
def backtest(stake_amount: float, processed: Dict[str, DataFrame],
|
def backtest(stake_amount: float, processed: Dict[str, DataFrame],
|
||||||
max_open_trades: int = 0, realistic: bool = True, sell_profit_only: bool = False, stoploss: int = -1.00) -> DataFrame:
|
max_open_trades: int = 0, realistic: bool = True, sell_profit_only: bool = False, stoploss: int = -1.00, use_sell_signal: bool = False) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
Implements backtesting functionality
|
Implements backtesting functionality
|
||||||
:param stake_amount: btc amount to use for each trade
|
:param stake_amount: btc amount to use for each trade
|
||||||
@ -113,7 +118,7 @@ def backtest(stake_amount: float, processed: Dict[str, DataFrame],
|
|||||||
current_profit_percent = trade.calc_profit_percent(rate=row2.close)
|
current_profit_percent = trade.calc_profit_percent(rate=row2.close)
|
||||||
if (sell_profit_only and current_profit_percent < 0) :
|
if (sell_profit_only and current_profit_percent < 0) :
|
||||||
continue
|
continue
|
||||||
if min_roi_reached(trade, row2.close, row2.date) or row2.sell == 1 or current_profit_percent < stoploss:
|
if min_roi_reached(trade, row2.close, row2.date) or (row2.sell == 1 and use_sell_signal) or current_profit_percent <= stoploss:
|
||||||
current_profit_btc = trade.calc_profit(rate=row2.close)
|
current_profit_btc = trade.calc_profit(rate=row2.close)
|
||||||
lock_pair_until = row2.Index
|
lock_pair_until = row2.Index
|
||||||
|
|
||||||
@ -122,11 +127,13 @@ def backtest(stake_amount: float, processed: Dict[str, DataFrame],
|
|||||||
pair,
|
pair,
|
||||||
current_profit_percent,
|
current_profit_percent,
|
||||||
current_profit_btc,
|
current_profit_btc,
|
||||||
row2.Index - row.Index
|
row2.Index - row.Index,
|
||||||
|
current_profit_btc > 0,
|
||||||
|
current_profit_btc < 0
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
labels = ['currency', 'profit_percent', 'profit_BTC', 'duration']
|
labels = ['currency', 'profit_percent', 'profit_BTC', 'duration', 'profit','loss']
|
||||||
return DataFrame.from_records(trades, columns=labels)
|
return DataFrame.from_records(trades, columns=labels)
|
||||||
|
|
||||||
|
|
||||||
@ -174,7 +181,7 @@ def start(args):
|
|||||||
|
|
||||||
# Execute backtest and print results
|
# Execute backtest and print results
|
||||||
results = backtest(
|
results = backtest(
|
||||||
config['stake_amount'], preprocessed, max_open_trades, args.realistic_simulation, config.get('experimental',{}).get('sell_profit_only', False), config.get('stoploss')
|
config['stake_amount'], preprocessed, max_open_trades, args.realistic_simulation, config.get('experimental',{}).get('sell_profit_only', False), config.get('stoploss'), config.get('experimental',{}).get('use_sell_signal',False)
|
||||||
)
|
)
|
||||||
logger.info(
|
logger.info(
|
||||||
'\n====================== BACKTESTING REPORT ================================\n%s',
|
'\n====================== BACKTESTING REPORT ================================\n%s',
|
||||||
|
Loading…
Reference in New Issue
Block a user