Remove hardcoded backtest-result.json in Plot scripts
This commit is contained in:
parent
15fb81da92
commit
5683f9e10e
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,6 +8,7 @@ logfile.txt
|
|||||||
hyperopt_trials.pickle
|
hyperopt_trials.pickle
|
||||||
user_data/
|
user_data/
|
||||||
freqtrade-plot.html
|
freqtrade-plot.html
|
||||||
|
freqtrade-profit-plot.html
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
@ -123,8 +123,8 @@ class Arguments(object):
|
|||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-r', '--refresh-pairs-cached',
|
'-r', '--refresh-pairs-cached',
|
||||||
help='refresh the pairs files in tests/testdata with the latest data from the exchange. \
|
help='refresh the pairs files in tests/testdata with the latest data from the '
|
||||||
Use it if you want to run your backtesting with up-to-date data.',
|
'exchange. Use it if you want to run your backtesting with up-to-date data.',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='refresh_pairs',
|
dest='refresh_pairs',
|
||||||
)
|
)
|
||||||
@ -140,11 +140,12 @@ class Arguments(object):
|
|||||||
'--export-filename',
|
'--export-filename',
|
||||||
help='Save backtest results to this filename \
|
help='Save backtest results to this filename \
|
||||||
requires --export to be set as well\
|
requires --export to be set as well\
|
||||||
Example --export-filename=backtest_today.json\
|
Example --export-filename=user_data/backtest_data/backtest_today.json\
|
||||||
(default: %(default)s',
|
(default: %(default)s',
|
||||||
type=str,
|
type=str,
|
||||||
default='backtest-result.json',
|
default=os.path.join('user_data', 'backtest_data', 'backtest-result.json'),
|
||||||
dest='exportfilename',
|
dest='exportfilename',
|
||||||
|
metavar='PATH',
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -220,8 +221,8 @@ class Arguments(object):
|
|||||||
self.hyperopt_options(hyperopt_cmd)
|
self.hyperopt_options(hyperopt_cmd)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_timerange(text: Optional[str]) -> Optional[Tuple[Tuple,
|
def parse_timerange(text: Optional[str]) -> \
|
||||||
Optional[int], Optional[int]]]:
|
Optional[Tuple[Tuple, Optional[int], Optional[int]]]:
|
||||||
"""
|
"""
|
||||||
Parse the value of the argument --timerange to determine what is the range desired
|
Parse the value of the argument --timerange to determine what is the range desired
|
||||||
:param text: value from --timerange
|
:param text: value from --timerange
|
||||||
|
@ -13,18 +13,14 @@ Optional Cli parameters
|
|||||||
-db / --db-url: Show trades stored in database
|
-db / --db-url: Show trades stored in database
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
from argparse import Namespace
|
from argparse import Namespace
|
||||||
|
from typing import Dict, List, Any
|
||||||
from typing import List
|
from sqlalchemy import create_engine
|
||||||
|
|
||||||
from plotly import tools
|
from plotly import tools
|
||||||
from plotly.offline import plot
|
from plotly.offline import plot
|
||||||
import plotly.graph_objs as go
|
import plotly.graph_objs as go
|
||||||
|
|
||||||
from typing import Dict, List, Any
|
|
||||||
from sqlalchemy import create_engine
|
|
||||||
|
|
||||||
from freqtrade.arguments import Arguments
|
from freqtrade.arguments import Arguments
|
||||||
from freqtrade.analyze import Analyze
|
from freqtrade.analyze import Analyze
|
||||||
from freqtrade import exchange
|
from freqtrade import exchange
|
||||||
@ -35,6 +31,7 @@ from freqtrade.persistence import Trade
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
_CONF: Dict[str, Any] = {}
|
_CONF: Dict[str, Any] = {}
|
||||||
|
|
||||||
|
|
||||||
def plot_analyzed_dataframe(args: Namespace) -> None:
|
def plot_analyzed_dataframe(args: Namespace) -> None:
|
||||||
"""
|
"""
|
||||||
Calls analyze() and plots the returned dataframe
|
Calls analyze() and plots the returned dataframe
|
||||||
@ -187,7 +184,7 @@ def plot_analyzed_dataframe(args: Namespace) -> None:
|
|||||||
fig['layout']['yaxis2'].update(title='Volume')
|
fig['layout']['yaxis2'].update(title='Volume')
|
||||||
fig['layout']['yaxis3'].update(title='MACD')
|
fig['layout']['yaxis3'].update(title='MACD')
|
||||||
|
|
||||||
plot(fig, filename='freqtrade-plot.html')
|
plot(fig, filename=os.path.join('user_data', 'freqtrade-plot.html'))
|
||||||
|
|
||||||
|
|
||||||
def plot_parse_args(args: List[str]) -> Namespace:
|
def plot_parse_args(args: List[str]) -> Namespace:
|
||||||
|
@ -8,9 +8,12 @@ Mandatory Cli parameters:
|
|||||||
Optional Cli parameters
|
Optional Cli parameters
|
||||||
-c / --config: specify configuration file
|
-c / --config: specify configuration file
|
||||||
-s / --strategy: strategy to use
|
-s / --strategy: strategy to use
|
||||||
--timerange: specify what timerange of data to use.
|
-d / --datadir: path to pair backtest data
|
||||||
|
--timerange: specify what timerange of data to use
|
||||||
|
--export-filename: Specify where the backtest export is located.
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
from argparse import Namespace
|
from argparse import Namespace
|
||||||
@ -90,7 +93,18 @@ def plot_profit(args: Namespace) -> None:
|
|||||||
'Impossible to load the strategy. Please check the file "user_data/strategies/%s.py"',
|
'Impossible to load the strategy. Please check the file "user_data/strategies/%s.py"',
|
||||||
config.get('strategy')
|
config.get('strategy')
|
||||||
)
|
)
|
||||||
exit()
|
exit(0)
|
||||||
|
|
||||||
|
# Load the profits results
|
||||||
|
try:
|
||||||
|
filename = args.exportfilename
|
||||||
|
with open(filename) as file:
|
||||||
|
data = json.load(file)
|
||||||
|
except FileNotFoundError:
|
||||||
|
logger.critical(
|
||||||
|
'File "backtest-result.json" not found. This script require backtesting '
|
||||||
|
'results to run.\nPlease run a backtesting with the parameter --export.')
|
||||||
|
exit(0)
|
||||||
|
|
||||||
# Take pairs from the cli otherwise switch to the pair in the config file
|
# Take pairs from the cli otherwise switch to the pair in the config file
|
||||||
if args.pair:
|
if args.pair:
|
||||||
@ -140,18 +154,7 @@ def plot_profit(args: Namespace) -> None:
|
|||||||
num += 1
|
num += 1
|
||||||
avgclose /= num
|
avgclose /= num
|
||||||
|
|
||||||
# Load the profits results
|
# make an profits-growth array
|
||||||
# And make an profits-growth array
|
|
||||||
|
|
||||||
try:
|
|
||||||
filename = 'backtest-result.json'
|
|
||||||
with open(filename) as file:
|
|
||||||
data = json.load(file)
|
|
||||||
except FileNotFoundError:
|
|
||||||
logger.critical('File "backtest-result.json" not found. This script require backtesting '
|
|
||||||
'results to run.\nPlease run a backtesting with the parameter --export.')
|
|
||||||
exit(0)
|
|
||||||
|
|
||||||
pg = make_profit_array(data, num_iterations, min_date, tick_interval, filter_pairs)
|
pg = make_profit_array(data, num_iterations, min_date, tick_interval, filter_pairs)
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -184,7 +187,7 @@ def plot_profit(args: Namespace) -> None:
|
|||||||
)
|
)
|
||||||
fig.append_trace(pair_profit, 3, 1)
|
fig.append_trace(pair_profit, 3, 1)
|
||||||
|
|
||||||
plot(fig, filename='freqtrade-profit-plot.html')
|
plot(fig, filename=os.path.join('user_data', 'freqtrade-profit-plot.html'))
|
||||||
|
|
||||||
|
|
||||||
def define_index(min_date: int, max_date: int, interval: str) -> int:
|
def define_index(min_date: int, max_date: int, interval: str) -> int:
|
||||||
|
0
user_data/backtest_data/.gitkeep
Normal file
0
user_data/backtest_data/.gitkeep
Normal file
Loading…
Reference in New Issue
Block a user