From 639a4d5cf724101b918db0a098527efcaf55e88d Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 17 Jul 2019 07:14:27 +0200 Subject: [PATCH] Allow importing interface from hyperopt.py --- docs/hyperopt.md | 6 ++++-- freqtrade/optimize/default_hyperopt_loss.py | 2 +- freqtrade/optimize/hyperopt.py | 2 ++ freqtrade/optimize/hyperopt_loss_sharpe.py | 2 +- user_data/hyperopts/sample_hyperopt.py | 14 -------------- 5 files changed, 8 insertions(+), 18 deletions(-) diff --git a/docs/hyperopt.md b/docs/hyperopt.md index 74d03b8ab..6be3d590f 100644 --- a/docs/hyperopt.md +++ b/docs/hyperopt.md @@ -161,12 +161,14 @@ This class should be in it's own file within the `user_data/hyperopts/` director ### Using a custom loss function -To use a custom loss Class, make sure that the function `hyperopt_loss_function` is defined in your custom hyperopt class. +To use a custom loss Class, make sure that the function `hyperopt_loss_function` is defined in your custom hyperopt loss class. For the sample below, you then need to add the command line parameter `--hyperoptloss SuperDuperHyperOptLoss` to your hyperopt call so this fuction is being used. -A sample of this can be found below, which is identical to the Default Hyperopt loss implementation. +A sample of this can be found below, which is identical to the Default Hyperopt loss implementation. A full sample can be found [user_data/hyperopts/](https://github.com/freqtrade/freqtrade/blob/develop/user_data/hyperopts/sample_hyperopt_loss.py) ``` python +from freqtrade.optimize.hyperopt import IHyperOptLoss + TARGET_TRADES = 600 EXPECTED_MAX_PROFIT = 3.0 MAX_ACCEPTED_TRADE_DURATION = 300 diff --git a/freqtrade/optimize/default_hyperopt_loss.py b/freqtrade/optimize/default_hyperopt_loss.py index 58be44ab9..2879c4091 100644 --- a/freqtrade/optimize/default_hyperopt_loss.py +++ b/freqtrade/optimize/default_hyperopt_loss.py @@ -8,7 +8,7 @@ from math import exp from pandas import DataFrame -from freqtrade.optimize.hyperopt_loss_interface import IHyperOptLoss +from freqtrade.optimize.hyperopt import IHyperOptLoss # Define some constants: diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index 3cc6efe12..759ceffbe 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -21,6 +21,8 @@ from skopt.space import Dimension from freqtrade.configuration import Arguments from freqtrade.data.history import load_data, get_timeframe from freqtrade.optimize.backtesting import Backtesting +# Import IHyperOptLoss to allow users import from this file +from freqtrade.optimize.hyperopt_loss_interface import IHyperOptLoss # noqa: F4 from freqtrade.resolvers.hyperopt_resolver import HyperOptResolver, HyperOptLossResolver diff --git a/freqtrade/optimize/hyperopt_loss_sharpe.py b/freqtrade/optimize/hyperopt_loss_sharpe.py index 5a22a215f..be1a3d4b4 100644 --- a/freqtrade/optimize/hyperopt_loss_sharpe.py +++ b/freqtrade/optimize/hyperopt_loss_sharpe.py @@ -8,7 +8,7 @@ from datetime import datetime from pandas import DataFrame import numpy as np -from freqtrade.optimize.hyperopt_loss_interface import IHyperOptLoss +from freqtrade.optimize.hyperopt import IHyperOptLoss class SharpeHyperOptLoss(IHyperOptLoss): diff --git a/user_data/hyperopts/sample_hyperopt.py b/user_data/hyperopts/sample_hyperopt.py index 8650d0a98..a78906cf3 100644 --- a/user_data/hyperopts/sample_hyperopt.py +++ b/user_data/hyperopts/sample_hyperopt.py @@ -13,20 +13,6 @@ from skopt.space import Categorical, Dimension, Integer, Real import freqtrade.vendor.qtpylib.indicators as qtpylib from freqtrade.optimize.hyperopt_interface import IHyperOpt -# set TARGET_TRADES to suit your number concurrent trades so its realistic -# to the number of days -TARGET_TRADES = 600 -# This is assumed to be expected avg profit * expected trade count. -# For example, for 0.35% avg per trade (or 0.0035 as ratio) and 1100 trades, -# self.expected_max_profit = 3.85 -# Check that the reported Σ% values do not exceed this! -# Note, this is ratio. 3.85 stated above means 385Σ%. -EXPECTED_MAX_PROFIT = 3.0 - -# max average trade duration in minutes -# if eval ends with higher value, we consider it a failed eval -MAX_ACCEPTED_TRADE_DURATION = 300 - # This class is a sample. Feel free to customize it. class SampleHyperOpts(IHyperOpt):