- add a profit/loss counter

- the use of the sell_signal is conditional now (taken from the config)
This commit is contained in:
Jean-Baptiste LE STANG 2018-01-03 11:19:46 +01:00
parent c176ace889
commit 45f2d01895

View File

@ -41,7 +41,7 @@ def generate_text_table(
floatfmt = ('s', 'd', '.2f', '.8f', '.1f')
tabular_data = []
headers = ['pair', 'buy count', 'avg profit %',
'total profit ' + stake_currency, 'avg duration']
'total profit ' + stake_currency, 'avg duration', 'profit','loss']
for pair in data:
result = results[results.currency == pair]
tabular_data.append([
@ -50,6 +50,8 @@ def generate_text_table(
result.profit_percent.mean() * 100.0,
result.profit_BTC.sum(),
result.duration.mean() * ticker_interval,
result.profit.sum(),
result.loss.sum()
])
# Append Total
@ -59,12 +61,15 @@ def generate_text_table(
results.profit_percent.mean() * 100.0,
results.profit_BTC.sum(),
results.duration.mean() * ticker_interval,
results.profit.sum(),
results.loss.sum(),
])
return tabulate(tabular_data, headers=headers, floatfmt=floatfmt)
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
: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)
if (sell_profit_only and current_profit_percent < 0) :
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)
lock_pair_until = row2.Index
@ -122,11 +127,13 @@ def backtest(stake_amount: float, processed: Dict[str, DataFrame],
pair,
current_profit_percent,
current_profit_btc,
row2.Index - row.Index
row2.Index - row.Index,
current_profit_btc > 0,
current_profit_btc < 0
)
)
break
labels = ['currency', 'profit_percent', 'profit_BTC', 'duration']
labels = ['currency', 'profit_percent', 'profit_BTC', 'duration', 'profit','loss']
return DataFrame.from_records(trades, columns=labels)
@ -174,7 +181,7 @@ def start(args):
# Execute backtest and print results
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(
'\n====================== BACKTESTING REPORT ================================\n%s',