Update notebook with new statistics example
This commit is contained in:
		| @@ -285,7 +285,7 @@ Examples: | ||||
| Use custom backtest-export file | ||||
|  | ||||
| ``` bash | ||||
| freqtrade plot-profit  -p LTC/BTC --export-filename user_data/backtest_results/backtest-result-Strategy005.json | ||||
| freqtrade plot-profit  -p LTC/BTC --export-filename user_data/backtest_results/backtest-result.json | ||||
| ``` | ||||
|  | ||||
| Use custom database | ||||
|   | ||||
| @@ -18,7 +18,7 @@ config = Configuration.from_files([]) | ||||
| # config = Configuration.from_files(["config.json"]) | ||||
|  | ||||
| # Define some constants | ||||
| config["timeframe"] = "5m" | ||||
| config["ticker_interval"] = "5m" | ||||
| # Name of the strategy class | ||||
| config["strategy"] = "SampleStrategy" | ||||
| # Location of the data | ||||
| @@ -33,7 +33,7 @@ pair = "BTC_USDT" | ||||
| from freqtrade.data.history import load_pair_history | ||||
|  | ||||
| candles = load_pair_history(datadir=data_location, | ||||
|                             timeframe=config["timeframe"], | ||||
|                             timeframe=config["ticker_interval"], | ||||
|                             pair=pair) | ||||
|  | ||||
| # Confirm success | ||||
| @@ -85,10 +85,44 @@ Analyze a trades dataframe (also used below for plotting) | ||||
|  | ||||
|  | ||||
| ```python | ||||
| from freqtrade.data.btanalysis import load_backtest_data | ||||
| from freqtrade.data.btanalysis import load_backtest_data, load_backtest_stats | ||||
|  | ||||
| # Load backtest results | ||||
| trades = load_backtest_data(config["user_data_dir"] / "backtest_results/backtest-result.json") | ||||
| # if backtest_dir points to a directory, it'll automatically load the last backtest file. | ||||
| backtest_dir = config["user_data_dir"] / "backtest_results" | ||||
| # backtest_dir can also point to a specific file  | ||||
| # backtest_dir = config["user_data_dir"] / "backtest_results/backtest-result-2020-07-01_20-04-22.json" | ||||
| ``` | ||||
|  | ||||
|  | ||||
| ```python | ||||
| # You can get the full backtest statistics by using the following command. | ||||
| # This contains all information used to generate the backtest result. | ||||
| stats = load_backtest_stats(backtest_dir) | ||||
|  | ||||
| strategy = 'SampleStrategy' | ||||
| # All statistics are available per strategy, so if `--strategy-list` was used during backtest, this will be reflected here as well. | ||||
| # Example usages: | ||||
| print(stats['strategy'][strategy]['results_per_pair']) | ||||
| # Get pairlist used for this backtest | ||||
| print(stats['strategy'][strategy]['pairlist']) | ||||
| # Get market change (average change of all pairs from start to end of the backtest period) | ||||
| print(stats['strategy'][strategy]['market_change']) | ||||
| # Maximum drawdown () | ||||
| print(stats['strategy'][strategy]['max_drawdown']) | ||||
| # Maximum drawdown start and end | ||||
| print(stats['strategy'][strategy]['drawdown_start']) | ||||
| print(stats['strategy'][strategy]['drawdown_end']) | ||||
|  | ||||
|  | ||||
| # Get strategy comparison (only relevant if multiple strategies were compared) | ||||
| print(stats['strategy_comparison']) | ||||
|  | ||||
| ``` | ||||
|  | ||||
|  | ||||
| ```python | ||||
| # Load backtested trades as dataframe | ||||
| trades = load_backtest_data(backtest_dir) | ||||
|  | ||||
| # Show value-counts per pair | ||||
| trades.groupby("pair")["sell_reason"].value_counts() | ||||
|   | ||||
| @@ -72,7 +72,7 @@ def load_backtest_stats(filename: Union[Path, str]) -> Dict[str, Any]: | ||||
| def load_backtest_data(filename: Union[Path, str], strategy: Optional[str] = None) -> pd.DataFrame: | ||||
|     """ | ||||
|     Load backtest data file. | ||||
|     :param filename: pathlib.Path object, or string pointing to the file. | ||||
|     :param filename: pathlib.Path object, or string pointing to a file or directory | ||||
|     :param strategy: Strategy to load - mainly relevant for multi-strategy backtests | ||||
|                      Can also serve as protection to load the correct result. | ||||
|     :return: a dataframe with the analysis results | ||||
|   | ||||
| @@ -136,10 +136,51 @@ | ||||
|    "metadata": {}, | ||||
|    "outputs": [], | ||||
|    "source": [ | ||||
|     "from freqtrade.data.btanalysis import load_backtest_data\n", | ||||
|     "from freqtrade.data.btanalysis import load_backtest_data, load_backtest_stats\n", | ||||
|     "\n", | ||||
|     "# Load backtest results\n", | ||||
|     "trades = load_backtest_data(config[\"user_data_dir\"] / \"backtest_results/backtest-result.json\")\n", | ||||
|     "# if backtest_dir points to a directory, it'll automatically load the last backtest file.\n", | ||||
|     "backtest_dir = config[\"user_data_dir\"] / \"backtest_results\"\n", | ||||
|     "# backtest_dir can also point to a specific file \n", | ||||
|     "# backtest_dir = config[\"user_data_dir\"] / \"backtest_results/backtest-result-2020-07-01_20-04-22.json\"" | ||||
|    ] | ||||
|   }, | ||||
|   { | ||||
|    "cell_type": "code", | ||||
|    "execution_count": null, | ||||
|    "metadata": {}, | ||||
|    "outputs": [], | ||||
|    "source": [ | ||||
|     "# You can get the full backtest statistics by using the following command.\n", | ||||
|     "# This contains all information used to generate the backtest result.\n", | ||||
|     "stats = load_backtest_stats(backtest_dir)\n", | ||||
|     "\n", | ||||
|     "strategy = 'SampleStrategy'\n", | ||||
|     "# All statistics are available per strategy, so if `--strategy-list` was used during backtest, this will be reflected here as well.\n", | ||||
|     "# Example usages:\n", | ||||
|     "print(stats['strategy'][strategy]['results_per_pair'])\n", | ||||
|     "# Get pairlist used for this backtest\n", | ||||
|     "print(stats['strategy'][strategy]['pairlist'])\n", | ||||
|     "# Get market change (average change of all pairs from start to end of the backtest period)\n", | ||||
|     "print(stats['strategy'][strategy]['market_change'])\n", | ||||
|     "# Maximum drawdown ()\n", | ||||
|     "print(stats['strategy'][strategy]['max_drawdown'])\n", | ||||
|     "# Maximum drawdown start and end\n", | ||||
|     "print(stats['strategy'][strategy]['drawdown_start'])\n", | ||||
|     "print(stats['strategy'][strategy]['drawdown_end'])\n", | ||||
|     "\n", | ||||
|     "\n", | ||||
|     "# Get strategy comparison (only relevant if multiple strategies were compared)\n", | ||||
|     "print(stats['strategy_comparison'])\n" | ||||
|    ] | ||||
|   }, | ||||
|   { | ||||
|    "cell_type": "code", | ||||
|    "execution_count": null, | ||||
|    "metadata": {}, | ||||
|    "outputs": [], | ||||
|    "source": [ | ||||
|     "# Load backtested trades as dataframe\n", | ||||
|     "trades = load_backtest_data(backtest_dir)\n", | ||||
|     "\n", | ||||
|     "# Show value-counts per pair\n", | ||||
|     "trades.groupby(\"pair\")[\"sell_reason\"].value_counts()" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user