Merge branch 'freqtrade:develop' into optuna
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""Freqtrade bot"""
|
||||
|
||||
__version__ = "2025.3-dev"
|
||||
__version__ = "2025.4-dev"
|
||||
|
||||
if "dev" in __version__:
|
||||
from pathlib import Path
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,5 @@
|
||||
from typing import Any
|
||||
from copy import deepcopy
|
||||
from typing import Any, cast
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
@@ -15,11 +16,16 @@ class BacktestResultType(TypedDict):
|
||||
|
||||
|
||||
def get_BacktestResultType_default() -> BacktestResultType:
|
||||
return {
|
||||
"metadata": {},
|
||||
"strategy": {},
|
||||
"strategy_comparison": [],
|
||||
}
|
||||
return cast(
|
||||
BacktestResultType,
|
||||
deepcopy(
|
||||
{
|
||||
"metadata": {},
|
||||
"strategy": {},
|
||||
"strategy_comparison": [],
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class BacktestHistoryEntryType(BacktestMetadataType):
|
||||
|
||||
@@ -1792,6 +1792,7 @@ class Backtesting:
|
||||
dt_appendix,
|
||||
market_change_data=combined_res,
|
||||
analysis_results=self.analysis_results,
|
||||
strategy_files={s.get_strategy_name(): s.__file__ for s in self.strategylist},
|
||||
)
|
||||
|
||||
# Results may be mixed up now. Sort them so they follow --strategy-list order.
|
||||
|
||||
@@ -6,6 +6,7 @@ from zipfile import ZIP_DEFLATED, ZipFile
|
||||
|
||||
from pandas import DataFrame
|
||||
|
||||
from freqtrade.configuration import sanitize_config
|
||||
from freqtrade.constants import LAST_BT_RESULT_FN
|
||||
from freqtrade.enums.runmode import RunMode
|
||||
from freqtrade.ft_types import BacktestResultType
|
||||
@@ -52,6 +53,7 @@ def store_backtest_results(
|
||||
*,
|
||||
market_change_data: DataFrame | None = None,
|
||||
analysis_results: dict[str, dict[str, DataFrame]] | None = None,
|
||||
strategy_files: dict[str, str] | None = None,
|
||||
) -> Path:
|
||||
"""
|
||||
Stores backtest results and analysis data in a zip file, with metadata stored separately
|
||||
@@ -85,6 +87,32 @@ def store_backtest_results(
|
||||
dump_json_to_file(stats_buf, stats_copy)
|
||||
zipf.writestr(json_filename.name, stats_buf.getvalue())
|
||||
|
||||
config_buf = StringIO()
|
||||
dump_json_to_file(config_buf, sanitize_config(config["original_config"]))
|
||||
zipf.writestr(f"{base_filename.stem}_config.json", config_buf.getvalue())
|
||||
|
||||
for strategy_name, strategy_file in (strategy_files or {}).items():
|
||||
# Store the strategy file and its parameters
|
||||
strategy_buf = BytesIO()
|
||||
strategy_path = Path(strategy_file)
|
||||
if not strategy_path.is_file():
|
||||
logger.warning(f"Strategy file '{strategy_path}' does not exist. Skipping.")
|
||||
continue
|
||||
with strategy_path.open("rb") as strategy_file_obj:
|
||||
strategy_buf.write(strategy_file_obj.read())
|
||||
strategy_buf.seek(0)
|
||||
zipf.writestr(f"{base_filename.stem}_{strategy_name}.py", strategy_buf.getvalue())
|
||||
strategy_params = strategy_path.with_suffix(".json")
|
||||
if strategy_params.is_file():
|
||||
strategy_params_buf = BytesIO()
|
||||
with strategy_params.open("rb") as strategy_params_obj:
|
||||
strategy_params_buf.write(strategy_params_obj.read())
|
||||
strategy_params_buf.seek(0)
|
||||
zipf.writestr(
|
||||
f"{base_filename.stem}_{strategy_name}.json",
|
||||
strategy_params_buf.getvalue(),
|
||||
)
|
||||
|
||||
# Add market change data if present
|
||||
if market_change_data is not None:
|
||||
market_change_name = f"{base_filename.stem}_market_change.feather"
|
||||
|
||||
@@ -18,7 +18,7 @@ from freqtrade.data.metrics import (
|
||||
calculate_sortino,
|
||||
calculate_sqn,
|
||||
)
|
||||
from freqtrade.ft_types import BacktestResultType
|
||||
from freqtrade.ft_types import BacktestResultType, get_BacktestResultType_default
|
||||
from freqtrade.util import decimals_per_coin, fmt_coin, get_dry_run_wallet
|
||||
|
||||
|
||||
@@ -587,11 +587,7 @@ def generate_backtest_stats(
|
||||
:param max_date: Backtest end date
|
||||
:return: Dictionary containing results per strategy and a strategy summary.
|
||||
"""
|
||||
result: BacktestResultType = {
|
||||
"metadata": {},
|
||||
"strategy": {},
|
||||
"strategy_comparison": [],
|
||||
}
|
||||
result: BacktestResultType = get_BacktestResultType_default()
|
||||
market_change = calculate_market_change(btdata, "close")
|
||||
metadata = {}
|
||||
pairlist = list(btdata.keys())
|
||||
|
||||
@@ -108,6 +108,9 @@ def __run_backtest_bg(btconfig: Config):
|
||||
ApiBG.bt["bt"].results,
|
||||
datetime.now().strftime("%Y-%m-%d_%H-%M-%S"),
|
||||
market_change_data=combined_res,
|
||||
strategy_files={
|
||||
s.get_strategy_name(): s.__file__ for s in ApiBG.bt["bt"].strategylist
|
||||
},
|
||||
)
|
||||
ApiBG.bt["bt"].results["metadata"][strategy_name]["filename"] = str(fn.stem)
|
||||
ApiBG.bt["bt"].results["metadata"][strategy_name]["strategy"] = strategy_name
|
||||
|
||||
@@ -132,6 +132,7 @@ class IStrategy(ABC, HyperStrategyMixin):
|
||||
stake_currency: str
|
||||
# container variable for strategy source code
|
||||
__source__: str = ""
|
||||
__file__: str = ""
|
||||
|
||||
# Definition of plot_config. See plotting documentation for more details.
|
||||
plot_config: dict = {}
|
||||
|
||||
Reference in New Issue
Block a user