change print to format so result can be used in hyperopt Trials

This commit is contained in:
Janne Sinivirta 2017-10-26 17:24:28 +03:00
parent 29de1645fe
commit 08ca7a8166
2 changed files with 10 additions and 9 deletions

View File

@ -13,17 +13,17 @@ from freqtrade.persistence import Trade
logging.disable(logging.DEBUG) # disable debug logs that slow backtesting a lot
def print_results(results):
print('Made {} buys. Average profit {:.2f}%. Total profit was {:.3f}. Average duration {:.1f} mins.'.format(
def format_results(results):
return 'Made {} buys. Average profit {:.2f}%. Total profit was {:.3f}. Average duration {:.1f} mins.'.format(
len(results.index),
results.profit.mean() * 100.0,
results.profit.sum(),
results.duration.mean() * 5
))
)
def print_pair_results(pair, results):
print('For currency {}:'.format(pair))
print_results(results[results.currency == pair])
print(format_results(results[results.currency == pair]))
@pytest.fixture
def pairs():
@ -77,4 +77,4 @@ def test_backtest(conf, pairs, mocker, report=True):
print('====================== BACKTESTING REPORT ================================')
[print_pair_results(pair, results) for pair in pairs]
print('TOTAL OVER ALL TRADES:')
print_results(results)
print(format_results(results))

View File

@ -15,7 +15,7 @@ from freqtrade.analyze import analyze_ticker
from freqtrade.main import should_sell
from freqtrade.persistence import Trade
from freqtrade.tests.test_backtesting import backtest, print_results
from freqtrade.tests.test_backtesting import backtest, format_results
logging.disable(logging.DEBUG) # disable debug logs that slow backtesting a lot
@ -83,9 +83,10 @@ def test_hyperopt(conf, pairs, mocker):
mocker.patch('freqtrade.analyze.populate_buy_trend', side_effect=buy_strategy)
results = backtest(conf, pairs, mocker)
print_results(results)
# set the value below to suit your number concurrent trades so its realistic to 20days of data
result = format_results(results)
print(result)
# set TARGET_TRADES to suit your number concurrent trades so its realistic to 20days of data
TARGET_TRADES = 1200
if results.profit.sum() == 0 or results.profit.mean() == 0:
return 49999999999 # avoid division by zero, return huge value to discard result