backtest export json2
This commit is contained in:
parent
27769f0301
commit
ed47ee4e29
@ -51,6 +51,11 @@ python3 ./freqtrade/main.py backtesting --realistic-simulation --live
|
||||
python3 ./freqtrade/main.py backtesting --datadir freqtrade/tests/testdata-20180101
|
||||
```
|
||||
|
||||
**Exporting trades to file**
|
||||
```bash
|
||||
freqtrade backtesting --export trades
|
||||
```
|
||||
|
||||
For help about backtesting usage, please refer to
|
||||
[Backtesting commands](#backtesting-commands).
|
||||
|
||||
|
@ -188,6 +188,14 @@ def build_subcommands(parser: argparse.ArgumentParser) -> None:
|
||||
action='store_true',
|
||||
dest='refresh_pairs',
|
||||
)
|
||||
backtesting_cmd.add_argument(
|
||||
'--export',
|
||||
help='Export backtest results, argument are: trades\
|
||||
Example --export trades',
|
||||
type=str,
|
||||
default=None,
|
||||
dest='export',
|
||||
)
|
||||
|
||||
# Add hyperopt subcommand
|
||||
hyperopt_cmd = subparsers.add_parser('hyperopt', help='hyperopt module')
|
||||
|
@ -1,6 +1,5 @@
|
||||
# pragma pylint: disable=missing-docstring,W0212
|
||||
|
||||
|
||||
import logging
|
||||
from typing import Tuple, Dict
|
||||
|
||||
@ -121,6 +120,8 @@ def backtest(args) -> DataFrame:
|
||||
processed = args['processed']
|
||||
max_open_trades = args.get('max_open_trades', 0)
|
||||
realistic = args.get('realistic', True)
|
||||
record = args.get('record', None)
|
||||
records = []
|
||||
trades = []
|
||||
trade_count_lock: dict = {}
|
||||
exchange._API = Bittrex({'key': '', 'secret': ''})
|
||||
@ -148,6 +149,16 @@ def backtest(args) -> DataFrame:
|
||||
if ret:
|
||||
lock_pair_until, trade_entry = ret
|
||||
trades.append(trade_entry)
|
||||
if record:
|
||||
# Note, need to be json.dump friendly
|
||||
# record a tuple of pair, current_profit_percent, entry-date, duration
|
||||
records.append((pair, trade_entry[1],
|
||||
row.Index, trade_entry[3]))
|
||||
# For now export inside backtest(), maybe change so that backtest()
|
||||
# returns a tuple like: (dataframe, records, logs, etc)
|
||||
if record and record.find('trades') >= 0:
|
||||
logger.info('Dumping backtest results')
|
||||
misc.file_dump_json('backtest-result.json', records)
|
||||
labels = ['currency', 'profit_percent', 'profit_BTC', 'duration', 'profit', 'loss']
|
||||
return DataFrame.from_records(trades, columns=labels)
|
||||
|
||||
@ -202,7 +213,8 @@ def start(args):
|
||||
'realistic': args.realistic_simulation,
|
||||
'sell_profit_only': sell_profit_only,
|
||||
'use_sell_signal': use_sell_signal,
|
||||
'stoploss': config.get('stoploss')
|
||||
'stoploss': config.get('stoploss'),
|
||||
'record': args.export
|
||||
})
|
||||
logger.info(
|
||||
'\n==================================== BACKTESTING REPORT ====================================\n%s', # noqa
|
||||
|
@ -175,6 +175,7 @@ def test_backtest_start(default_conf, mocker, caplog):
|
||||
args.level = 10
|
||||
args.live = False
|
||||
args.datadir = None
|
||||
args.export = None
|
||||
backtesting.start(args)
|
||||
# check the logs, that will contain the backtest result
|
||||
exists = ['Using max_open_trades: 1 ...',
|
||||
|
Loading…
Reference in New Issue
Block a user