Merge pull request #218 from glonlas/fix_hyperopt
Fix hyperopt when using MongoDB
This commit is contained in:
commit
ff186c7f65
11
.gitignore
vendored
11
.gitignore
vendored
@ -1,5 +1,10 @@
|
||||
# Freqtrade rules
|
||||
freqtrade/tests/testdata/*.json
|
||||
hyperopt_conf.py
|
||||
config.json
|
||||
*.sqlite
|
||||
.hyperopt
|
||||
logfile.txt
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
@ -76,12 +81,6 @@ target/
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
config.json
|
||||
preprocessor.py
|
||||
*.sqlite
|
||||
.hyperopt
|
||||
logfile.txt
|
||||
|
||||
.env
|
||||
.venv
|
||||
.idea
|
||||
|
@ -5,6 +5,7 @@ import json
|
||||
import os
|
||||
from typing import Optional, List, Dict
|
||||
from freqtrade.exchange import get_ticker_history
|
||||
from freqtrade.optimize.hyperopt_conf import hyperopt_optimize_conf
|
||||
|
||||
from pandas import DataFrame
|
||||
|
||||
@ -13,7 +14,7 @@ from freqtrade.analyze import populate_indicators, parse_ticker_dataframe
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def load_data(pairs: List[str], ticker_interval: int = 5,
|
||||
def load_data(ticker_interval: int = 5, pairs: Optional[List[str]] = None,
|
||||
refresh_pairs: Optional[bool] = False) -> Dict[str, List]:
|
||||
"""
|
||||
Loads ticker history data for the given parameters
|
||||
@ -24,12 +25,14 @@ def load_data(pairs: List[str], ticker_interval: int = 5,
|
||||
path = testdata_path()
|
||||
result = {}
|
||||
|
||||
_pairs = pairs or hyperopt_optimize_conf()['exchange']['pair_whitelist']
|
||||
|
||||
# If the user force the refresh of pairs
|
||||
if refresh_pairs:
|
||||
logger.info('Download data for all pairs and store them in freqtrade/tests/testsdata')
|
||||
download_pairs(pairs)
|
||||
download_pairs(_pairs)
|
||||
|
||||
for pair in pairs:
|
||||
for pair in _pairs:
|
||||
file = '{abspath}/{pair}-{ticker_interval}.json'.format(
|
||||
abspath=path,
|
||||
pair=pair,
|
||||
|
@ -16,6 +16,7 @@ from freqtrade import exchange, optimize
|
||||
from freqtrade.exchange import Bittrex
|
||||
from freqtrade.misc import load_config
|
||||
from freqtrade.optimize.backtesting import backtest
|
||||
from freqtrade.optimize.hyperopt_conf import hyperopt_optimize_conf
|
||||
from freqtrade.vendor.qtpylib.indicators import crossed_above
|
||||
|
||||
# Remove noisy log messages
|
||||
@ -35,19 +36,8 @@ AVG_PROFIT_TO_BEAT = 0.2
|
||||
AVG_DURATION_TO_BEAT = 50
|
||||
|
||||
# Configuration and data used by hyperopt
|
||||
PROCESSED = []
|
||||
OPTIMIZE_CONFIG = {
|
||||
'max_open_trades': 3,
|
||||
'stake_currency': 'BTC',
|
||||
'stake_amount': 0.01,
|
||||
'minimal_roi': {
|
||||
'40': 0.0,
|
||||
'30': 0.01,
|
||||
'20': 0.02,
|
||||
'0': 0.04,
|
||||
},
|
||||
'stoploss': -0.10,
|
||||
}
|
||||
PROCESSED = optimize.preprocess(optimize.load_data())
|
||||
OPTIMIZE_CONFIG = hyperopt_optimize_conf()
|
||||
|
||||
# Monkey patch config
|
||||
from freqtrade import main # noqa
|
||||
|
41
freqtrade/optimize/hyperopt_conf.py
Normal file
41
freqtrade/optimize/hyperopt_conf.py
Normal file
@ -0,0 +1,41 @@
|
||||
"""
|
||||
File that contains the configuration for Hyperopt
|
||||
"""
|
||||
|
||||
|
||||
def hyperopt_optimize_conf() -> dict:
|
||||
"""
|
||||
This function is used to define which parameters Hyperopt must used.
|
||||
The "pair_whitelist" is only used is your are using Hyperopt with MongoDB,
|
||||
without MongoDB, Hyperopt will use the pair your have set in your config file.
|
||||
:return:
|
||||
"""
|
||||
return {
|
||||
'max_open_trades': 3,
|
||||
'stake_currency': 'BTC',
|
||||
'stake_amount': 0.01,
|
||||
"minimal_roi": {
|
||||
'40': 0.0,
|
||||
'30': 0.01,
|
||||
'20': 0.02,
|
||||
'0': 0.04,
|
||||
},
|
||||
'stoploss': -0.10,
|
||||
"bid_strategy": {
|
||||
"ask_last_balance": 0.0
|
||||
},
|
||||
"exchange": {
|
||||
"pair_whitelist": [
|
||||
"BTC_ETH",
|
||||
"BTC_LTC",
|
||||
"BTC_ETC",
|
||||
"BTC_DASH",
|
||||
"BTC_ZEC",
|
||||
"BTC_XLM",
|
||||
"BTC_NXT",
|
||||
"BTC_POWR",
|
||||
"BTC_ADA",
|
||||
"BTC_XMR"
|
||||
]
|
||||
}
|
||||
}
|
16
freqtrade/tests/test_optimize_hyperopt_config.py
Normal file
16
freqtrade/tests/test_optimize_hyperopt_config.py
Normal file
@ -0,0 +1,16 @@
|
||||
# pragma pylint: disable=missing-docstring,W0212
|
||||
|
||||
from freqtrade.optimize.hyperopt_conf import hyperopt_optimize_conf
|
||||
|
||||
|
||||
def test_hyperopt_optimize_conf():
|
||||
hyperopt_conf = hyperopt_optimize_conf()
|
||||
|
||||
assert "max_open_trades" in hyperopt_conf
|
||||
assert "stake_currency" in hyperopt_conf
|
||||
assert "stake_amount" in hyperopt_conf
|
||||
assert "minimal_roi" in hyperopt_conf
|
||||
assert "stoploss" in hyperopt_conf
|
||||
assert "bid_strategy" in hyperopt_conf
|
||||
assert "exchange" in hyperopt_conf
|
||||
assert "pair_whitelist" in hyperopt_conf['exchange']
|
Loading…
Reference in New Issue
Block a user