From d1104bd434e4c60ba3d7f2582c093a0027c65af0 Mon Sep 17 00:00:00 2001 From: octaviusgus Date: Tue, 6 Jul 2021 22:47:39 +0200 Subject: [PATCH 1/2] fix daily profit data and daily profit curve example --- freqtrade/optimize/optimize_reports.py | 2 +- freqtrade/templates/strategy_analysis_example.ipynb | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/freqtrade/optimize/optimize_reports.py b/freqtrade/optimize/optimize_reports.py index 89cf70437..5dc8554c4 100644 --- a/freqtrade/optimize/optimize_reports.py +++ b/freqtrade/optimize/optimize_reports.py @@ -272,7 +272,7 @@ def generate_daily_stats(results: DataFrame) -> Dict[str, Any]: winning_days = sum(daily_profit > 0) draw_days = sum(daily_profit == 0) losing_days = sum(daily_profit < 0) - daily_profit_list = daily_profit.tolist() + daily_profit_list = [(str(idx.date()), val) for idx, val in daily_profit.iteritems()] return { 'backtest_best_day': best_rel, diff --git a/freqtrade/templates/strategy_analysis_example.ipynb b/freqtrade/templates/strategy_analysis_example.ipynb index f3b0d8d03..99720ae6e 100644 --- a/freqtrade/templates/strategy_analysis_example.ipynb +++ b/freqtrade/templates/strategy_analysis_example.ipynb @@ -215,13 +215,18 @@ "stats = load_backtest_stats(backtest_dir)\n", "strategy_stats = stats['strategy'][strategy]\n", "\n", + "dates = []\n", + "profits = []\n", + "for date_profit in strategy_stats['daily_profit']:\n", + " dates.append(date_profit[0])\n", + " profits.append(date_profit[1])\n", + "\n", "equity = 0\n", "equity_daily = []\n", - "for dp in strategy_stats['daily_profit']:\n", + "for daily_profit in profits:\n", " equity_daily.append(equity)\n", - " equity += float(dp)\n", + " equity += float(daily_profit)\n", "\n", - "dates = pd.date_range(strategy_stats['backtest_start'], strategy_stats['backtest_end'])\n", "\n", "df = pd.DataFrame({'dates': dates,'equity_daily': equity_daily})\n", "\n", From 03861945a39af7441f8898f00bf7416f11f7d7ca Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 8 Jul 2021 20:04:47 +0200 Subject: [PATCH 2/2] Update documentation page too. --- docs/strategy_analysis_example.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/strategy_analysis_example.md b/docs/strategy_analysis_example.md index 27c620c3d..27192aa2f 100644 --- a/docs/strategy_analysis_example.md +++ b/docs/strategy_analysis_example.md @@ -148,13 +148,18 @@ import pandas as pd stats = load_backtest_stats(backtest_dir) strategy_stats = stats['strategy'][strategy] +dates = [] +profits = [] +for date_profit in strategy_stats['daily_profit']: + dates.append(date_profit[0]) + profits.append(date_profit[1]) + equity = 0 equity_daily = [] -for dp in strategy_stats['daily_profit']: +for daily_profit in profits: equity_daily.append(equity) - equity += float(dp) + equity += float(daily_profit) -dates = pd.date_range(strategy_stats['backtest_start'], strategy_stats['backtest_end']) df = pd.DataFrame({'dates': dates,'equity_daily': equity_daily})