tests cover more backtesting
This commit is contained in:
parent
421ccb23d3
commit
79fcd0b06c
@ -12,8 +12,9 @@ from freqtrade import exchange
|
|||||||
from freqtrade.analyze import populate_buy_trend, populate_sell_trend
|
from freqtrade.analyze import populate_buy_trend, populate_sell_trend
|
||||||
from freqtrade.exchange import Bittrex
|
from freqtrade.exchange import Bittrex
|
||||||
from freqtrade.main import min_roi_reached
|
from freqtrade.main import min_roi_reached
|
||||||
from freqtrade.misc import load_config
|
import freqtrade.misc as misc
|
||||||
from freqtrade.optimize import load_data, preprocess
|
from freqtrade.optimize import preprocess
|
||||||
|
import freqtrade.optimize as optimize
|
||||||
from freqtrade.persistence import Trade
|
from freqtrade.persistence import Trade
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -149,7 +150,7 @@ def start(args):
|
|||||||
exchange._API = Bittrex({'key': '', 'secret': ''})
|
exchange._API = Bittrex({'key': '', 'secret': ''})
|
||||||
|
|
||||||
logger.info('Using config: %s ...', args.config)
|
logger.info('Using config: %s ...', args.config)
|
||||||
config = load_config(args.config)
|
config = misc.load_config(args.config)
|
||||||
|
|
||||||
logger.info('Using ticker_interval: %s ...', args.ticker_interval)
|
logger.info('Using ticker_interval: %s ...', args.ticker_interval)
|
||||||
|
|
||||||
@ -161,7 +162,7 @@ def start(args):
|
|||||||
data[pair] = exchange.get_ticker_history(pair, args.ticker_interval)
|
data[pair] = exchange.get_ticker_history(pair, args.ticker_interval)
|
||||||
else:
|
else:
|
||||||
logger.info('Using local backtesting data (using whitelist in given config) ...')
|
logger.info('Using local backtesting data (using whitelist in given config) ...')
|
||||||
data = load_data(pairs=pairs, ticker_interval=args.ticker_interval,
|
data = optimize.load_data(pairs=pairs, ticker_interval=args.ticker_interval,
|
||||||
refresh_pairs=args.refresh_pairs)
|
refresh_pairs=args.refresh_pairs)
|
||||||
|
|
||||||
logger.info('Using stake_currency: %s ...', config['stake_currency'])
|
logger.info('Using stake_currency: %s ...', config['stake_currency'])
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
# pragma pylint: disable=missing-docstring,W0212
|
# pragma pylint: disable=missing-docstring,W0212
|
||||||
|
|
||||||
|
import logging
|
||||||
import math
|
import math
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
# from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
from freqtrade import exchange, optimize
|
from freqtrade import exchange, optimize
|
||||||
from freqtrade.exchange import Bittrex
|
from freqtrade.exchange import Bittrex
|
||||||
from freqtrade.optimize import preprocess
|
from freqtrade.optimize import preprocess
|
||||||
from freqtrade.optimize.backtesting import backtest, generate_text_table, get_timeframe
|
from freqtrade.optimize.backtesting import backtest, generate_text_table, get_timeframe
|
||||||
# import freqtrade.optimize.backtesting as backtesting
|
import freqtrade.optimize.backtesting as backtesting
|
||||||
|
|
||||||
|
|
||||||
def test_generate_text_table():
|
def test_generate_text_table():
|
||||||
@ -61,7 +62,6 @@ def test_backtest_1min_ticker_interval(default_conf, mocker):
|
|||||||
def trim_dictlist(dl, num):
|
def trim_dictlist(dl, num):
|
||||||
new = {}
|
new = {}
|
||||||
for pair, pair_data in dl.items():
|
for pair, pair_data in dl.items():
|
||||||
# Can't figure out why -num wont work
|
|
||||||
new[pair] = pair_data[num:]
|
new[pair] = pair_data[num:]
|
||||||
return new
|
return new
|
||||||
|
|
||||||
@ -148,21 +148,29 @@ def test_backtest_pricecontours(default_conf, mocker):
|
|||||||
for [contour, numres] in tests:
|
for [contour, numres] in tests:
|
||||||
simple_backtest(default_conf, contour, numres)
|
simple_backtest(default_conf, contour, numres)
|
||||||
|
|
||||||
# Please make this work, the load_config needs to be mocked
|
|
||||||
# and cleanups.
|
def mocked_load_data(pairs=[], ticker_interval=0, refresh_pairs=False):
|
||||||
# def test_backtest_start(default_conf, mocker):
|
tickerdata = optimize.load_tickerdata_file('BTC_UNITEST', 1)
|
||||||
# default_conf['exchange']['pair_whitelist'] = ['BTC_UNITEST']
|
pairdata = {'BTC_UNITEST': tickerdata}
|
||||||
# mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
return trim_dictlist(pairdata, -100)
|
||||||
# # see https://pypi.python.org/pypi/pytest-mock/
|
|
||||||
# # and http://www.voidspace.org.uk/python/mock/patch.html
|
|
||||||
# # No usage example of simple function mocking,
|
def test_backtest_start(default_conf, mocker, caplog):
|
||||||
# # and no documentation of side_effect
|
default_conf['exchange']['pair_whitelist'] = ['BTC_UNITEST']
|
||||||
# mocker.patch('freqtrade.misc.load_config', new=lambda s, t: {})
|
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||||
# args = MagicMock()
|
mocker.patch('freqtrade.misc.load_config', new=lambda s: default_conf)
|
||||||
# args.level = 10
|
mocker.patch.multiple('freqtrade.optimize',
|
||||||
# #load_config('foo')
|
load_data=mocked_load_data)
|
||||||
# backtesting.start(args)
|
args = MagicMock()
|
||||||
#
|
args.ticker_interval = 1
|
||||||
# Check what sideeffect backtstesting has done.
|
args.level = 10
|
||||||
# Probably need to capture standard-output and
|
args.live = False
|
||||||
# check for the generated report table.
|
backtesting.start(args)
|
||||||
|
# check the logs, that will contain the backtest result
|
||||||
|
exists = ['Using max_open_trades: 1 ...',
|
||||||
|
'Using stake_amount: 0.001 ...',
|
||||||
|
'Measuring data from 2017-11-14T21:17:00+00:00 up to 2017-11-14T22:59:00+00:00 ...']
|
||||||
|
for line in exists:
|
||||||
|
assert ('freqtrade.optimize.backtesting',
|
||||||
|
logging.INFO,
|
||||||
|
line) in caplog.record_tuples
|
||||||
|
Loading…
Reference in New Issue
Block a user