stable/freqtrade/commands/strategy_utils_commands.py
hippocritical 5edcf4c2ef first version of the backtest lookahead bias tester.
Putting this out there so matthias can comment on if he doesnt like something.
Plan:
- make variables adaptive like timerange and max_try_signals
- create a proper list of results at the end of a --strategy-list run
- output to specified .csv-file ('cause I am using that currently myself for the grafana server and so others can have a list of that too for later use or sharing things)
- tests
- docs

Current command which is tested with is as follows:
backtest_lookahead_bias_checker
--config=user_data/configs_backtest/config_baseline.json
--config=user_data/pairlists/binance_spot/USDT/monthly/monthly_90_USDT_0,01_minprice_20220901.json
--strategy-list=A1
--timeframe=5m
2023-03-12 20:13:05 +01:00

104 lines
3.9 KiB
Python

import logging
import sys
import time
from pathlib import Path
from typing import Any, Dict
from freqtrade.configuration import setup_utils_configuration
from freqtrade.enums import RunMode
from freqtrade.resolvers import StrategyResolver
from freqtrade.strategy.backtest_lookahead_bias_checker import backtest_lookahead_bias_checker
from freqtrade.strategy.strategyupdater import StrategyUpdater
logger = logging.getLogger(__name__)
def start_strategy_update(args: Dict[str, Any]) -> None:
"""
Start the strategy updating script
:param args: Cli args from Arguments()
:return: None
"""
if sys.version_info == (3, 8): # pragma: no cover
sys.exit("Freqtrade strategy updater requires Python version >= 3.9")
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
strategy_objs = StrategyResolver.search_all_objects(
config, enum_failed=False, recursive=config.get('recursive_strategy_search', False))
filtered_strategy_objs = []
if 'strategy_list' in args:
for args_strategy in args['strategy_list']:
for strategy_obj in strategy_objs:
if (strategy_obj['name'] == args_strategy
and strategy_obj not in filtered_strategy_objs):
filtered_strategy_objs.append(strategy_obj)
break
for filtered_strategy_obj in filtered_strategy_objs:
start_conversion(filtered_strategy_obj, config)
else:
processed_locations = set()
for strategy_obj in strategy_objs:
if strategy_obj['location'] not in processed_locations:
processed_locations.add(strategy_obj['location'])
start_conversion(strategy_obj, config)
def start_conversion(strategy_obj, config):
# try:
print(f"Conversion of {Path(strategy_obj['location']).name} started.")
instance_strategy_updater = StrategyUpdater()
start = time.perf_counter()
instance_strategy_updater.start(config, strategy_obj)
elapsed = time.perf_counter() - start
print(f"Conversion of {Path(strategy_obj['location']).name} took {elapsed:.1f} seconds.")
# except:
# pass
def start_backtest_lookahead_bias_checker(args: Dict[str, Any]) -> None:
"""
Start the backtest bias tester script
:param args: Cli args from Arguments()
:return: None
"""
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
strategy_objs = StrategyResolver.search_all_objects(
config, enum_failed=False, recursive=config.get('recursive_strategy_search', False))
filtered_strategy_objs = []
if 'strategy_list' in args and args['strategy_list'] is not None:
for args_strategy in args['strategy_list']:
for strategy_obj in strategy_objs:
if (strategy_obj['name'] == args_strategy
and strategy_obj not in filtered_strategy_objs):
filtered_strategy_objs.append(strategy_obj)
break
for filtered_strategy_obj in filtered_strategy_objs:
initialize_single_lookahead_bias_checker(filtered_strategy_obj, config)
else:
processed_locations = set()
for strategy_obj in strategy_objs:
if strategy_obj['location'] not in processed_locations:
processed_locations.add(strategy_obj['location'])
initialize_single_lookahead_bias_checker(strategy_obj, config)
def initialize_single_lookahead_bias_checker(strategy_obj, config):
# try:
print(f"Bias test of {Path(strategy_obj['location']).name} started.")
instance_backtest_lookahead_bias_checker = backtest_lookahead_bias_checker()
start = time.perf_counter()
instance_backtest_lookahead_bias_checker.start(config, strategy_obj)
elapsed = time.perf_counter() - start
print(f"checking look ahead bias via backtests of {Path(strategy_obj['location']).name} "
f"took {elapsed:.1f} seconds.")
# except:
# pass