tests: anal stretching to accomodate flake8
This commit is contained in:
parent
f48f5d0f31
commit
ab112581a7
@ -1,5 +1,3 @@
|
|||||||
# pragma pylint: disable=missing-docstring,W0212
|
|
||||||
|
|
||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
@ -129,6 +127,7 @@ def trim_dataframe(df, num):
|
|||||||
new[pair] = pair_data[-num:] # last 50 rows
|
new[pair] = pair_data[-num:] # last 50 rows
|
||||||
return new
|
return new
|
||||||
|
|
||||||
|
|
||||||
def load_data_test(what):
|
def load_data_test(what):
|
||||||
data = optimize.load_data(ticker_interval=1, pairs=['BTC_UNITEST'])
|
data = optimize.load_data(ticker_interval=1, pairs=['BTC_UNITEST'])
|
||||||
data = trim_dataframe(data, -40)
|
data = trim_dataframe(data, -40)
|
||||||
@ -136,63 +135,66 @@ def load_data_test(what):
|
|||||||
|
|
||||||
# Depending on the what parameter we now adjust the
|
# Depending on the what parameter we now adjust the
|
||||||
# loaded data:
|
# loaded data:
|
||||||
# pair :: [{'O': 0.123, 'H': 0.123, 'L': 0.123, 'C': 0.123, 'V': 123.123, 'T': '2017-11-04T23:02:00', 'BV': 0.123}]
|
# pair :: [{'O': 0.123, 'H': 0.123, 'L': 0.123,
|
||||||
|
# 'C': 0.123, 'V': 123.123,
|
||||||
|
# 'T': '2017-11-04T23:02:00', 'BV': 0.123}]
|
||||||
if what == 'raise':
|
if what == 'raise':
|
||||||
o = h = l = c = 0.001
|
o = 0.001
|
||||||
l -= 0.0001
|
h = 0.001
|
||||||
|
ll = 0.001
|
||||||
|
c = 0.001
|
||||||
|
ll -= 0.0001
|
||||||
h += 0.0001
|
h += 0.0001
|
||||||
for frame in pair:
|
for frame in pair:
|
||||||
o += 0.0001
|
o += 0.0001
|
||||||
h += 0.0001
|
h += 0.0001
|
||||||
l += 0.0001
|
ll += 0.0001
|
||||||
c += 0.0001
|
c += 0.0001
|
||||||
o = round(o,9) # round to satoshis
|
# save prices rounded to satoshis
|
||||||
h = round(h,9)
|
frame['O'] = round(o, 9)
|
||||||
l = round(l,9)
|
frame['H'] = round(h, 9)
|
||||||
c = round(c,9)
|
frame['L'] = round(ll, 9)
|
||||||
frame['O'] = o
|
frame['C'] = round(c, 9)
|
||||||
frame['H'] = h
|
|
||||||
frame['L'] = l
|
|
||||||
frame['C'] = c
|
|
||||||
if what == 'lower':
|
if what == 'lower':
|
||||||
o = h = l = c = 0.001
|
o = 0.001
|
||||||
l -= 0.0001
|
h = 0.001
|
||||||
|
ll = 0.001
|
||||||
|
c = 0.001
|
||||||
|
ll -= 0.0001
|
||||||
h += 0.0001
|
h += 0.0001
|
||||||
for frame in pair:
|
for frame in pair:
|
||||||
o -= 0.0001
|
o -= 0.0001
|
||||||
h -= 0.0001
|
h -= 0.0001
|
||||||
l -= 0.0001
|
ll -= 0.0001
|
||||||
c -= 0.0001
|
c -= 0.0001
|
||||||
o = round(o,9) # round to satoshis
|
# save prices rounded to satoshis
|
||||||
h = round(h,9)
|
frame['O'] = round(o, 9)
|
||||||
l = round(l,9)
|
frame['H'] = round(h, 9)
|
||||||
c = round(c,9)
|
frame['L'] = round(ll, 9)
|
||||||
frame['O'] = o
|
frame['C'] = round(c, 9)
|
||||||
frame['H'] = h
|
|
||||||
frame['L'] = l
|
|
||||||
frame['C'] = c
|
|
||||||
if what == 'sine':
|
if what == 'sine':
|
||||||
i = 0
|
i = 0
|
||||||
o = h = l = c = (2 + math.sin(i/10)) / 1000
|
o = (2 + math.sin(i/10)) / 1000
|
||||||
|
h = o
|
||||||
|
ll = o
|
||||||
|
c = o
|
||||||
h += 0.0001
|
h += 0.0001
|
||||||
l -= 0.0001
|
ll -= 0.0001
|
||||||
for frame in pair:
|
for frame in pair:
|
||||||
o = (2 + math.sin(i/10)) / 1000
|
o = (2 + math.sin(i/10)) / 1000
|
||||||
h = (2 + math.sin(i/10)) / 1000 + 0.0001
|
h = (2 + math.sin(i/10)) / 1000 + 0.0001
|
||||||
l = (2 + math.sin(i/10)) / 1000 - 0.0001
|
ll = (2 + math.sin(i/10)) / 1000 - 0.0001
|
||||||
c = (2 + math.sin(i/10)) / 1000 - 0.000001
|
c = (2 + math.sin(i/10)) / 1000 - 0.000001
|
||||||
|
|
||||||
o = round(o,9) # round to satoshis
|
# save prices rounded to satoshis
|
||||||
h = round(h,9)
|
frame['O'] = round(o, 9)
|
||||||
l = round(l,9)
|
frame['H'] = round(h, 9)
|
||||||
c = round(c,9)
|
frame['L'] = round(ll, 9)
|
||||||
frame['O'] = o
|
frame['C'] = round(c, 9)
|
||||||
frame['H'] = h
|
|
||||||
frame['L'] = l
|
|
||||||
frame['C'] = c
|
|
||||||
i += 1
|
i += 1
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def simple_backtest(config, contour, num_results):
|
def simple_backtest(config, contour, num_results):
|
||||||
data = load_data_test(contour)
|
data = load_data_test(contour)
|
||||||
processed = optimize.preprocess(data)
|
processed = optimize.preprocess(data)
|
||||||
@ -204,23 +206,23 @@ def simple_backtest(config, contour, num_results):
|
|||||||
# Test backtest on offline data
|
# Test backtest on offline data
|
||||||
# loaded by freqdata/optimize/__init__.py::load_data()
|
# loaded by freqdata/optimize/__init__.py::load_data()
|
||||||
|
|
||||||
def test_backtest(default_conf, mocker):
|
|
||||||
|
def test_backtest2(default_conf, mocker):
|
||||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||||
data = optimize.load_data(ticker_interval=5, pairs=['BTC_ETH'])
|
data = optimize.load_data(ticker_interval=5, pairs=['BTC_ETH'])
|
||||||
results = backtest(default_conf['stake_amount'], optimize.preprocess(data), 10, True)
|
results = backtest(default_conf['stake_amount'], optimize.preprocess(data), 10, True)
|
||||||
num_resutls = len(results)
|
num_resutls = len(results)
|
||||||
assert num_resutls > 0
|
assert num_resutls > 0
|
||||||
|
|
||||||
|
|
||||||
def test_processed(default_conf, mocker):
|
def test_processed(default_conf, mocker):
|
||||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||||
data = load_data_test('raise')
|
data = load_data_test('raise')
|
||||||
processed = optimize.preprocess(data)
|
assert optimize.preprocess(data)
|
||||||
|
|
||||||
|
|
||||||
def test_raise(default_conf, mocker):
|
def test_raise(default_conf, mocker):
|
||||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||||
tests = [['raise', 359], ['lower', 0], ['sine', 1734]]
|
tests = [['raise', 359], ['lower', 0], ['sine', 1734]]
|
||||||
for [contour, numres] in tests:
|
for [contour, numres] in tests:
|
||||||
simple_backtest(default_conf, contour, numres)
|
simple_backtest(default_conf, contour, numres)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,24 +1,17 @@
|
|||||||
|
from freqtrade.main import refresh_whitelist
|
||||||
|
|
||||||
# whitelist, blacklist, filtering, all of that will
|
# whitelist, blacklist, filtering, all of that will
|
||||||
# eventually become some rules to run on a generic ACL engine
|
# eventually become some rules to run on a generic ACL engine
|
||||||
|
|
||||||
# perhaps try to anticipate that by using some python package
|
# perhaps try to anticipate that by using some python package
|
||||||
|
|
||||||
import pytest
|
|
||||||
from unittest.mock import MagicMock
|
|
||||||
import copy
|
|
||||||
|
|
||||||
from freqtrade.main import refresh_whitelist
|
|
||||||
#from freqtrade.exchange import Exchanges
|
|
||||||
from freqtrade import exchange
|
|
||||||
|
|
||||||
# "deep equal"
|
|
||||||
def assert_list_equal(l1, l2):
|
def assert_list_equal(l1, l2):
|
||||||
for pair in l1:
|
for pair in l1:
|
||||||
assert pair in l2
|
assert pair in l2
|
||||||
for pair in l2:
|
for pair in l2:
|
||||||
assert pair in l1
|
assert pair in l1
|
||||||
|
|
||||||
|
|
||||||
def whitelist_conf():
|
def whitelist_conf():
|
||||||
return {
|
return {
|
||||||
"stake_currency": "BTC",
|
"stake_currency": "BTC",
|
||||||
@ -33,6 +26,7 @@ def whitelist_conf():
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_health():
|
def get_health():
|
||||||
return [{'Currency': 'ETH',
|
return [{'Currency': 'ETH',
|
||||||
'IsActive': True
|
'IsActive': True
|
||||||
@ -41,12 +35,14 @@ def get_health():
|
|||||||
'IsActive': True
|
'IsActive': True
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
|
||||||
def get_health_empty():
|
def get_health_empty():
|
||||||
return []
|
return []
|
||||||
|
|
||||||
# below three test could be merged into a single
|
# below three test could be merged into a single
|
||||||
# test that ran randomlly generated health lists
|
# test that ran randomlly generated health lists
|
||||||
|
|
||||||
|
|
||||||
def test_refresh_whitelist(mocker):
|
def test_refresh_whitelist(mocker):
|
||||||
conf = whitelist_conf()
|
conf = whitelist_conf()
|
||||||
mocker.patch.dict('freqtrade.main._CONF', conf)
|
mocker.patch.dict('freqtrade.main._CONF', conf)
|
||||||
@ -59,6 +55,7 @@ def test_refresh_whitelist(mocker):
|
|||||||
# Ensure all except those in whitelist are removed
|
# Ensure all except those in whitelist are removed
|
||||||
assert_list_equal(whitelist, pairslist)
|
assert_list_equal(whitelist, pairslist)
|
||||||
|
|
||||||
|
|
||||||
def test_refresh_whitelist_dynamic(mocker):
|
def test_refresh_whitelist_dynamic(mocker):
|
||||||
conf = whitelist_conf()
|
conf = whitelist_conf()
|
||||||
mocker.patch.dict('freqtrade.main._CONF', conf)
|
mocker.patch.dict('freqtrade.main._CONF', conf)
|
||||||
@ -70,6 +67,7 @@ def test_refresh_whitelist_dynamic(mocker):
|
|||||||
pairslist = conf['exchange']['pair_whitelist']
|
pairslist = conf['exchange']['pair_whitelist']
|
||||||
assert_list_equal(whitelist, pairslist)
|
assert_list_equal(whitelist, pairslist)
|
||||||
|
|
||||||
|
|
||||||
def test_refresh_whitelist_dynamic_empty(mocker):
|
def test_refresh_whitelist_dynamic_empty(mocker):
|
||||||
conf = whitelist_conf()
|
conf = whitelist_conf()
|
||||||
mocker.patch.dict('freqtrade.main._CONF', conf)
|
mocker.patch.dict('freqtrade.main._CONF', conf)
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
|
|
||||||
import pytest
|
|
||||||
import pandas
|
import pandas
|
||||||
|
|
||||||
from freqtrade import analyze
|
from freqtrade import analyze
|
||||||
import freqtrade.optimize
|
import freqtrade.optimize
|
||||||
from pandas import DataFrame
|
|
||||||
|
|
||||||
_pairs = ['BTC_ETH']
|
_pairs = ['BTC_ETH']
|
||||||
|
|
||||||
|
|
||||||
def load_dataframe_pair(pairs):
|
def load_dataframe_pair(pairs):
|
||||||
ld = freqtrade.optimize.load_data(ticker_interval=5, pairs=pairs)
|
ld = freqtrade.optimize.load_data(ticker_interval=5, pairs=pairs)
|
||||||
assert isinstance(ld, dict)
|
assert isinstance(ld, dict)
|
||||||
@ -16,10 +14,12 @@ def load_dataframe_pair(pairs):
|
|||||||
dataframe = analyze.analyze_ticker(dataframe)
|
dataframe = analyze.analyze_ticker(dataframe)
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
|
|
||||||
def test_dataframe_load():
|
def test_dataframe_load():
|
||||||
dataframe = load_dataframe_pair(_pairs)
|
dataframe = load_dataframe_pair(_pairs)
|
||||||
assert isinstance(dataframe, pandas.core.frame.DataFrame)
|
assert isinstance(dataframe, pandas.core.frame.DataFrame)
|
||||||
|
|
||||||
|
|
||||||
def test_dataframe_columns_exists():
|
def test_dataframe_columns_exists():
|
||||||
dataframe = load_dataframe_pair(_pairs)
|
dataframe = load_dataframe_pair(_pairs)
|
||||||
assert 'high' in dataframe.columns
|
assert 'high' in dataframe.columns
|
||||||
|
Loading…
Reference in New Issue
Block a user