feat: use get_dry_run_wallet helper

This commit is contained in:
Matthias
2024-12-03 07:27:45 +01:00
parent c082e5f6a6
commit 7a8971b9b6
10 changed files with 20 additions and 12 deletions
+2 -1
View File
@@ -4,6 +4,7 @@ from typing import Any
from freqtrade import constants from freqtrade import constants
from freqtrade.enums import RunMode from freqtrade.enums import RunMode
from freqtrade.exceptions import ConfigurationError, OperationalException from freqtrade.exceptions import ConfigurationError, OperationalException
from freqtrade.util import get_dry_run_wallet
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -26,7 +27,7 @@ def setup_optimize_configuration(args: dict[str, Any], method: RunMode) -> dict[
RunMode.HYPEROPT: "hyperoptimization", RunMode.HYPEROPT: "hyperoptimization",
} }
if method in no_unlimited_runmodes.keys(): if method in no_unlimited_runmodes.keys():
wallet_size = config["dry_run_wallet"] * config["tradable_balance_ratio"] wallet_size = get_dry_run_wallet(config) * config["tradable_balance_ratio"]
# tradable_balance_ratio # tradable_balance_ratio
if ( if (
config["stake_amount"] != constants.UNLIMITED_STAKE_AMOUNT config["stake_amount"] != constants.UNLIMITED_STAKE_AMOUNT
@@ -10,7 +10,7 @@ from freqtrade.constants import Config
from freqtrade.exceptions import OperationalException from freqtrade.exceptions import OperationalException
from freqtrade.optimize.analysis.lookahead import LookaheadAnalysis from freqtrade.optimize.analysis.lookahead import LookaheadAnalysis
from freqtrade.resolvers import StrategyResolver from freqtrade.resolvers import StrategyResolver
from freqtrade.util import print_rich_table from freqtrade.util import get_dry_run_wallet, print_rich_table
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -163,7 +163,7 @@ class LookaheadAnalysisSubFunctions:
config["max_open_trades"] = len(config["pairs"]) config["max_open_trades"] = len(config["pairs"])
min_dry_run_wallet = 1000000000 min_dry_run_wallet = 1000000000
if config["dry_run_wallet"] < min_dry_run_wallet: if get_dry_run_wallet(config) < min_dry_run_wallet:
logger.info( logger.info(
"Dry run wallet was not set to 1 billion, pushing it up there " "Dry run wallet was not set to 1 billion, pushing it up there "
"just to avoid false positives" "just to avoid false positives"
@@ -12,6 +12,7 @@ from pandas import DataFrame
from freqtrade.constants import Config from freqtrade.constants import Config
from freqtrade.data.metrics import calculate_calmar from freqtrade.data.metrics import calculate_calmar
from freqtrade.optimize.hyperopt import IHyperOptLoss from freqtrade.optimize.hyperopt import IHyperOptLoss
from freqtrade.util import get_dry_run_wallet
class CalmarHyperOptLoss(IHyperOptLoss): class CalmarHyperOptLoss(IHyperOptLoss):
@@ -36,7 +37,7 @@ class CalmarHyperOptLoss(IHyperOptLoss):
Uses Calmar Ratio calculation. Uses Calmar Ratio calculation.
""" """
starting_balance = config["dry_run_wallet"] starting_balance = get_dry_run_wallet(config)
calmar_ratio = calculate_calmar(results, min_date, max_date, starting_balance) calmar_ratio = calculate_calmar(results, min_date, max_date, starting_balance)
# print(expected_returns_mean, max_drawdown, calmar_ratio) # print(expected_returns_mean, max_drawdown, calmar_ratio)
return -calmar_ratio return -calmar_ratio
@@ -10,6 +10,7 @@ from pandas import DataFrame
from freqtrade.constants import Config from freqtrade.constants import Config
from freqtrade.data.metrics import calculate_underwater from freqtrade.data.metrics import calculate_underwater
from freqtrade.optimize.hyperopt import IHyperOptLoss from freqtrade.optimize.hyperopt import IHyperOptLoss
from freqtrade.util import get_dry_run_wallet
class MaxDrawDownRelativeHyperOptLoss(IHyperOptLoss): class MaxDrawDownRelativeHyperOptLoss(IHyperOptLoss):
@@ -31,7 +32,7 @@ class MaxDrawDownRelativeHyperOptLoss(IHyperOptLoss):
total_profit = results["profit_abs"].sum() total_profit = results["profit_abs"].sum()
try: try:
drawdown_df = calculate_underwater( drawdown_df = calculate_underwater(
results, value_col="profit_abs", starting_balance=config["dry_run_wallet"] results, value_col="profit_abs", starting_balance=get_dry_run_wallet(config)
) )
max_drawdown = abs(min(drawdown_df["drawdown"])) max_drawdown = abs(min(drawdown_df["drawdown"]))
relative_drawdown = max(drawdown_df["drawdown_relative"]) relative_drawdown = max(drawdown_df["drawdown_relative"])
@@ -36,6 +36,7 @@ from pandas import DataFrame
from freqtrade.constants import Config from freqtrade.constants import Config
from freqtrade.data.metrics import calculate_expectancy, calculate_max_drawdown from freqtrade.data.metrics import calculate_expectancy, calculate_max_drawdown
from freqtrade.optimize.hyperopt import IHyperOptLoss from freqtrade.optimize.hyperopt import IHyperOptLoss
from freqtrade.util import get_dry_run_wallet
# smaller numbers penalize drawdowns more severely # smaller numbers penalize drawdowns more severely
@@ -83,7 +84,7 @@ class MultiMetricHyperOptLoss(IHyperOptLoss):
# Calculate drawdown # Calculate drawdown
try: try:
drawdown = calculate_max_drawdown( drawdown = calculate_max_drawdown(
results, starting_balance=config["dry_run_wallet"], value_col="profit_abs" results, starting_balance=get_dry_run_wallet(config), value_col="profit_abs"
) )
relative_account_drawdown = drawdown.relative_account_drawdown relative_account_drawdown = drawdown.relative_account_drawdown
except ValueError: except ValueError:
@@ -13,6 +13,7 @@ from pandas import DataFrame
from freqtrade.constants import Config from freqtrade.constants import Config
from freqtrade.data.metrics import calculate_max_drawdown from freqtrade.data.metrics import calculate_max_drawdown
from freqtrade.optimize.hyperopt import IHyperOptLoss from freqtrade.optimize.hyperopt import IHyperOptLoss
from freqtrade.util import get_dry_run_wallet
# smaller numbers penalize drawdowns more severely # smaller numbers penalize drawdowns more severely
@@ -26,7 +27,7 @@ class ProfitDrawDownHyperOptLoss(IHyperOptLoss):
try: try:
drawdown = calculate_max_drawdown( drawdown = calculate_max_drawdown(
results, starting_balance=config["dry_run_wallet"], value_col="profit_abs" results, starting_balance=get_dry_run_wallet(config), value_col="profit_abs"
) )
relative_account_drawdown = drawdown.relative_account_drawdown relative_account_drawdown = drawdown.relative_account_drawdown
except ValueError: except ValueError:
@@ -12,6 +12,7 @@ from pandas import DataFrame
from freqtrade.constants import Config from freqtrade.constants import Config
from freqtrade.data.metrics import calculate_sharpe from freqtrade.data.metrics import calculate_sharpe
from freqtrade.optimize.hyperopt import IHyperOptLoss from freqtrade.optimize.hyperopt import IHyperOptLoss
from freqtrade.util.dry_run_wallet import get_dry_run_wallet
class SharpeHyperOptLoss(IHyperOptLoss): class SharpeHyperOptLoss(IHyperOptLoss):
@@ -36,7 +37,7 @@ class SharpeHyperOptLoss(IHyperOptLoss):
Uses Sharpe Ratio calculation. Uses Sharpe Ratio calculation.
""" """
starting_balance = config["dry_run_wallet"] starting_balance = get_dry_run_wallet(config)
sharp_ratio = calculate_sharpe(results, min_date, max_date, starting_balance) sharp_ratio = calculate_sharpe(results, min_date, max_date, starting_balance)
# print(expected_returns_mean, up_stdev, sharp_ratio) # print(expected_returns_mean, up_stdev, sharp_ratio)
return -sharp_ratio return -sharp_ratio
@@ -12,6 +12,7 @@ from pandas import DataFrame
from freqtrade.constants import Config from freqtrade.constants import Config
from freqtrade.data.metrics import calculate_sortino from freqtrade.data.metrics import calculate_sortino
from freqtrade.optimize.hyperopt import IHyperOptLoss from freqtrade.optimize.hyperopt import IHyperOptLoss
from freqtrade.util import get_dry_run_wallet
class SortinoHyperOptLoss(IHyperOptLoss): class SortinoHyperOptLoss(IHyperOptLoss):
@@ -36,7 +37,7 @@ class SortinoHyperOptLoss(IHyperOptLoss):
Uses Sortino Ratio calculation. Uses Sortino Ratio calculation.
""" """
starting_balance = config["dry_run_wallet"] starting_balance = get_dry_run_wallet(config)
sortino_ratio = calculate_sortino(results, min_date, max_date, starting_balance) sortino_ratio = calculate_sortino(results, min_date, max_date, starting_balance)
# print(expected_returns_mean, down_stdev, sortino_ratio) # print(expected_returns_mean, down_stdev, sortino_ratio)
return -sortino_ratio return -sortino_ratio
@@ -18,7 +18,7 @@ from freqtrade.data.metrics import (
calculate_sortino, calculate_sortino,
) )
from freqtrade.ft_types import BacktestResultType from freqtrade.ft_types import BacktestResultType
from freqtrade.util import decimals_per_coin, fmt_coin from freqtrade.util import decimals_per_coin, fmt_coin, get_dry_run_wallet
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -373,7 +373,7 @@ def generate_strategy_stats(
return {} return {}
config = content["config"] config = content["config"]
max_open_trades = min(config["max_open_trades"], len(pairlist)) max_open_trades = min(config["max_open_trades"], len(pairlist))
start_balance = config["dry_run_wallet"] start_balance = get_dry_run_wallet(config)
stake_currency = config["stake_currency"] stake_currency = config["stake_currency"]
pair_results = generate_pair_metrics( pair_results = generate_pair_metrics(
+2 -1
View File
@@ -28,6 +28,7 @@ from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist
from freqtrade.resolvers import ExchangeResolver, StrategyResolver from freqtrade.resolvers import ExchangeResolver, StrategyResolver
from freqtrade.strategy import IStrategy from freqtrade.strategy import IStrategy
from freqtrade.strategy.strategy_wrapper import strategy_safe_wrapper from freqtrade.strategy.strategy_wrapper import strategy_safe_wrapper
from freqtrade.util import get_dry_run_wallet
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -706,7 +707,7 @@ def plot_profit(config: Config) -> None:
trades, trades,
config["timeframe"], config["timeframe"],
config.get("stake_currency", ""), config.get("stake_currency", ""),
config.get("available_capital", config["dry_run_wallet"]), config.get("available_capital", get_dry_run_wallet(config)),
) )
store_plot_file( store_plot_file(
fig, fig,