add daily_profit_list
added extra key daily_profit in return of optimize_reports.generate_daily_stats this allows us to analyze and plot a daily profit chart / equity line using snippet below inside jupyter notebook ``` # 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 import plotly.express as px import pandas as pd # strategy = 'Strat' # config = Configuration.from_files(["user_data/config.json"]) # backtest_dir = config["user_data_dir"] / "backtest_results" stats = load_backtest_stats(backtest_dir) strategy_stats = stats['strategy'][strategy] equity = 0 equity_daily = [] for dp in strategy_stats['daily_profit']: equity_daily.append(equity) equity += float(dp) dates = pd.date_range(strategy_stats['backtest_start'], strategy_stats['backtest_end']) df = pd.DataFrame({'dates':dates,'equity_daily':equity_daily}) fig = px.line(df, x="dates", y="equity_daily") fig.show() ```
This commit is contained in:
parent
791dfd9ba3
commit
4aa2ae37bd
@ -261,6 +261,7 @@ def generate_daily_stats(results: DataFrame) -> Dict[str, Any]:
|
||||
'winning_days': 0,
|
||||
'draw_days': 0,
|
||||
'losing_days': 0,
|
||||
'daily_profit_list': [],
|
||||
}
|
||||
daily_profit_rel = results.resample('1d', on='close_date')['profit_ratio'].sum()
|
||||
daily_profit = results.resample('1d', on='close_date')['profit_abs'].sum().round(10)
|
||||
@ -271,6 +272,7 @@ def generate_daily_stats(results: DataFrame) -> Dict[str, Any]:
|
||||
winning_days = sum(daily_profit > 0)
|
||||
draw_days = sum(daily_profit == 0)
|
||||
losing_days = sum(daily_profit < 0)
|
||||
daily_profit_list = daily_profit.tolist()
|
||||
|
||||
return {
|
||||
'backtest_best_day': best_rel,
|
||||
@ -280,6 +282,7 @@ def generate_daily_stats(results: DataFrame) -> Dict[str, Any]:
|
||||
'winning_days': winning_days,
|
||||
'draw_days': draw_days,
|
||||
'losing_days': losing_days,
|
||||
'daily_profit': daily_profit_list,
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user