chore: re-format ipynb notebook
This commit is contained in:
@@ -13,6 +13,7 @@ Please follow the [documentation](https://www.freqtrade.io/en/stable/data-downlo
|
|||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
# Change directory
|
# Change directory
|
||||||
# Modify this cell to insure that the output shows the correct path.
|
# Modify this cell to insure that the output shows the correct path.
|
||||||
# Define all paths relative to the project root shown in the cell output
|
# Define all paths relative to the project root shown in the cell output
|
||||||
@@ -20,12 +21,14 @@ project_root = "somedir/freqtrade"
|
|||||||
i=0
|
i=0
|
||||||
try:
|
try:
|
||||||
os.chdir(project_root)
|
os.chdir(project_root)
|
||||||
assert Path('LICENSE').is_file()
|
if not Path('LICENSE').is_file():
|
||||||
except:
|
i = 0
|
||||||
while i<4 and (not Path('LICENSE').is_file()):
|
while i < 4 and (not Path('LICENSE').is_file()):
|
||||||
os.chdir(Path(Path.cwd(), '../'))
|
os.chdir(Path(Path.cwd(), '../'))
|
||||||
i+=1
|
i += 1
|
||||||
project_root = Path.cwd()
|
project_root = Path.cwd()
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("Please define the project root relative to the current directory")
|
||||||
print(Path.cwd())
|
print(Path.cwd())
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -35,6 +38,7 @@ print(Path.cwd())
|
|||||||
```python
|
```python
|
||||||
from freqtrade.configuration import Configuration
|
from freqtrade.configuration import Configuration
|
||||||
|
|
||||||
|
|
||||||
# Customize these according to your needs.
|
# Customize these according to your needs.
|
||||||
|
|
||||||
# Initialize empty configuration object
|
# Initialize empty configuration object
|
||||||
@@ -58,6 +62,7 @@ pair = "BTC/USDT"
|
|||||||
from freqtrade.data.history import load_pair_history
|
from freqtrade.data.history import load_pair_history
|
||||||
from freqtrade.enums import CandleType
|
from freqtrade.enums import CandleType
|
||||||
|
|
||||||
|
|
||||||
candles = load_pair_history(datadir=data_location,
|
candles = load_pair_history(datadir=data_location,
|
||||||
timeframe=config["timeframe"],
|
timeframe=config["timeframe"],
|
||||||
pair=pair,
|
pair=pair,
|
||||||
@@ -76,8 +81,10 @@ candles.head()
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
# Load strategy using values set above
|
# Load strategy using values set above
|
||||||
from freqtrade.resolvers import StrategyResolver
|
|
||||||
from freqtrade.data.dataprovider import DataProvider
|
from freqtrade.data.dataprovider import DataProvider
|
||||||
|
from freqtrade.resolvers import StrategyResolver
|
||||||
|
|
||||||
|
|
||||||
strategy = StrategyResolver.load_strategy(config)
|
strategy = StrategyResolver.load_strategy(config)
|
||||||
strategy.dp = DataProvider(config, None, None)
|
strategy.dp = DataProvider(config, None, None)
|
||||||
strategy.ft_bot_start()
|
strategy.ft_bot_start()
|
||||||
@@ -119,10 +126,13 @@ Analyze a trades dataframe (also used below for plotting)
|
|||||||
```python
|
```python
|
||||||
from freqtrade.data.btanalysis import load_backtest_data, load_backtest_stats
|
from freqtrade.data.btanalysis import load_backtest_data, load_backtest_stats
|
||||||
|
|
||||||
|
|
||||||
# if backtest_dir points to a directory, it'll automatically load the last backtest file.
|
# 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 = config["user_data_dir"] / "backtest_results"
|
||||||
# backtest_dir can also point to a specific file
|
# 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"
|
# backtest_dir = (
|
||||||
|
# config["user_data_dir"] / "backtest_results/backtest-result-2020-07-01_20-04-22.json"
|
||||||
|
# )
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -132,7 +142,8 @@ backtest_dir = config["user_data_dir"] / "backtest_results"
|
|||||||
stats = load_backtest_stats(backtest_dir)
|
stats = load_backtest_stats(backtest_dir)
|
||||||
|
|
||||||
strategy = 'SampleStrategy'
|
strategy = 'SampleStrategy'
|
||||||
# All statistics are available per strategy, so if `--strategy-list` was used during backtest, this will be reflected here as well.
|
# All statistics are available per strategy, so if `--strategy-list` was used during backtest,
|
||||||
|
# this will be reflected here as well.
|
||||||
# Example usages:
|
# Example usages:
|
||||||
print(stats['strategy'][strategy]['results_per_pair'])
|
print(stats['strategy'][strategy]['results_per_pair'])
|
||||||
# Get pairlist used for this backtest
|
# Get pairlist used for this backtest
|
||||||
@@ -166,10 +177,12 @@ trades.groupby("pair")["exit_reason"].value_counts()
|
|||||||
```python
|
```python
|
||||||
# Plotting equity line (starting with 0 on day 1 and adding daily profit for each backtested day)
|
# Plotting equity line (starting with 0 on day 1 and adding daily profit for each backtested day)
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
import plotly.express as px
|
||||||
|
|
||||||
from freqtrade.configuration import Configuration
|
from freqtrade.configuration import Configuration
|
||||||
from freqtrade.data.btanalysis import load_backtest_stats
|
from freqtrade.data.btanalysis import load_backtest_stats
|
||||||
import plotly.express as px
|
|
||||||
import pandas as pd
|
|
||||||
|
|
||||||
# strategy = 'SampleStrategy'
|
# strategy = 'SampleStrategy'
|
||||||
# config = Configuration.from_files(["user_data/config.json"])
|
# config = Configuration.from_files(["user_data/config.json"])
|
||||||
@@ -194,6 +207,7 @@ In case you did already some trading and want to analyze your performance
|
|||||||
```python
|
```python
|
||||||
from freqtrade.data.btanalysis import load_trades_from_db
|
from freqtrade.data.btanalysis import load_trades_from_db
|
||||||
|
|
||||||
|
|
||||||
# Fetch trades from database
|
# Fetch trades from database
|
||||||
trades = load_trades_from_db("sqlite:///tradesv3.sqlite")
|
trades = load_trades_from_db("sqlite:///tradesv3.sqlite")
|
||||||
|
|
||||||
@@ -210,6 +224,7 @@ This can be useful to find the best `max_open_trades` parameter, when used with
|
|||||||
```python
|
```python
|
||||||
from freqtrade.data.btanalysis import analyze_trade_parallelism
|
from freqtrade.data.btanalysis import analyze_trade_parallelism
|
||||||
|
|
||||||
|
|
||||||
# Analyze the above
|
# Analyze the above
|
||||||
parallel_trades = analyze_trade_parallelism(trades, '5m')
|
parallel_trades = analyze_trade_parallelism(trades, '5m')
|
||||||
|
|
||||||
@@ -222,7 +237,9 @@ Freqtrade offers interactive plotting capabilities based on plotly.
|
|||||||
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from freqtrade.plot.plotting import generate_candlestick_graph
|
from freqtrade.plot.plotting import generate_candlestick_graph
|
||||||
|
|
||||||
|
|
||||||
# Limit graph period to keep plotly quick and reactive
|
# Limit graph period to keep plotly quick and reactive
|
||||||
|
|
||||||
# Filter trades to one pair
|
# Filter trades to one pair
|
||||||
@@ -257,6 +274,7 @@ graph.show(renderer="browser")
|
|||||||
```python
|
```python
|
||||||
import plotly.figure_factory as ff
|
import plotly.figure_factory as ff
|
||||||
|
|
||||||
|
|
||||||
hist_data = [trades.profit_ratio]
|
hist_data = [trades.profit_ratio]
|
||||||
group_labels = ['profit_ratio'] # name of the dataset
|
group_labels = ['profit_ratio'] # name of the dataset
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
"import os\n",
|
"import os\n",
|
||||||
"from pathlib import Path\n",
|
"from pathlib import Path\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"\n",
|
||||||
"# Change directory\n",
|
"# Change directory\n",
|
||||||
"# Modify this cell to insure that the output shows the correct path.\n",
|
"# Modify this cell to insure that the output shows the correct path.\n",
|
||||||
"# Define all paths relative to the project root shown in the cell output\n",
|
"# Define all paths relative to the project root shown in the cell output\n",
|
||||||
@@ -36,12 +37,14 @@
|
|||||||
"i=0\n",
|
"i=0\n",
|
||||||
"try:\n",
|
"try:\n",
|
||||||
" os.chdir(project_root)\n",
|
" os.chdir(project_root)\n",
|
||||||
" assert Path('LICENSE').is_file()\n",
|
" if not Path('LICENSE').is_file():\n",
|
||||||
"except:\n",
|
" i = 0\n",
|
||||||
" while i<4 and (not Path('LICENSE').is_file()):\n",
|
" while i < 4 and (not Path('LICENSE').is_file()):\n",
|
||||||
" os.chdir(Path(Path.cwd(), '../'))\n",
|
" os.chdir(Path(Path.cwd(), '../'))\n",
|
||||||
" i+=1\n",
|
" i += 1\n",
|
||||||
" project_root = Path.cwd()\n",
|
" project_root = Path.cwd()\n",
|
||||||
|
"except FileNotFoundError:\n",
|
||||||
|
" print(\"Please define the project root relative to the current directory\")\n",
|
||||||
"print(Path.cwd())"
|
"print(Path.cwd())"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -60,6 +63,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"from freqtrade.configuration import Configuration\n",
|
"from freqtrade.configuration import Configuration\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"\n",
|
||||||
"# Customize these according to your needs.\n",
|
"# Customize these according to your needs.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# Initialize empty configuration object\n",
|
"# Initialize empty configuration object\n",
|
||||||
@@ -87,6 +91,7 @@
|
|||||||
"from freqtrade.data.history import load_pair_history\n",
|
"from freqtrade.data.history import load_pair_history\n",
|
||||||
"from freqtrade.enums import CandleType\n",
|
"from freqtrade.enums import CandleType\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"\n",
|
||||||
"candles = load_pair_history(datadir=data_location,\n",
|
"candles = load_pair_history(datadir=data_location,\n",
|
||||||
" timeframe=config[\"timeframe\"],\n",
|
" timeframe=config[\"timeframe\"],\n",
|
||||||
" pair=pair,\n",
|
" pair=pair,\n",
|
||||||
@@ -114,8 +119,10 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# Load strategy using values set above\n",
|
"# Load strategy using values set above\n",
|
||||||
"from freqtrade.resolvers import StrategyResolver\n",
|
|
||||||
"from freqtrade.data.dataprovider import DataProvider\n",
|
"from freqtrade.data.dataprovider import DataProvider\n",
|
||||||
|
"from freqtrade.resolvers import StrategyResolver\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
"strategy = StrategyResolver.load_strategy(config)\n",
|
"strategy = StrategyResolver.load_strategy(config)\n",
|
||||||
"strategy.dp = DataProvider(config, None, None)\n",
|
"strategy.dp = DataProvider(config, None, None)\n",
|
||||||
"strategy.ft_bot_start()\n",
|
"strategy.ft_bot_start()\n",
|
||||||
@@ -179,10 +186,13 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"from freqtrade.data.btanalysis import load_backtest_data, load_backtest_stats\n",
|
"from freqtrade.data.btanalysis import load_backtest_data, load_backtest_stats\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"\n",
|
||||||
"# if backtest_dir points to a directory, it'll automatically load the last backtest file.\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 = config[\"user_data_dir\"] / \"backtest_results\"\n",
|
||||||
"# backtest_dir can also point to a specific file\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\""
|
"# backtest_dir = (\n",
|
||||||
|
"# config[\"user_data_dir\"] / \"backtest_results/backtest-result-2020-07-01_20-04-22.json\"\n",
|
||||||
|
"# )"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -196,7 +206,8 @@
|
|||||||
"stats = load_backtest_stats(backtest_dir)\n",
|
"stats = load_backtest_stats(backtest_dir)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"strategy = 'SampleStrategy'\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",
|
"# All statistics are available per strategy, so if `--strategy-list` was used during backtest,\n",
|
||||||
|
"# this will be reflected here as well.\n",
|
||||||
"# Example usages:\n",
|
"# Example usages:\n",
|
||||||
"print(stats['strategy'][strategy]['results_per_pair'])\n",
|
"print(stats['strategy'][strategy]['results_per_pair'])\n",
|
||||||
"# Get pairlist used for this backtest\n",
|
"# Get pairlist used for this backtest\n",
|
||||||
@@ -242,10 +253,12 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"# Plotting equity line (starting with 0 on day 1 and adding daily profit for each backtested day)\n",
|
"# Plotting equity line (starting with 0 on day 1 and adding daily profit for each backtested day)\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"import pandas as pd\n",
|
||||||
|
"import plotly.express as px\n",
|
||||||
|
"\n",
|
||||||
"from freqtrade.configuration import Configuration\n",
|
"from freqtrade.configuration import Configuration\n",
|
||||||
"from freqtrade.data.btanalysis import load_backtest_stats\n",
|
"from freqtrade.data.btanalysis import load_backtest_stats\n",
|
||||||
"import plotly.express as px\n",
|
"\n",
|
||||||
"import pandas as pd\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"# strategy = 'SampleStrategy'\n",
|
"# strategy = 'SampleStrategy'\n",
|
||||||
"# config = Configuration.from_files([\"user_data/config.json\"])\n",
|
"# config = Configuration.from_files([\"user_data/config.json\"])\n",
|
||||||
@@ -278,6 +291,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"from freqtrade.data.btanalysis import load_trades_from_db\n",
|
"from freqtrade.data.btanalysis import load_trades_from_db\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"\n",
|
||||||
"# Fetch trades from database\n",
|
"# Fetch trades from database\n",
|
||||||
"trades = load_trades_from_db(\"sqlite:///tradesv3.sqlite\")\n",
|
"trades = load_trades_from_db(\"sqlite:///tradesv3.sqlite\")\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -303,6 +317,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"from freqtrade.data.btanalysis import analyze_trade_parallelism\n",
|
"from freqtrade.data.btanalysis import analyze_trade_parallelism\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"\n",
|
||||||
"# Analyze the above\n",
|
"# Analyze the above\n",
|
||||||
"parallel_trades = analyze_trade_parallelism(trades, '5m')\n",
|
"parallel_trades = analyze_trade_parallelism(trades, '5m')\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -324,7 +339,9 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"from freqtrade.plot.plotting import generate_candlestick_graph\n",
|
"from freqtrade.plot.plotting import generate_candlestick_graph\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
"# Limit graph period to keep plotly quick and reactive\n",
|
"# Limit graph period to keep plotly quick and reactive\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# Filter trades to one pair\n",
|
"# Filter trades to one pair\n",
|
||||||
@@ -370,6 +387,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"import plotly.figure_factory as ff\n",
|
"import plotly.figure_factory as ff\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"\n",
|
||||||
"hist_data = [trades.profit_ratio]\n",
|
"hist_data = [trades.profit_ratio]\n",
|
||||||
"group_labels = ['profit_ratio'] # name of the dataset\n",
|
"group_labels = ['profit_ratio'] # name of the dataset\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
|||||||
Reference in New Issue
Block a user