From 97275f5a466d30108a85487a0ab850d0ae4025e4 Mon Sep 17 00:00:00 2001 From: Mohsen <59406034+mohsenjfar@users.noreply.github.com> Date: Thu, 7 Sep 2023 17:18:43 +0330 Subject: [PATCH 1/2] Update strategy_analysis_example.md A better approach to calculate equity and equity_daily --- docs/strategy_analysis_example.md | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/docs/strategy_analysis_example.md b/docs/strategy_analysis_example.md index 06dd33bc2..d0883de8f 100644 --- a/docs/strategy_analysis_example.md +++ b/docs/strategy_analysis_example.md @@ -178,20 +178,8 @@ 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 daily_profit in profits: - equity_daily.append(equity) - equity += float(daily_profit) - - -df = pd.DataFrame({'dates': dates,'equity_daily': equity_daily}) +df = pd.DataFrame(columns=['dates','equity'], data=strategy_stats['daily_profit']) +df['equity_daily'] = df['equity'].cumsum() fig = px.line(df, x="dates", y="equity_daily") fig.show() From f13e134e9b2ca0b76dcc6b0a48570a3191bc54be Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 8 Sep 2023 06:47:31 +0200 Subject: [PATCH 2/2] Update actual notebook (not just the docs) --- docs/strategy_analysis_example.md | 2 +- .../templates/strategy_analysis_example.ipynb | 20 ++++--------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/docs/strategy_analysis_example.md b/docs/strategy_analysis_example.md index d0883de8f..846c53238 100644 --- a/docs/strategy_analysis_example.md +++ b/docs/strategy_analysis_example.md @@ -167,7 +167,7 @@ trades.groupby("pair")["exit_reason"].value_counts() # Plotting equity line (starting with 0 on day 1 and adding daily profit for each backtested day) from freqtrade.configuration import Configuration -from freqtrade.data.btanalysis import load_backtest_data, load_backtest_stats +from freqtrade.data.btanalysis import load_backtest_stats import plotly.express as px import pandas as pd diff --git a/freqtrade/templates/strategy_analysis_example.ipynb b/freqtrade/templates/strategy_analysis_example.ipynb index 2bfa4155d..0b30dbd54 100644 --- a/freqtrade/templates/strategy_analysis_example.ipynb +++ b/freqtrade/templates/strategy_analysis_example.ipynb @@ -243,7 +243,7 @@ "# Plotting equity line (starting with 0 on day 1 and adding daily profit for each backtested day)\n", "\n", "from freqtrade.configuration import Configuration\n", - "from freqtrade.data.btanalysis import load_backtest_data, load_backtest_stats\n", + "from freqtrade.data.btanalysis import load_backtest_stats\n", "import plotly.express as px\n", "import pandas as pd\n", "\n", @@ -254,20 +254,8 @@ "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 daily_profit in profits:\n", - " equity_daily.append(equity)\n", - " equity += float(daily_profit)\n", - "\n", - "\n", - "df = pd.DataFrame({'dates': dates,'equity_daily': equity_daily})\n", + "df = pd.DataFrame(columns=['dates','equity'], data=strategy_stats['daily_profit'])\n", + "df['equity_daily'] = df['equity'].cumsum()\n", "\n", "fig = px.line(df, x=\"dates\", y=\"equity_daily\")\n", "fig.show()\n" @@ -414,7 +402,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.7" + "version": "3.11.4" }, "mimetype": "text/x-python", "name": "python",