Merge commit '35c51c73f713bfdb81bd84721f3dceab0c19e819' into feature/objectify

This commit is contained in:
Gerald Lonlas 2018-03-04 01:33:39 -08:00
commit 6fcc173489
3 changed files with 30 additions and 43 deletions

View File

@ -107,10 +107,28 @@ class Arguments(object):
""" """
parser.add_argument( parser.add_argument(
'-l', '--live', '-l', '--live',
help='using live data',
action='store_true', action='store_true',
dest='live', dest='live',
help='using live data',
) )
parser.add_argument(
'-r', '--refresh-pairs-cached',
help='refresh the pairs files in tests/testdata with the latest data from Bittrex. \
Use it if you want to run your backtesting with up-to-date data.',
action='store_true',
dest='refresh_pairs',
)
parser.add_argument(
'--export',
help='export backtest results, argument are: trades\
Example --export=trades',
type=str,
default=None,
dest='export',
)
@staticmethod
def _optimizer_shared_options(parser: argparse.ArgumentParser) -> None:
parser.add_argument( parser.add_argument(
'-i', '--ticker-interval', '-i', '--ticker-interval',
help='specify ticker interval in minutes (1, 5, 30, 60, 1440)', help='specify ticker interval in minutes (1, 5, 30, 60, 1440)',
@ -124,24 +142,9 @@ class Arguments(object):
action='store_true', action='store_true',
dest='realistic_simulation', dest='realistic_simulation',
) )
parser.add_argument(
'-r', '--refresh-pairs-cached',
help='refresh the pairs files in tests/testdata with the latest data from Bittrex. \
Use it if you want to run your backtesting with up-to-date data.',
action='store_true',
dest='refresh_pairs',
)
parser.add_argument(
'--export',
help='Export backtest results, argument are: trades\
Example --export=trades',
type=str,
default=None,
dest='export',
)
parser.add_argument( parser.add_argument(
'--timerange', '--timerange',
help='Specify what timerange of data to use.', help='specify what timerange of data to use.',
default=None, default=None,
type=str, type=str,
dest='timerange', dest='timerange',
@ -166,20 +169,6 @@ class Arguments(object):
dest='mongodb', dest='mongodb',
action='store_true', action='store_true',
) )
parser.add_argument(
'-i', '--ticker-interval',
help='specify ticker interval in minutes (1, 5, 30, 60, 1440)',
dest='ticker_interval',
type=int,
metavar='INT',
)
parser.add_argument(
'--timerange',
help='Specify what timerange of data to use.',
default=None,
type=str,
dest='timerange',
)
parser.add_argument( parser.add_argument(
'-s', '--spaces', '-s', '--spaces',
help='Specify which parameters to hyperopt. Space separate list. \ help='Specify which parameters to hyperopt. Space separate list. \
@ -202,11 +191,13 @@ class Arguments(object):
# Add backtesting subcommand # Add backtesting subcommand
backtesting_cmd = subparsers.add_parser('backtesting', help='backtesting module') backtesting_cmd = subparsers.add_parser('backtesting', help='backtesting module')
backtesting_cmd.set_defaults(func=backtesting.start) backtesting_cmd.set_defaults(func=backtesting.start)
self._optimizer_shared_options(backtesting_cmd)
self._backtesting_options(backtesting_cmd) self._backtesting_options(backtesting_cmd)
# Add hyperopt subcommand # Add hyperopt subcommand
hyperopt_cmd = subparsers.add_parser('hyperopt', help='hyperopt module') hyperopt_cmd = subparsers.add_parser('hyperopt', help='hyperopt module')
hyperopt_cmd.set_defaults(func=hyperopt.start) hyperopt_cmd.set_defaults(func=hyperopt.start)
self._optimizer_shared_options(hyperopt_cmd)
self._hyperopt_options(hyperopt_cmd) self._hyperopt_options(hyperopt_cmd)
@staticmethod @staticmethod

View File

@ -147,13 +147,12 @@ class Backtesting(object):
realistic: do we try to simulate realistic trades? (default: True) realistic: do we try to simulate realistic trades? (default: True)
sell_profit_only: sell if profit only sell_profit_only: sell if profit only
use_sell_signal: act on sell-signal use_sell_signal: act on sell-signal
stoploss: use stoploss
:return: DataFrame :return: DataFrame
""" """
headers = ['date', 'buy', 'open', 'close', 'sell'] headers = ['date', 'buy', 'open', 'close', 'sell']
processed = args['processed'] processed = args['processed']
max_open_trades = args.get('max_open_trades', 0) max_open_trades = args.get('max_open_trades', 0)
realistic = args.get('realistic', True) realistic = args.get('realistic', False)
record = args.get('record', None) record = args.get('record', None)
records = [] records = []
trades = [] trades = []
@ -251,7 +250,6 @@ class Backtesting(object):
'realistic': self.config.get('realistic_simulation', False), 'realistic': self.config.get('realistic_simulation', False),
'sell_profit_only': sell_profit_only, 'sell_profit_only': sell_profit_only,
'use_sell_signal': use_sell_signal, 'use_sell_signal': use_sell_signal,
'stoploss': self.analyze.strategy.stoploss,
'record': self.config.get('export') 'record': self.config.get('export')
} }
) )

View File

@ -433,23 +433,21 @@ class Hyperopt(Backtesting):
return populate_buy_trend return populate_buy_trend
def optimizer(self, params) -> Dict: def generate_optimizer(self, params) -> Dict:
if 'roi_t1' in params: if self.has_space('roi'):
self.analyze.strategy.minimal_roi = self.generate_roi_table(params) self.analyze.strategy.minimal_roi = self.generate_roi_table(params)
if 'trigger' in params: if self.has_space('buy'):
self.populate_buy_trend = self.buy_strategy_generator(params) self.populate_buy_trend = self.buy_strategy_generator(params)
if 'stoploss' in params: if self.has_space('stoploss'):
stoploss = params['stoploss'] self.analyze.strategy.stoploss = params['stoploss']
else:
stoploss = self.analyze.strategy.stoploss
results = self.backtest( results = self.backtest(
{ {
'stake_amount': self.config['stake_amount'], 'stake_amount': self.config['stake_amount'],
'processed': self.processed, 'processed': self.processed,
'stoploss': stoploss 'realistic': params['realistic_simulation'],
} }
) )
result_explanation = self.format_results(results) result_explanation = self.format_results(results)
@ -542,7 +540,7 @@ class Hyperopt(Backtesting):
self.logging.set_format('\n%(message)s') self.logging.set_format('\n%(message)s')
best_parameters = fmin( best_parameters = fmin(
fn=self.optimizer, fn=self.generate_optimizer,
space=self.hyperopt_space(), space=self.hyperopt_space(),
algo=tpe.suggest, algo=tpe.suggest,
max_evals=self.total_tries, max_evals=self.total_tries,