Update data-analysis documentation to properly initialize configuration

This commit is contained in:
Matthias 2020-02-11 20:45:53 +01:00
parent 64fb8e28ec
commit 7be9f0067e
2 changed files with 26 additions and 28 deletions

View File

@ -7,18 +7,19 @@ Debugging a strategy can be time-consuming. FreqTrade offers helper functions to
```python ```python
from pathlib import Path from pathlib import Path
from freqtrade.configuration import Configuration
# Customize these according to your needs. # Customize these according to your needs.
# Initialize empty configuration object
config = Configuration.from_files([])
# Optionally, Use existing configuration file
# config = Configuration.from_files(["config.json"])
# Define some constants # Define some constants
timeframe = "5m" config["ticker_interval"] = "5m"
# Name of the strategy class # Name of the strategy class
strategy_name = 'SampleStrategy' config["strategy"] = "SampleStrategy"
# Path to user data
user_data_dir = Path('user_data')
# Location of the strategy
strategy_location = user_data_dir / 'strategies'
# Location of the data
data_location = Path(user_data_dir, 'data', 'binance')
# Pair to analyze - Only use one pair here # Pair to analyze - Only use one pair here
pair = "BTC_USDT" pair = "BTC_USDT"
``` ```
@ -28,8 +29,8 @@ pair = "BTC_USDT"
# Load data using values set above # Load data using values set above
from freqtrade.data.history import load_pair_history from freqtrade.data.history import load_pair_history
candles = load_pair_history(datadir=data_location, candles = load_pair_history(datadir=config["data_dir"],
timeframe=timeframe, timeframe=config["ticker_interval"],
pair=pair) pair=pair)
# Confirm success # Confirm success
@ -44,9 +45,7 @@ candles.head()
```python ```python
# Load strategy using values set above # Load strategy using values set above
from freqtrade.resolvers import StrategyResolver from freqtrade.resolvers import StrategyResolver
strategy = StrategyResolver.load_strategy({'strategy': strategy_name, strategy = StrategyResolver.load_strategy(config)
'user_data_dir': user_data_dir,
'strategy_path': strategy_location})
# Generate buy/sell signals using strategy # Generate buy/sell signals using strategy
df = strategy.analyze_ticker(candles, {'pair': pair}) df = strategy.analyze_ticker(candles, {'pair': pair})
@ -86,7 +85,7 @@ Analyze a trades dataframe (also used below for plotting)
from freqtrade.data.btanalysis import load_backtest_data from freqtrade.data.btanalysis import load_backtest_data
# Load backtest results # Load backtest results
trades = load_backtest_data(user_data_dir / "backtest_results/backtest-result.json") trades = load_backtest_data(config["user_data_dir"] / "backtest_results/backtest-result.json")
# Show value-counts per pair # Show value-counts per pair
trades.groupby("pair")["sell_reason"].value_counts() trades.groupby("pair")["sell_reason"].value_counts()

View File

@ -23,18 +23,19 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"from pathlib import Path\n", "from pathlib import Path\n",
"from freqtrade.configuration import Configuration\n",
"\n",
"# Customize these according to your needs.\n", "# Customize these according to your needs.\n",
"\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", "# Define some constants\n",
"timeframe = \"5m\"\n", "config[\"ticker_interval\"] = \"5m\"\n",
"# Name of the strategy class\n", "# Name of the strategy class\n",
"strategy_name = 'SampleStrategy'\n", "config[\"strategy\"] = \"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",
"# Location of the data\n",
"data_location = Path(user_data_dir, 'data', 'binance')\n",
"# Pair to analyze - Only use one pair here\n", "# Pair to analyze - Only use one pair here\n",
"pair = \"BTC_USDT\"" "pair = \"BTC_USDT\""
] ]
@ -48,8 +49,8 @@
"# Load data using values set above\n", "# Load data using values set above\n",
"from freqtrade.data.history import load_pair_history\n", "from freqtrade.data.history import load_pair_history\n",
"\n", "\n",
"candles = load_pair_history(datadir=data_location,\n", "candles = load_pair_history(datadir=config[\"data_dir\"],\n",
" timeframe=timeframe,\n", " timeframe=config[\"ticker_interval\"],\n",
" pair=pair)\n", " pair=pair)\n",
"\n", "\n",
"# Confirm success\n", "# Confirm success\n",
@ -73,9 +74,7 @@
"source": [ "source": [
"# Load strategy using values set above\n", "# Load strategy using values set above\n",
"from freqtrade.resolvers import StrategyResolver\n", "from freqtrade.resolvers import StrategyResolver\n",
"strategy = StrategyResolver.load_strategy({'strategy': strategy_name,\n", "strategy = StrategyResolver.load_strategy(config)\n",
" 'user_data_dir': user_data_dir,\n",
" 'strategy_path': strategy_location})\n",
"\n", "\n",
"# Generate buy/sell signals using strategy\n", "# Generate buy/sell signals using strategy\n",
"df = strategy.analyze_ticker(candles, {'pair': pair})\n", "df = strategy.analyze_ticker(candles, {'pair': pair})\n",
@ -137,7 +136,7 @@
"from freqtrade.data.btanalysis import load_backtest_data\n", "from freqtrade.data.btanalysis import load_backtest_data\n",
"\n", "\n",
"# Load backtest results\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", "\n",
"# Show value-counts per pair\n", "# Show value-counts per pair\n",
"trades.groupby(\"pair\")[\"sell_reason\"].value_counts()" "trades.groupby(\"pair\")[\"sell_reason\"].value_counts()"