From 558bcc79592a459f45e1f8d4a44d526202d259e1 Mon Sep 17 00:00:00 2001 From: octaviusgus Date: Sun, 4 Jul 2021 15:56:55 +0200 Subject: [PATCH] Jupyter notebook snippet: Plotting daily profit / equity line --- .../templates/strategy_analysis_example.ipynb | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/freqtrade/templates/strategy_analysis_example.ipynb b/freqtrade/templates/strategy_analysis_example.ipynb index 0bc593e2d..9af24ae2d 100644 --- a/freqtrade/templates/strategy_analysis_example.ipynb +++ b/freqtrade/templates/strategy_analysis_example.ipynb @@ -188,6 +188,47 @@ "trades.groupby(\"pair\")[\"sell_reason\"].value_counts()" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Plotting daily profit / equity line" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "# 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", + "import plotly.express as px\n", + "import pandas as pd\n", + "\n", + "# strategy = 'SampleStrategy'\n", + "# config = Configuration.from_files([\"user_data/config.json\"])\n", + "# backtest_dir = config[\"user_data_dir\"] / \"backtest_results\"\n", + "\n", + "stats = load_backtest_stats(backtest_dir)\n", + "strategy_stats = stats['strategy'][strategy]\n", + "\n", + "equity = 0\n", + "equity_daily = []\n", + "for dp in strategy_stats['daily_profit']:\n", + " equity_daily.append(equity)\n", + " equity += float(dp)\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", + "fig = px.line(df, x=\"dates\", y=\"equity_daily\")\n", + "fig.show()\n" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -329,7 +370,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.8.5" }, "mimetype": "text/x-python", "name": "python",