Merge pull request #2906 from freqtrade/fix/jupyterexample

Update data-analysis documentation to properly initialize configuration
This commit is contained in:
hroff-1902
2020-02-14 22:36:35 +03:00
committed by GitHub
2 changed files with 30 additions and 26 deletions

View File

@@ -6,7 +6,8 @@
"source": [
"# Strategy analysis example\n",
"\n",
"Debugging a strategy can be time-consuming. FreqTrade offers helper functions to visualize raw data."
"Debugging a strategy can be time-consuming. Freqtrade offers helper functions to visualize raw data.\n",
"The following assumes you work with SampleStrategy, data for 5m timeframe from Binance and have downloaded them into the data directory in the default location."
]
},
{
@@ -23,18 +24,21 @@
"outputs": [],
"source": [
"from pathlib import Path\n",
"from freqtrade.configuration import Configuration\n",
"\n",
"# Customize these according to your needs.\n",
"\n",
"# Initialize empty configuration object\n",
"config = Configuration.from_files([])\n",
"# Optionally, use existing configuration file\n",
"# config = Configuration.from_files([\"config.json\"])\n",
"\n",
"# Define some constants\n",
"timeframe = \"5m\"\n",
"config[\"ticker_interval\"] = \"5m\"\n",
"# Name of the strategy class\n",
"strategy_name = 'SampleStrategy'\n",
"# Path to user data\n",
"user_data_dir = Path('user_data')\n",
"# Location of the strategy\n",
"strategy_location = user_data_dir / 'strategies'\n",
"config[\"strategy\"] = \"SampleStrategy\"\n",
"# Location of the data\n",
"data_location = Path(user_data_dir, 'data', 'binance')\n",
"data_location = Path(config['user_data_dir'], 'data', 'binance')\n",
"# Pair to analyze - Only use one pair here\n",
"pair = \"BTC_USDT\""
]
@@ -49,7 +53,7 @@
"from freqtrade.data.history import load_pair_history\n",
"\n",
"candles = load_pair_history(datadir=data_location,\n",
" timeframe=timeframe,\n",
" timeframe=config[\"ticker_interval\"],\n",
" pair=pair)\n",
"\n",
"# Confirm success\n",
@@ -73,9 +77,7 @@
"source": [
"# Load strategy using values set above\n",
"from freqtrade.resolvers import StrategyResolver\n",
"strategy = StrategyResolver.load_strategy({'strategy': strategy_name,\n",
" 'user_data_dir': user_data_dir,\n",
" 'strategy_path': strategy_location})\n",
"strategy = StrategyResolver.load_strategy(config)\n",
"\n",
"# Generate buy/sell signals using strategy\n",
"df = strategy.analyze_ticker(candles, {'pair': pair})\n",
@@ -137,7 +139,7 @@
"from freqtrade.data.btanalysis import load_backtest_data\n",
"\n",
"# Load backtest results\n",
"trades = load_backtest_data(user_data_dir / \"backtest_results/backtest-result.json\")\n",
"trades = load_backtest_data(config[\"user_data_dir\"] / \"backtest_results/backtest-result.json\")\n",
"\n",
"# Show value-counts per pair\n",
"trades.groupby(\"pair\")[\"sell_reason\"].value_counts()"