mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-14 04:03:55 +00:00
Clean up some codes which use list-based tests
This commit is contained in:
parent
80dbba1280
commit
5479c67178
|
@ -1,6 +1,5 @@
|
||||||
# pragma pylint: disable=missing-docstring, W0212, line-too-long, C0103, unused-argument
|
# pragma pylint: disable=missing-docstring, W0212, line-too-long, C0103, unused-argument
|
||||||
|
|
||||||
import math
|
|
||||||
import random
|
import random
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
@ -14,7 +13,7 @@ from freqtrade import DependencyException, OperationalException, constants
|
||||||
from freqtrade.configuration import TimeRange
|
from freqtrade.configuration import TimeRange
|
||||||
from freqtrade.data import history
|
from freqtrade.data import history
|
||||||
from freqtrade.data.btanalysis import evaluate_result_multi
|
from freqtrade.data.btanalysis import evaluate_result_multi
|
||||||
from freqtrade.data.converter import parse_ticker_dataframe
|
from freqtrade.data.converter import clean_ohlcv_dataframe
|
||||||
from freqtrade.data.dataprovider import DataProvider
|
from freqtrade.data.dataprovider import DataProvider
|
||||||
from freqtrade.data.history import get_timerange
|
from freqtrade.data.history import get_timerange
|
||||||
from freqtrade.optimize import setup_configuration, start_backtesting
|
from freqtrade.optimize import setup_configuration, start_backtesting
|
||||||
|
@ -50,47 +49,33 @@ def trim_dictlist(dict_list, num):
|
||||||
|
|
||||||
def load_data_test(what, testdatadir):
|
def load_data_test(what, testdatadir):
|
||||||
timerange = TimeRange.parse_timerange('1510694220-1510700340')
|
timerange = TimeRange.parse_timerange('1510694220-1510700340')
|
||||||
pair = history.load_tickerdata_file(testdatadir, timeframe='1m',
|
data = history.load_pair_history(pair='UNITTEST/BTC', datadir=testdatadir,
|
||||||
pair='UNITTEST/BTC', timerange=timerange)
|
timeframe='1m', timerange=timerange,
|
||||||
datalen = len(pair)
|
drop_incomplete=False,
|
||||||
|
fill_up_missing=False)
|
||||||
|
|
||||||
base = 0.001
|
base = 0.001
|
||||||
if what == 'raise':
|
if what == 'raise':
|
||||||
data = [
|
data.loc[:, 'open'] = data.index * base
|
||||||
[
|
data.loc[:, 'high'] = data.index * base + 0.0001
|
||||||
pair[x][0], # Keep old dates
|
data.loc[:, 'low'] = data.index * base - 0.0001
|
||||||
x * base, # But replace O,H,L,C
|
data.loc[:, 'close'] = data.index * base
|
||||||
x * base + 0.0001,
|
|
||||||
x * base - 0.0001,
|
|
||||||
x * base,
|
|
||||||
pair[x][5], # Keep old volume
|
|
||||||
] for x in range(0, datalen)
|
|
||||||
]
|
|
||||||
if what == 'lower':
|
if what == 'lower':
|
||||||
data = [
|
data.loc[:, 'open'] = 1 - data.index * base
|
||||||
[
|
data.loc[:, 'high'] = 1 - data.index * base + 0.0001
|
||||||
pair[x][0], # Keep old dates
|
data.loc[:, 'low'] = 1 - data.index * base - 0.0001
|
||||||
1 - x * base, # But replace O,H,L,C
|
data.loc[:, 'close'] = 1 - data.index * base
|
||||||
1 - x * base + 0.0001,
|
|
||||||
1 - x * base - 0.0001,
|
|
||||||
1 - x * base,
|
|
||||||
pair[x][5] # Keep old volume
|
|
||||||
] for x in range(0, datalen)
|
|
||||||
]
|
|
||||||
if what == 'sine':
|
if what == 'sine':
|
||||||
hz = 0.1 # frequency
|
hz = 0.1 # frequency
|
||||||
data = [
|
data.loc[:, 'open'] = np.sin(data.index * hz) / 1000 + base
|
||||||
[
|
data.loc[:, 'high'] = np.sin(data.index * hz) / 1000 + base + 0.0001
|
||||||
pair[x][0], # Keep old dates
|
data.loc[:, 'low'] = np.sin(data.index * hz) / 1000 + base - 0.0001
|
||||||
math.sin(x * hz) / 1000 + base, # But replace O,H,L,C
|
data.loc[:, 'close'] = np.sin(data.index * hz) / 1000 + base
|
||||||
math.sin(x * hz) / 1000 + base + 0.0001,
|
|
||||||
math.sin(x * hz) / 1000 + base - 0.0001,
|
return {'UNITTEST/BTC': clean_ohlcv_dataframe(data, timeframe='1m', pair='UNITTEST/BTC',
|
||||||
math.sin(x * hz) / 1000 + base,
|
fill_missing=True)}
|
||||||
pair[x][5] # Keep old volume
|
|
||||||
] for x in range(0, datalen)
|
|
||||||
]
|
|
||||||
return {'UNITTEST/BTC': parse_ticker_dataframe(data, '1m', pair="UNITTEST/BTC",
|
|
||||||
fill_missing=True)}
|
|
||||||
|
|
||||||
|
|
||||||
def simple_backtest(config, contour, num_results, mocker, testdatadir) -> None:
|
def simple_backtest(config, contour, num_results, mocker, testdatadir) -> None:
|
||||||
|
@ -328,10 +313,8 @@ def test_tickerdata_with_fee(default_conf, mocker, testdatadir) -> None:
|
||||||
def test_tickerdata_to_dataframe_bt(default_conf, mocker, testdatadir) -> None:
|
def test_tickerdata_to_dataframe_bt(default_conf, mocker, testdatadir) -> None:
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
timerange = TimeRange.parse_timerange('1510694220-1510700340')
|
timerange = TimeRange.parse_timerange('1510694220-1510700340')
|
||||||
tick = history.load_tickerdata_file(testdatadir, 'UNITTEST/BTC', '1m', timerange=timerange)
|
tickerlist = history.load_data(testdatadir, '1m', ['UNITTEST/BTC'], timerange=timerange,
|
||||||
tickerlist = {'UNITTEST/BTC': parse_ticker_dataframe(tick, '1m', pair="UNITTEST/BTC",
|
fill_up_missing=True)
|
||||||
fill_missing=True)}
|
|
||||||
|
|
||||||
backtesting = Backtesting(default_conf)
|
backtesting = Backtesting(default_conf)
|
||||||
data = backtesting.strategy.tickerdata_to_dataframe(tickerlist)
|
data = backtesting.strategy.tickerdata_to_dataframe(tickerlist)
|
||||||
assert len(data['UNITTEST/BTC']) == 102
|
assert len(data['UNITTEST/BTC']) == 102
|
||||||
|
|
Loading…
Reference in New Issue
Block a user