Fix some assumptions on the data
available_capital is not guaranteed to be available, while dry-run-wallet is.
This commit is contained in:
parent
7160f9085a
commit
1e2523af61
@ -1,5 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import Dict, Optional, Tuple
|
from typing import Dict, Tuple
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
@ -73,7 +73,7 @@ def create_cum_profit(df: pd.DataFrame, trades: pd.DataFrame, col_name: str,
|
|||||||
|
|
||||||
|
|
||||||
def _calc_drawdown_series(profit_results: pd.DataFrame, *, date_col: str, value_col: str,
|
def _calc_drawdown_series(profit_results: pd.DataFrame, *, date_col: str, value_col: str,
|
||||||
starting_balance: Optional[float] = 0.0) -> pd.DataFrame:
|
starting_balance: float) -> pd.DataFrame:
|
||||||
max_drawdown_df = pd.DataFrame()
|
max_drawdown_df = pd.DataFrame()
|
||||||
max_drawdown_df['cumulative'] = profit_results[value_col].cumsum()
|
max_drawdown_df['cumulative'] = profit_results[value_col].cumsum()
|
||||||
max_drawdown_df['high_value'] = max_drawdown_df['cumulative'].cummax()
|
max_drawdown_df['high_value'] = max_drawdown_df['cumulative'].cummax()
|
||||||
@ -93,7 +93,7 @@ def _calc_drawdown_series(profit_results: pd.DataFrame, *, date_col: str, value_
|
|||||||
|
|
||||||
|
|
||||||
def calculate_underwater(trades: pd.DataFrame, *, date_col: str = 'close_date',
|
def calculate_underwater(trades: pd.DataFrame, *, date_col: str = 'close_date',
|
||||||
value_col: str = 'profit_ratio', starting_balance: Optional[float] = 0.0
|
value_col: str = 'profit_ratio', starting_balance: float = 0.0
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Calculate max drawdown and the corresponding close dates
|
Calculate max drawdown and the corresponding close dates
|
||||||
|
@ -36,7 +36,7 @@ class MaxDrawDownRelativeHyperOptLoss(IHyperOptLoss):
|
|||||||
drawdown_df = calculate_underwater(
|
drawdown_df = calculate_underwater(
|
||||||
results,
|
results,
|
||||||
value_col='profit_abs',
|
value_col='profit_abs',
|
||||||
starting_balance=config['available_capital']
|
starting_balance=config['dry_run_wallet']
|
||||||
)
|
)
|
||||||
max_drawdown = abs(min(drawdown_df['drawdown']))
|
max_drawdown = abs(min(drawdown_df['drawdown']))
|
||||||
relative_drawdown = max(drawdown_df['drawdown_relative'])
|
relative_drawdown = max(drawdown_df['drawdown_relative'])
|
||||||
|
@ -692,7 +692,8 @@ def plot_profit(config: Dict[str, Any]) -> None:
|
|||||||
# this could be useful to gauge the overall market trend
|
# this could be useful to gauge the overall market trend
|
||||||
fig = generate_profit_graph(plot_elements['pairs'], plot_elements['ohlcv'],
|
fig = generate_profit_graph(plot_elements['pairs'], plot_elements['ohlcv'],
|
||||||
trades, config['timeframe'],
|
trades, config['timeframe'],
|
||||||
config.get('stake_currency', ''), config['available_capital'])
|
config.get('stake_currency', ''),
|
||||||
|
config.get('available_capital', config['dry_run_wallet']))
|
||||||
store_plot_file(fig, filename='freqtrade-profit-plot.html',
|
store_plot_file(fig, filename='freqtrade-profit-plot.html',
|
||||||
directory=config['user_data_dir'] / 'plot',
|
directory=config['user_data_dir'] / 'plot',
|
||||||
auto_open=config.get('plot_auto_open', False))
|
auto_open=config.get('plot_auto_open', False))
|
||||||
|
@ -454,7 +454,6 @@ def test_plot_profit(default_conf, mocker, testdatadir):
|
|||||||
default_conf['datadir'] = testdatadir
|
default_conf['datadir'] = testdatadir
|
||||||
default_conf['exportfilename'] = testdatadir / 'backtest-result_test_nofile.json'
|
default_conf['exportfilename'] = testdatadir / 'backtest-result_test_nofile.json'
|
||||||
default_conf['pairs'] = ['ETH/BTC', 'LTC/BTC']
|
default_conf['pairs'] = ['ETH/BTC', 'LTC/BTC']
|
||||||
default_conf['available_capital'] = 1000
|
|
||||||
|
|
||||||
profit_mock = MagicMock()
|
profit_mock = MagicMock()
|
||||||
store_mock = MagicMock()
|
store_mock = MagicMock()
|
||||||
|
Loading…
Reference in New Issue
Block a user