Skip to content

Commit

Permalink
Merge branch 'freqtrade:develop' into freqtrade-develop
Browse files Browse the repository at this point in the history
  • Loading branch information
stash86 authored Aug 18, 2024
2 parents 4acd410 + 624dfdf commit 9faa750
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
22 changes: 18 additions & 4 deletions freqtrade/optimize/analysis/recursive.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,27 @@
)
from freqtrade.optimize.backtesting import Backtesting
from freqtrade.optimize.base_analysis import BaseAnalysis, VarHolder
from freqtrade.resolvers import StrategyResolver


logger = logging.getLogger(__name__)


class RecursiveAnalysis(BaseAnalysis):
def __init__(self, config: Dict[str, Any], strategy_obj: Dict):
self._startup_candle = config.get("startup_candle", [199, 399, 499, 999, 1999])
self._startup_candle = list(
map(int, config.get("startup_candle", [199, 399, 499, 999, 1999]))
)

super().__init__(config, strategy_obj)

strat = StrategyResolver.load_strategy(config)
self._strat_scc = strat.startup_candle_count

if self._strat_scc not in self._startup_candle:
self._startup_candle.append(self._strat_scc)
self._startup_candle.sort()

self.partial_varHolder_array: List[VarHolder] = []
self.partial_varHolder_lookahead_array: List[VarHolder] = []

Expand Down Expand Up @@ -58,9 +68,13 @@ def analyze_indicators(self):
values_diff = compare_df.loc[indicator]
values_diff_self = values_diff.loc["self"]
values_diff_other = values_diff.loc["other"]
diff = (values_diff_other - values_diff_self) / values_diff_self * 100

self.dict_recursive[indicator][part.startup_candle] = f"{diff:.3f}%"
if values_diff_self and values_diff_other:
diff = (values_diff_other - values_diff_self) / values_diff_self * 100
str_diff = f"{diff:.3f}%"
else:
str_diff = "NaN"
self.dict_recursive[indicator][part.startup_candle] = str_diff

else:
logger.info("No variance on indicator(s) found due to recursive formula.")
Expand Down Expand Up @@ -174,7 +188,7 @@ def start(self) -> None:
start_date_partial = end_date_full - timedelta(minutes=int(timeframe_minutes))

for startup_candle in self._startup_candle:
self.fill_partial_varholder(start_date_partial, int(startup_candle))
self.fill_partial_varholder(start_date_partial, startup_candle)

# Restore verbosity, so it's not too quiet for the next strategy
restore_verbosity_for_bias_tester()
Expand Down
6 changes: 5 additions & 1 deletion freqtrade/optimize/analysis/recursive_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ class RecursiveAnalysisSubFunctions:
@staticmethod
def text_table_recursive_analysis_instances(recursive_instances: List[RecursiveAnalysis]):
startups = recursive_instances[0]._startup_candle
strat_scc = recursive_instances[0]._strat_scc
headers = ["Indicators"]
for candle in startups:
headers.append(str(candle))
if candle == strat_scc:
headers.append(f"{candle} (from strategy)")
else:
headers.append(str(candle))

data = []
for inst in recursive_instances:
Expand Down

0 comments on commit 9faa750

Please sign in to comment.