Create generate_plot_graph
This commit is contained in:
parent
0b517584aa
commit
c7a4a16eec
@ -5,9 +5,10 @@ from typing import Any, Dict, List, Optional
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
from freqtrade.arguments import Arguments
|
from freqtrade.arguments import Arguments
|
||||||
from freqtrade.exchange import Exchange
|
|
||||||
from freqtrade.data import history
|
from freqtrade.data import history
|
||||||
from freqtrade.data.btanalysis import load_trades
|
from freqtrade.data.btanalysis import (combine_tickers_with_mean,
|
||||||
|
create_cum_profit, load_trades)
|
||||||
|
from freqtrade.exchange import Exchange
|
||||||
from freqtrade.resolvers import ExchangeResolver, StrategyResolver
|
from freqtrade.resolvers import ExchangeResolver, StrategyResolver
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -28,6 +29,7 @@ class FTPlots():
|
|||||||
self._config = config
|
self._config = config
|
||||||
self.exchange: Optional[Exchange] = None
|
self.exchange: Optional[Exchange] = None
|
||||||
|
|
||||||
|
# Exchange is only needed when downloading data!
|
||||||
if self._config.get("live", False) or self._config.get("refresh_pairs", False):
|
if self._config.get("live", False) or self._config.get("refresh_pairs", False):
|
||||||
self.exchange = ExchangeResolver(self._config.get('exchange', {}).get('name'),
|
self.exchange = ExchangeResolver(self._config.get('exchange', {}).get('name'),
|
||||||
self._config).exchange
|
self._config).exchange
|
||||||
@ -258,6 +260,35 @@ def generate_candlestick_graph(pair: str, data: pd.DataFrame, trades: pd.DataFra
|
|||||||
return fig
|
return fig
|
||||||
|
|
||||||
|
|
||||||
|
def generate_profit_graph(pairs: str, tickers: Dict[str, pd.DataFrame], trades: pd.DataFrame = None,
|
||||||
|
) -> go.Figure:
|
||||||
|
# Combine close-values for all pairs, rename columns to "pair"
|
||||||
|
df_comb = combine_tickers_with_mean(tickers, "close")
|
||||||
|
|
||||||
|
# Add combined cumulative profit
|
||||||
|
df_comb = create_cum_profit(df_comb, trades, 'cum_profit')
|
||||||
|
|
||||||
|
# Plot the pairs average close prices, and total profit growth
|
||||||
|
avgclose = go.Scattergl(
|
||||||
|
x=df_comb.index,
|
||||||
|
y=df_comb['mean'],
|
||||||
|
name='Avg close price',
|
||||||
|
)
|
||||||
|
|
||||||
|
fig = tools.make_subplots(rows=3, cols=1, shared_xaxes=True, row_width=[1, 1, 1])
|
||||||
|
|
||||||
|
fig.append_trace(avgclose, 1, 1)
|
||||||
|
fig = add_profit(fig, 2, df_comb, 'cum_profit', 'Profit')
|
||||||
|
|
||||||
|
for pair in pairs:
|
||||||
|
profit_col = f'cum_profit_{pair}'
|
||||||
|
df_comb = create_cum_profit(df_comb, trades[trades['pair'] == pair], profit_col)
|
||||||
|
|
||||||
|
fig = add_profit(fig, 3, df_comb, profit_col, f"Profit {pair}")
|
||||||
|
|
||||||
|
store_plot_file(fig, filename='freqtrade-profit-plot.html', auto_open=True)
|
||||||
|
|
||||||
|
|
||||||
def generate_plot_filename(pair, ticker_interval) -> str:
|
def generate_plot_filename(pair, ticker_interval) -> str:
|
||||||
"""
|
"""
|
||||||
Generate filenames per pair/ticker_interval to be used for storing plots
|
Generate filenames per pair/ticker_interval to be used for storing plots
|
||||||
|
@ -8,13 +8,9 @@ import logging
|
|||||||
import sys
|
import sys
|
||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List
|
||||||
|
|
||||||
import plotly.graph_objs as go
|
|
||||||
from plotly import tools
|
|
||||||
|
|
||||||
from freqtrade.arguments import ARGS_PLOT_PROFIT, Arguments
|
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.optimize import setup_configuration
|
||||||
from freqtrade.plot.plotting import FTPlots, store_plot_file, add_profit
|
from freqtrade.plot.plotting import FTPlots, generate_profit_graph
|
||||||
from freqtrade.state import RunMode
|
from freqtrade.state import RunMode
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -33,32 +29,7 @@ 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)
|
||||||
# Combine close-values for all pairs, rename columns to "pair"
|
|
||||||
df_comb = combine_tickers_with_mean(plot.tickers, "close")
|
|
||||||
|
|
||||||
# Add combined cumulative profit
|
|
||||||
df_comb = create_cum_profit(df_comb, trades, 'cum_profit')
|
|
||||||
|
|
||||||
# Plot the pairs average close prices, and total profit growth
|
|
||||||
avgclose = go.Scattergl(
|
|
||||||
x=df_comb.index,
|
|
||||||
y=df_comb['mean'],
|
|
||||||
name='Avg close price',
|
|
||||||
)
|
|
||||||
|
|
||||||
fig = tools.make_subplots(rows=3, cols=1, shared_xaxes=True, row_width=[1, 1, 1])
|
|
||||||
|
|
||||||
fig.append_trace(avgclose, 1, 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)
|
|
||||||
|
|
||||||
fig = add_profit(fig, 3, df_comb, profit_col, f"Profit {pair}")
|
|
||||||
|
|
||||||
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]:
|
||||||
|
Loading…
Reference in New Issue
Block a user