Test generate_profit_plot

This commit is contained in:
Matthias 2019-06-30 10:47:55 +02:00
parent c7a4a16eec
commit 587d71efb5
3 changed files with 38 additions and 4 deletions

View File

@ -276,6 +276,7 @@ def generate_profit_graph(pairs: str, tickers: Dict[str, pd.DataFrame], trades:
) )
fig = tools.make_subplots(rows=3, cols=1, shared_xaxes=True, row_width=[1, 1, 1]) fig = tools.make_subplots(rows=3, cols=1, shared_xaxes=True, row_width=[1, 1, 1])
fig['layout'].update(title="Profit plot")
fig.append_trace(avgclose, 1, 1) fig.append_trace(avgclose, 1, 1)
fig = add_profit(fig, 2, df_comb, 'cum_profit', 'Profit') fig = add_profit(fig, 2, df_comb, 'cum_profit', 'Profit')
@ -286,7 +287,7 @@ def generate_profit_graph(pairs: str, tickers: Dict[str, pd.DataFrame], trades:
fig = add_profit(fig, 3, df_comb, profit_col, f"Profit {pair}") fig = add_profit(fig, 3, df_comb, profit_col, f"Profit {pair}")
store_plot_file(fig, filename='freqtrade-profit-plot.html', auto_open=True) return fig
def generate_plot_filename(pair, ticker_interval) -> str: def generate_plot_filename(pair, ticker_interval) -> str:

View File

@ -10,7 +10,8 @@ from freqtrade.data import history
from freqtrade.data.btanalysis import create_cum_profit, load_backtest_data from freqtrade.data.btanalysis import create_cum_profit, load_backtest_data
from freqtrade.plot.plotting import (add_indicators, add_profit, from freqtrade.plot.plotting import (add_indicators, add_profit,
generate_candlestick_graph, generate_candlestick_graph,
generate_plot_filename, plot_trades, generate_plot_filename,
generate_profit_graph, plot_trades,
store_plot_file) store_plot_file)
from freqtrade.strategy.default_strategy import DefaultStrategy from freqtrade.strategy.default_strategy import DefaultStrategy
from freqtrade.tests.conftest import log_has, log_has_re from freqtrade.tests.conftest import log_has, log_has_re
@ -214,3 +215,34 @@ def test_add_profit():
profits = find_trace_in_fig_data(figure.data, "Profits") profits = find_trace_in_fig_data(figure.data, "Profits")
assert isinstance(profits, go.Scattergl) assert isinstance(profits, go.Scattergl)
assert profits.yaxis == "y2" assert profits.yaxis == "y2"
def test_generate_profit_graph():
filename = history.make_testdata_path(None) / "backtest-result_test.json"
trades = load_backtest_data(filename)
timerange = Arguments.parse_timerange("20180110-20180112")
pairs = ["POWR/BTC", "XLM/BTC"]
tickers = history.load_data(datadir=None,
pairs=pairs,
ticker_interval='5m',
timerange=timerange
)
trades = trades[trades['pair'].isin(pairs)]
fig = generate_profit_graph(pairs, tickers, trades)
assert isinstance(fig, go.Figure)
assert fig.layout.title.text == "Profit plot"
figure = fig.layout.figure
assert len(figure.data) == 4
avgclose = find_trace_in_fig_data(figure.data, "Avg close price")
assert isinstance(avgclose, go.Scattergl)
profit = find_trace_in_fig_data(figure.data, "Profit")
assert isinstance(profit, go.Scattergl)
for pair in pairs:
profit_pair = find_trace_in_fig_data(figure.data, f"Profit {pair}")
assert isinstance(profit_pair, go.Scattergl)

View File

@ -10,7 +10,7 @@ from typing import Any, Dict, List
from freqtrade.arguments import ARGS_PLOT_PROFIT, Arguments from freqtrade.arguments import ARGS_PLOT_PROFIT, Arguments
from freqtrade.optimize import setup_configuration from freqtrade.optimize import setup_configuration
from freqtrade.plot.plotting import FTPlots, generate_profit_graph from freqtrade.plot.plotting import FTPlots, generate_profit_graph, store_plot_file
from freqtrade.state import RunMode from freqtrade.state import RunMode
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -29,7 +29,8 @@ def plot_profit(config: Dict[str, Any]) -> None:
# Create an average close price of all the pairs that were involved. # Create an average close price of all the pairs that were involved.
# this could be useful to gauge the overall market trend # this could be useful to gauge the overall market trend
generate_profit_graph(plot.pairs, plot.tickers, trades) fig = generate_profit_graph(plot.pairs, plot.tickers, trades)
store_plot_file(fig, filename='freqtrade-profit-plot.html', auto_open=True)
def plot_parse_args(args: List[str]) -> Dict[str, Any]: def plot_parse_args(args: List[str]) -> Dict[str, Any]: