Add samples for plotting to jupyter documentation
This commit is contained in:
parent
5234f8bf28
commit
359b0ba088
@ -61,34 +61,6 @@ except:
|
||||
print(Path.cwd())
|
||||
```
|
||||
|
||||
## Load existing objects into a Jupyter notebook
|
||||
|
||||
These examples assume that you have already generated data using the cli. They will allow you to drill deeper into your results, and perform analysis which otherwise would make the output very difficult to digest due to information overload.
|
||||
|
||||
### Load backtest results into a pandas dataframe
|
||||
|
||||
```python
|
||||
from freqtrade.data.btanalysis import load_backtest_data
|
||||
|
||||
# Load backtest results
|
||||
df = load_backtest_data("user_data/backtest_results/backtest-result.json")
|
||||
|
||||
# Show value-counts per pair
|
||||
df.groupby("pair")["sell_reason"].value_counts()
|
||||
```
|
||||
|
||||
### Load live trading results into a pandas dataframe
|
||||
|
||||
``` python
|
||||
from freqtrade.data.btanalysis import load_trades_from_db
|
||||
|
||||
# Fetch trades from database
|
||||
df = load_trades_from_db("sqlite:///tradesv3.sqlite")
|
||||
|
||||
# Display results
|
||||
df.groupby("pair")["sell_reason"].value_counts()
|
||||
```
|
||||
|
||||
### Load multiple configuration files
|
||||
|
||||
This option can be useful to inspect the results of passing in multiple configs.
|
||||
@ -114,30 +86,9 @@ Best avoid relative paths, since this starts at the storage location of the jupy
|
||||
}
|
||||
```
|
||||
|
||||
### Load exchange data to a pandas dataframe
|
||||
### Further Data analysis documentation
|
||||
|
||||
This loads candle data to a dataframe
|
||||
|
||||
```python
|
||||
from pathlib import Path
|
||||
from freqtrade.data.history import load_pair_history
|
||||
|
||||
# Load data using values passed to function
|
||||
ticker_interval = "5m"
|
||||
data_location = Path('user_data', 'data', 'bitrex')
|
||||
pair = "BTC_USDT"
|
||||
candles = load_pair_history(datadir=data_location,
|
||||
ticker_interval=ticker_interval,
|
||||
pair=pair)
|
||||
|
||||
# Confirm success
|
||||
print(f"Loaded len(candles) rows of data for {pair} from {data_location}")
|
||||
candles.head()
|
||||
```
|
||||
|
||||
Further Data analysis documents:
|
||||
|
||||
* [Strategy debugging](strategy_analysis_example.md)
|
||||
* [Strategy debugging](strategy_analysis_example.md) - also available as Jupyter notebook (`user_data/notebooks/strategy_analysis_example.ipynb`)
|
||||
* [Plotting](plotting.md)
|
||||
|
||||
Feel free to submit an issue or Pull Request enhancing this document if you would like to share ideas on how to best analyze the data.
|
||||
|
@ -68,8 +68,75 @@ df.tail()
|
||||
```python
|
||||
# Report results
|
||||
print(f"Generated {df['buy'].sum()} buy signals")
|
||||
data = df.set_index('date', drop=True)
|
||||
data = df.set_index('date', drop=False)
|
||||
data.tail()
|
||||
```
|
||||
|
||||
## Load existing objects into a Jupyter notebook
|
||||
|
||||
The following cells assume that you have already generated data using the cli.
|
||||
They will allow you to drill deeper into your results, and perform analysis which otherwise would make the output very difficult to digest due to information overload.
|
||||
|
||||
### Load backtest results to pandas dataframe
|
||||
|
||||
Analyze a trades dataframe (also used below for plotting)
|
||||
|
||||
|
||||
```python
|
||||
from freqtrade.data.btanalysis import load_backtest_data
|
||||
|
||||
# Load backtest results
|
||||
trades = load_backtest_data(user_data_dir / "backtest_results/backtest-result.json")
|
||||
|
||||
# Show value-counts per pair
|
||||
trades.groupby("pair")["sell_reason"].value_counts()
|
||||
```
|
||||
|
||||
### Load live trading results into a pandas dataframe
|
||||
|
||||
In case you did already some trading and want to analyze your performance
|
||||
|
||||
|
||||
```python
|
||||
from freqtrade.data.btanalysis import load_trades_from_db
|
||||
|
||||
# Fetch trades from database
|
||||
trades = load_trades_from_db("sqlite:///tradesv3.sqlite")
|
||||
|
||||
# Display results
|
||||
trades.groupby("pair")["sell_reason"].value_counts()
|
||||
```
|
||||
|
||||
## Plot results
|
||||
|
||||
Freqtrade offers interactive plotting capabilities based on plotly.
|
||||
|
||||
|
||||
```python
|
||||
from freqtrade.plot.plotting import generate_candlestick_graph
|
||||
# Limit graph period to keep plotly quick and reactive
|
||||
|
||||
data_red = data['2019-06-01':'2019-06-10']
|
||||
# Generate candlestick graph
|
||||
graph = generate_candlestick_graph(pair=pair,
|
||||
data=data_red,
|
||||
trades=trades,
|
||||
indicators1=['sma20', 'ema50', 'ema55'],
|
||||
indicators2=['rsi', 'macd', 'macdsignal', 'macdhist']
|
||||
)
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
# Show graph inline
|
||||
# graph.show()
|
||||
|
||||
# Render graph in a seperate window
|
||||
graph.show(renderer="browser")
|
||||
|
||||
```
|
||||
|
||||
Feel free to submit an issue or Pull Request enhancing this document if you would like to share ideas on how to best analyze the data.
|
||||
|
@ -107,10 +107,111 @@
|
||||
"source": [
|
||||
"# Report results\n",
|
||||
"print(f\"Generated {df['buy'].sum()} buy signals\")\n",
|
||||
"data = df.set_index('date', drop=True)\n",
|
||||
"data = df.set_index('date', drop=False)\n",
|
||||
"data.tail()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Load existing objects into a Jupyter notebook\n",
|
||||
"\n",
|
||||
"The following cells assume that you have already generated data using the cli. \n",
|
||||
"They will allow you to drill deeper into your results, and perform analysis which otherwise would make the output very difficult to digest due to information overload."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Load backtest results to pandas dataframe\n",
|
||||
"\n",
|
||||
"Analyze a trades dataframe (also used below for plotting)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"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",
|
||||
"\n",
|
||||
"# Show value-counts per pair\n",
|
||||
"trades.groupby(\"pair\")[\"sell_reason\"].value_counts()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Load live trading results into a pandas dataframe\n",
|
||||
"\n",
|
||||
"In case you did already some trading and want to analyze your performance"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from freqtrade.data.btanalysis import load_trades_from_db\n",
|
||||
"\n",
|
||||
"# Fetch trades from database\n",
|
||||
"trades = load_trades_from_db(\"sqlite:///tradesv3.sqlite\")\n",
|
||||
"\n",
|
||||
"# Display results\n",
|
||||
"trades.groupby(\"pair\")[\"sell_reason\"].value_counts()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Plot results\n",
|
||||
"\n",
|
||||
"Freqtrade offers interactive plotting capabilities based on plotly."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from freqtrade.plot.plotting import generate_candlestick_graph\n",
|
||||
"# Limit graph period to keep plotly quick and reactive\n",
|
||||
"\n",
|
||||
"data_red = data['2019-06-01':'2019-06-10']\n",
|
||||
"# Generate candlestick graph\n",
|
||||
"graph = generate_candlestick_graph(pair=pair,\n",
|
||||
" data=data_red,\n",
|
||||
" trades=trades,\n",
|
||||
" indicators1=['sma20', 'ema50', 'ema55'],\n",
|
||||
" indicators2=['rsi', 'macd', 'macdsignal', 'macdhist']\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Show graph inline\n",
|
||||
"# graph.show()\n",
|
||||
"\n",
|
||||
"# Render graph in a seperate window\n",
|
||||
"graph.show(renderer=\"browser\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
|
Loading…
Reference in New Issue
Block a user