commit
58d07eeb87
@ -225,11 +225,38 @@ def calculate_loss(total_profit: float, trade_count: int, trade_duration: float)
|
|||||||
return trade_loss + profit_loss + duration_loss
|
return trade_loss + profit_loss + duration_loss
|
||||||
|
|
||||||
|
|
||||||
def hyperopt_space() -> List[Dict]:
|
def generate_roi_table(params):
|
||||||
|
roi_table = {}
|
||||||
|
roi_table["0"] = params['roi_p1'] + params['roi_p2'] + params['roi_p3']
|
||||||
|
roi_table[str(params['roi_t3'])] = params['roi_p1'] + params['roi_p2']
|
||||||
|
roi_table[str(params['roi_t3'] + params['roi_t2'])] = params['roi_p1']
|
||||||
|
roi_table[str(params['roi_t3'] + params['roi_t2'] + params['roi_t1'])] = 0
|
||||||
|
|
||||||
|
return roi_table
|
||||||
|
|
||||||
|
|
||||||
|
def roi_space() -> List[Dict]:
|
||||||
|
return {
|
||||||
|
'roi_t1': hp.quniform('roi_t1', 10, 220, 10),
|
||||||
|
'roi_t2': hp.quniform('roi_t2', 10, 120, 10),
|
||||||
|
'roi_t3': hp.quniform('roi_t3', 10, 120, 10),
|
||||||
|
'roi_p1': hp.quniform('roi_p1', 1, 5, 1),
|
||||||
|
'roi_p2': hp.quniform('roi_p2', 1, 5, 1),
|
||||||
|
'roi_p3': hp.quniform('roi_p3', 1, 10, 1),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def stoploss_space() -> Dict:
|
||||||
|
return {
|
||||||
|
'stoploss': hp.uniform('stoploss', -0.5, -0.02),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def indicator_space() -> List[Dict]:
|
||||||
"""
|
"""
|
||||||
Define your Hyperopt space for searching strategy parameters
|
Define your Hyperopt space for searching strategy parameters
|
||||||
"""
|
"""
|
||||||
space = {
|
return {
|
||||||
'macd_below_zero': hp.choice('macd_below_zero', [
|
'macd_below_zero': hp.choice('macd_below_zero', [
|
||||||
{'enabled': False},
|
{'enabled': False},
|
||||||
{'enabled': True}
|
{'enabled': True}
|
||||||
@ -282,9 +309,11 @@ def hyperopt_space() -> List[Dict]:
|
|||||||
{'type': 'heiken_reversal_bull'},
|
{'type': 'heiken_reversal_bull'},
|
||||||
{'type': 'di_cross'},
|
{'type': 'di_cross'},
|
||||||
]),
|
]),
|
||||||
'stoploss': hp.uniform('stoploss', -0.5, -0.02),
|
|
||||||
}
|
}
|
||||||
return space
|
|
||||||
|
|
||||||
|
def hyperopt_space() -> List[Dict]:
|
||||||
|
return {**indicator_space(), **roi_space(), **stoploss_space()}
|
||||||
|
|
||||||
|
|
||||||
def buy_strategy_generator(params) -> None:
|
def buy_strategy_generator(params) -> None:
|
||||||
@ -364,6 +393,10 @@ def buy_strategy_generator(params) -> None:
|
|||||||
def optimizer(params):
|
def optimizer(params):
|
||||||
global _CURRENT_TRIES
|
global _CURRENT_TRIES
|
||||||
|
|
||||||
|
if 'roi_t1' in params:
|
||||||
|
strategy = Strategy()
|
||||||
|
strategy.minimal_roi = generate_roi_table(params)
|
||||||
|
|
||||||
backtesting.populate_buy_trend = buy_strategy_generator(params)
|
backtesting.populate_buy_trend = buy_strategy_generator(params)
|
||||||
|
|
||||||
results = backtest({'stake_amount': OPTIMIZE_CONFIG['stake_amount'],
|
results = backtest({'stake_amount': OPTIMIZE_CONFIG['stake_amount'],
|
||||||
@ -484,6 +517,8 @@ def start(args):
|
|||||||
)
|
)
|
||||||
|
|
||||||
logger.info('Best parameters:\n%s', json.dumps(best_parameters, indent=4))
|
logger.info('Best parameters:\n%s', json.dumps(best_parameters, indent=4))
|
||||||
|
if 'roi_t1' in best_parameters:
|
||||||
|
logger.info('ROI table:\n%s', generate_roi_table(best_parameters))
|
||||||
logger.info('Best Result:\n%s', best_result)
|
logger.info('Best Result:\n%s', best_result)
|
||||||
|
|
||||||
# Store trials result to file to resume next time
|
# Store trials result to file to resume next time
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# pragma pylint: disable=missing-docstring,W0212,C0103
|
# pragma pylint: disable=missing-docstring,W0212,C0103
|
||||||
from freqtrade.optimize.hyperopt import calculate_loss, TARGET_TRADES, EXPECTED_MAX_PROFIT, start, \
|
from freqtrade.optimize.hyperopt import calculate_loss, TARGET_TRADES, EXPECTED_MAX_PROFIT, start, \
|
||||||
log_results, save_trials, read_trials
|
log_results, save_trials, read_trials, generate_roi_table
|
||||||
|
|
||||||
|
|
||||||
def test_loss_calculation_prefer_correct_trade_count():
|
def test_loss_calculation_prefer_correct_trade_count():
|
||||||
@ -125,6 +125,12 @@ def test_fmin_best_results(mocker, caplog):
|
|||||||
"uptrend_short_ema": 0,
|
"uptrend_short_ema": 0,
|
||||||
"uptrend_sma": 0,
|
"uptrend_sma": 0,
|
||||||
"stoploss": -0.1,
|
"stoploss": -0.1,
|
||||||
|
"roi_t1": 1,
|
||||||
|
"roi_t2": 2,
|
||||||
|
"roi_t3": 3,
|
||||||
|
"roi_p1": 1,
|
||||||
|
"roi_p2": 2,
|
||||||
|
"roi_p3": 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
mocker.patch('freqtrade.optimize.hyperopt.MongoTrials', return_value=create_trials(mocker))
|
mocker.patch('freqtrade.optimize.hyperopt.MongoTrials', return_value=create_trials(mocker))
|
||||||
@ -228,3 +234,15 @@ def test_read_trials_returns_trials_file(mocker):
|
|||||||
assert read_trials() == trials
|
assert read_trials() == trials
|
||||||
mock_open.assert_called_once()
|
mock_open.assert_called_once()
|
||||||
mock_load.assert_called_once()
|
mock_load.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
|
def test_roi_table_generation():
|
||||||
|
params = {
|
||||||
|
'roi_t1': 5,
|
||||||
|
'roi_t2': 10,
|
||||||
|
'roi_t3': 15,
|
||||||
|
'roi_p1': 1,
|
||||||
|
'roi_p2': 2,
|
||||||
|
'roi_p3': 3,
|
||||||
|
}
|
||||||
|
assert generate_roi_table(params) == {'0': 6, '15': 3, '25': 1, '30': 0}
|
||||||
|
Loading…
Reference in New Issue
Block a user