mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +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
|
||||
|
||||
import math
|
||||
import random
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock
|
||||
|
@ -14,7 +13,7 @@ from freqtrade import DependencyException, OperationalException, constants
|
|||
from freqtrade.configuration import TimeRange
|
||||
from freqtrade.data import history
|
||||
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.history import get_timerange
|
||||
from freqtrade.optimize import setup_configuration, start_backtesting
|
||||
|
@ -50,47 +49,33 @@ def trim_dictlist(dict_list, num):
|
|||
|
||||
def load_data_test(what, testdatadir):
|
||||
timerange = TimeRange.parse_timerange('1510694220-1510700340')
|
||||
pair = history.load_tickerdata_file(testdatadir, timeframe='1m',
|
||||
pair='UNITTEST/BTC', timerange=timerange)
|
||||
datalen = len(pair)
|
||||
data = history.load_pair_history(pair='UNITTEST/BTC', datadir=testdatadir,
|
||||
timeframe='1m', timerange=timerange,
|
||||
drop_incomplete=False,
|
||||
fill_up_missing=False)
|
||||
|
||||
base = 0.001
|
||||
if what == 'raise':
|
||||
data = [
|
||||
[
|
||||
pair[x][0], # Keep old dates
|
||||
x * base, # But replace O,H,L,C
|
||||
x * base + 0.0001,
|
||||
x * base - 0.0001,
|
||||
x * base,
|
||||
pair[x][5], # Keep old volume
|
||||
] for x in range(0, datalen)
|
||||
]
|
||||
data.loc[:, 'open'] = data.index * base
|
||||
data.loc[:, 'high'] = data.index * base + 0.0001
|
||||
data.loc[:, 'low'] = data.index * base - 0.0001
|
||||
data.loc[:, 'close'] = data.index * base
|
||||
|
||||
if what == 'lower':
|
||||
data = [
|
||||
[
|
||||
pair[x][0], # Keep old dates
|
||||
1 - x * base, # But replace O,H,L,C
|
||||
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)
|
||||
]
|
||||
data.loc[:, 'open'] = 1 - data.index * base
|
||||
data.loc[:, 'high'] = 1 - data.index * base + 0.0001
|
||||
data.loc[:, 'low'] = 1 - data.index * base - 0.0001
|
||||
data.loc[:, 'close'] = 1 - data.index * base
|
||||
|
||||
if what == 'sine':
|
||||
hz = 0.1 # frequency
|
||||
data = [
|
||||
[
|
||||
pair[x][0], # Keep old dates
|
||||
math.sin(x * hz) / 1000 + base, # But replace O,H,L,C
|
||||
math.sin(x * hz) / 1000 + base + 0.0001,
|
||||
math.sin(x * hz) / 1000 + base - 0.0001,
|
||||
math.sin(x * hz) / 1000 + base,
|
||||
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)}
|
||||
data.loc[:, 'open'] = np.sin(data.index * hz) / 1000 + base
|
||||
data.loc[:, 'high'] = np.sin(data.index * hz) / 1000 + base + 0.0001
|
||||
data.loc[:, 'low'] = np.sin(data.index * hz) / 1000 + base - 0.0001
|
||||
data.loc[:, 'close'] = np.sin(data.index * hz) / 1000 + base
|
||||
|
||||
return {'UNITTEST/BTC': clean_ohlcv_dataframe(data, timeframe='1m', pair='UNITTEST/BTC',
|
||||
fill_missing=True)}
|
||||
|
||||
|
||||
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:
|
||||
patch_exchange(mocker)
|
||||
timerange = TimeRange.parse_timerange('1510694220-1510700340')
|
||||
tick = history.load_tickerdata_file(testdatadir, 'UNITTEST/BTC', '1m', timerange=timerange)
|
||||
tickerlist = {'UNITTEST/BTC': parse_ticker_dataframe(tick, '1m', pair="UNITTEST/BTC",
|
||||
fill_missing=True)}
|
||||
|
||||
tickerlist = history.load_data(testdatadir, '1m', ['UNITTEST/BTC'], timerange=timerange,
|
||||
fill_up_missing=True)
|
||||
backtesting = Backtesting(default_conf)
|
||||
data = backtesting.strategy.tickerdata_to_dataframe(tickerlist)
|
||||
assert len(data['UNITTEST/BTC']) == 102
|
||||
|
|
Loading…
Reference in New Issue
Block a user