From 0b517584aacc12d9c1b054b77c29a52633c9b3b8 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 30 Jun 2019 10:25:48 +0200 Subject: [PATCH] Use add_profit in script --- freqtrade/plot/plotting.py | 2 +- freqtrade/tests/test_plotting.py | 12 ++++++------ scripts/plot_profit.py | 18 +++--------------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/freqtrade/plot/plotting.py b/freqtrade/plot/plotting.py index f8736fe74..4c45c0375 100644 --- a/freqtrade/plot/plotting.py +++ b/freqtrade/plot/plotting.py @@ -7,7 +7,7 @@ import pandas as pd from freqtrade.arguments import Arguments from freqtrade.exchange import Exchange from freqtrade.data import history -from freqtrade.data.btanalysis import load_trades, create_cum_profit +from freqtrade.data.btanalysis import load_trades from freqtrade.resolvers import ExchangeResolver, StrategyResolver logger = logging.getLogger(__name__) diff --git a/freqtrade/tests/test_plotting.py b/freqtrade/tests/test_plotting.py index 2a73ad24e..fb2c52e1e 100644 --- a/freqtrade/tests/test_plotting.py +++ b/freqtrade/tests/test_plotting.py @@ -5,13 +5,13 @@ from unittest.mock import MagicMock import plotly.graph_objs as go from plotly import tools -from freqtrade.arguments import TimeRange, Arguments +from freqtrade.arguments import Arguments, TimeRange from freqtrade.data import history -from freqtrade.data.btanalysis import load_backtest_data, create_cum_profit -from freqtrade.plot.plotting import (generate_candlestick_graph, - store_plot_file, add_profit, - generate_plot_filename, add_indicators, - plot_trades) +from freqtrade.data.btanalysis import create_cum_profit, load_backtest_data +from freqtrade.plot.plotting import (add_indicators, add_profit, + generate_candlestick_graph, + generate_plot_filename, plot_trades, + store_plot_file) from freqtrade.strategy.default_strategy import DefaultStrategy from freqtrade.tests.conftest import log_has, log_has_re diff --git a/scripts/plot_profit.py b/scripts/plot_profit.py index 248eeb7b0..ad135b5e6 100755 --- a/scripts/plot_profit.py +++ b/scripts/plot_profit.py @@ -8,14 +8,13 @@ import logging import sys from typing import Any, Dict, List -import pandas as pd import plotly.graph_objs as go from plotly import tools from freqtrade.arguments import ARGS_PLOT_PROFIT, Arguments from freqtrade.data.btanalysis import create_cum_profit, combine_tickers_with_mean from freqtrade.optimize import setup_configuration -from freqtrade.plot.plotting import FTPlots, store_plot_file +from freqtrade.plot.plotting import FTPlots, store_plot_file, add_profit from freqtrade.state import RunMode logger = logging.getLogger(__name__) @@ -48,27 +47,16 @@ def plot_profit(config: Dict[str, Any]) -> None: name='Avg close price', ) - profit = go.Scattergl( - x=df_comb.index, - y=df_comb['cum_profit'], - name='Profit', - ) - fig = tools.make_subplots(rows=3, cols=1, shared_xaxes=True, row_width=[1, 1, 1]) fig.append_trace(avgclose, 1, 1) - fig.append_trace(profit, 2, 1) + fig = add_profit(fig, 2, df_comb, 'cum_profit', 'Profit') for pair in plot.pairs: profit_col = f'cum_profit_{pair}' df_comb = create_cum_profit(df_comb, trades[trades['pair'] == pair], profit_col) - pair_profit = go.Scattergl( - x=df_comb.index, - y=df_comb[profit_col], - name=f"Profit {pair}", - ) - fig.append_trace(pair_profit, 3, 1) + fig = add_profit(fig, 3, df_comb, profit_col, f"Profit {pair}") store_plot_file(fig, filename='freqtrade-profit-plot.html', auto_open=True)