# Buggy code
def start(args):
    global TOTAL_TRIES, PROCESSED, SPACE
    TOTAL_TRIES = args.epochs

    exchange._API = Bittrex({"key": "", "secret": ""})

    # Initialize logger
    logging.basicConfig(
        level=args.loglevel,
        format="\n%(message)s",
    )

    logger.info("Using config: %s ...", args.config)
    config = load_config(args.config)
    pairs = config["exchange"]["pair_whitelist"]
    PROCESSED = optimize.preprocess(
        optimize.load_data(
            args.datadir, pairs=pairs, ticker_interval=args.ticker_interval
        )
    )

    if args.mongodb:
        logger.info("Using mongodb ...")
        logger.info(
            "Start scripts/start-mongodb.sh and start-hyperopt-worker.sh manually!"
        )

        db_name = "freqtrade_hyperopt"
        trials = MongoTrials(
            "mongo://127.0.0.1:1234/{}/jobs".format(db_name), exp_key="exp1"
        )
    else:
        trials = Trials()

    best = fmin(
        fn=optimizer,
        space=SPACE,
        algo=tpe.suggest,
        max_evals=TOTAL_TRIES,
        trials=trials,
    )

    # Improve best parameter logging display
    if best:
        best = space_eval(SPACE, best)

    logger.info("Best parameters:\n%s", json.dumps(best, indent=4))

    results = sorted(trials.results, key=itemgetter("loss"))
    logger.info("Best Result:\n%s", results[0]["result"])


# Traceback (AttributeError)
Validating configuration ...
.....Traceback (most recent call last):
File "freqtrade/.env/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 52, in _wrapfunc
return getattr(obj, method)(*args, **kwds)
AttributeError: 'list' object has no attribute 'argmin'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "./freqtrade/main.py", line 472, in <module>
main()
File "./freqtrade/main.py", line 412, in main
args.func(args)
File "freqtrade/freqtrade/optimize/hyperopt.py", line 245, in start
best = fmin(fn=optimizer, space=SPACE, algo=tpe.suggest, max_evals=TOTAL_TRIES, trials=trials)
File "freqtrade/.env/lib/python3.6/site-packages/hyperopt/fmin.py", line 307, in fmin
return_argmin=return_argmin,
File "freqtrade/.env/lib/python3.6/site-packages/hyperopt/base.py", line 635, in fmin
return_argmin=return_argmin)
File "freqtrade/.env/lib/python3.6/site-packages/hyperopt/fmin.py", line 322, in fmin
return trials.argmin
File "freqtrade/.env/lib/python3.6/site-packages/hyperopt/base.py", line 590, in argmin
best_trial = self.best_trial
File "freqtrade/.env/lib/python3.6/site-packages/hyperopt/base.py", line 585, in best_trial
best = np.argmin(losses)
File "freqtrade/.env/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 1068, in argmin
return _wrapfunc(a, 'argmin', axis=axis, out=out)
File "freqtrade/.env/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 62, in _wrapfunc
return _wrapit(obj, method, *args, **kwds)
File "freqtrade/.env/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 42, in _wrapit
result = getattr(asarray(obj), method)(*args, **kwds)
ValueError: attempt to get argmin of an empty sequence

# Fixed code
def start(args):
    global TOTAL_TRIES, PROCESSED, SPACE
    TOTAL_TRIES = args.epochs

    exchange._API = Bittrex({"key": "", "secret": ""})

    # Initialize logger
    logging.basicConfig(
        level=args.loglevel,
        format="\n%(message)s",
    )

    logger.info("Using config: %s ...", args.config)
    config = load_config(args.config)
    pairs = config["exchange"]["pair_whitelist"]
    PROCESSED = optimize.preprocess(
        optimize.load_data(
            args.datadir, pairs=pairs, ticker_interval=args.ticker_interval
        )
    )

    if args.mongodb:
        logger.info("Using mongodb ...")
        logger.info(
            "Start scripts/start-mongodb.sh and start-hyperopt-worker.sh manually!"
        )

        db_name = "freqtrade_hyperopt"
        trials = MongoTrials(
            "mongo://127.0.0.1:1234/{}/jobs".format(db_name), exp_key="exp1"
        )
    else:
        trials = Trials()

    try:
        best_parameters = fmin(
            fn=optimizer,
            space=SPACE,
            algo=tpe.suggest,
            max_evals=TOTAL_TRIES,
            trials=trials,
        )

        results = sorted(trials.results, key=itemgetter("loss"))
        best_result = results[0]["result"]

    except ValueError:
        best_parameters = {}
        best_result = (
            "Sorry, Hyperopt was not able to find good parameters. Please "
            "try with more epochs (param: -e)."
        )

    # Improve best parameter logging display
    if best_parameters:
        best_parameters = space_eval(SPACE, best_parameters)

    logger.info("Best parameters:\n%s", json.dumps(best_parameters, indent=4))
    logger.info("Best Result:\n%s", best_result)