refactoring tests

This commit is contained in:
Kevin Johnson
2019-02-28 10:40:19 -08:00
parent add843baa0
commit 061cb18f3d
5 changed files with 110 additions and 82 deletions
+47 -34
View File
@@ -51,10 +51,11 @@ class TestMomentum(TestCase):
pdt.assert_series_equal(apo, tal_apo, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(apo, tal_apo, col='corr')
col = 'corr'
corr = pandas_ta.utils.df_error_analysis(apo, tal_apo, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {apo.name}: {ex}")
print(f"\n [!] {apo.name}['{col}']: {ex}")
def test_bop(self):
bop = self.momentum.bop(self.open, self.high, self.low, self.close)
@@ -66,10 +67,11 @@ class TestMomentum(TestCase):
pdt.assert_series_equal(bop, tal_bop, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(bop, tal_bop, col='corr')
col = 'corr'
corr = pandas_ta.utils.df_error_analysis(bop, tal_bop, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {bop.name}: {ex}")
print(f"\n [!] {bop.name}['{col}']: {ex}")
def test_cci(self):
cci = self.momentum.cci(self.high, self.low, self.close)
@@ -81,10 +83,11 @@ class TestMomentum(TestCase):
pdt.assert_series_equal(cci, tal_cci, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(cci, tal_cci, col='corr')
col = 'corr'
corr = pandas_ta.utils.df_error_analysis(cci, tal_cci, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {cci.name}: {ex}")
print(f"\n [!] {cci.name}['{col}']: {ex}")
def test_cmo(self):
cmo = self.momentum.cmo(self.close)
@@ -96,10 +99,11 @@ class TestMomentum(TestCase):
pdt.assert_series_equal(cmo, tal_cmo, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(cmo, tal_cmo, col='corr')
col = 'corr'
corr = pandas_ta.utils.df_error_analysis(cmo, tal_cmo, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {cmo.name}: {ex}")
print(f"\n [!] {cmo.name}['{col}']: {ex}")
def test_coppock(self):
coppock = self.momentum.coppock(self.close)
@@ -121,23 +125,24 @@ class TestMomentum(TestCase):
tal_macddf = DataFrame({'MACD_12_26_9': tal_macd[0], 'MACDH_12_26_9': tal_macd[2], 'MACDS_12_26_9': tal_macd[1]})
pdt.assert_frame_equal(macd, tal_macddf)
except AssertionError as ae:
col = 'corr'
try:
macd_corr = pandas_ta.utils.df_error_analysis(macd.iloc[:,0], tal_macddf.iloc[:,0], col='corr')
macd_corr = pandas_ta.utils.df_error_analysis(macd.iloc[:,0], tal_macddf.iloc[:,0], col=col)
self.assertGreater(macd_corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {macd.iloc[:,0].name}: {ex}")
print(f"\n [!] {macd.iloc[:,0].name}['{col}']: {ex}")
try:
history_corr = pandas_ta.utils.df_error_analysis(macd.iloc[:,1], tal_macddf.iloc[:,1], col='corr')
history_corr = pandas_ta.utils.df_error_analysis(macd.iloc[:,1], tal_macddf.iloc[:,1], col=col)
self.assertGreater(history_corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {macd.iloc[:,1].name}: {ex}")
print(f"\n [!] {macd.iloc[:,1].name}['{col}']: {ex}")
try:
signal_corr = pandas_ta.utils.df_error_analysis(macd.iloc[:,2], tal_macddf.iloc[:,2], col='corr')
signal_corr = pandas_ta.utils.df_error_analysis(macd.iloc[:,2], tal_macddf.iloc[:,2], col=col)
self.assertGreater(signal_corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {macd.iloc[:,2].name}: {ex}")
print(f"\n [!] {macd.iloc[:,2].name}['{col}']: {ex}")
def test_mom(self):
mom = self.momentum.mom(self.close)
@@ -149,10 +154,11 @@ class TestMomentum(TestCase):
pdt.assert_series_equal(mom, tal_mom, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(mom, tal_mom, col='corr')
col = 'corr'
corr = pandas_ta.utils.df_error_analysis(mom, tal_mom, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {mom.name}: {ex}")
print(f"\n [!] {mom.name}['{col}']: {ex}")
def test_ppo(self):
ppo = self.momentum.ppo(self.close)
@@ -164,10 +170,11 @@ class TestMomentum(TestCase):
pdt.assert_series_equal(ppo['PPO_12_26_9'], tal_ppo, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(ppo['PPO_12_26_9'], tal_ppo, col='corr')
col='corr'
corr = pandas_ta.utils.df_error_analysis(ppo['PPO_12_26_9'], tal_ppo, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {ppo['PPO_12_26_9'].name}: {ex}")
print(f"\n [!] {ppo['PPO_12_26_9'].name}['{col}']: {ex}")
def test_roc(self):
roc = self.momentum.roc(self.close)
@@ -179,10 +186,11 @@ class TestMomentum(TestCase):
pdt.assert_series_equal(roc, tal_roc, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(roc, tal_roc, col='corr')
col='corr'
corr = pandas_ta.utils.df_error_analysis(roc, tal_roc, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {roc.name}: {ex}")
print(f"\n [!] {roc.name}['{col}']: {ex}")
def test_rsi(self):
rsi = self.momentum.rsi(self.close)
@@ -194,10 +202,11 @@ class TestMomentum(TestCase):
pdt.assert_series_equal(rsi, tal_rsi, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(rsi, tal_rsi, col='corr')
col='corr'
corr = pandas_ta.utils.df_error_analysis(rsi, tal_rsi, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {rsi.name}: {ex}")
print(f"\n [!] {rsi.name}['{col}']: {ex}")
def test_stoch(self):
stoch = self.momentum.stoch(self.high, self.low, self.close)
@@ -210,29 +219,31 @@ class TestMomentum(TestCase):
tal_stochdf = DataFrame({'STOCHF_14': tal_stochf[0], 'STOCHF_3': tal_stochf[1], 'STOCH_5': tal_stoch[0], 'STOCH_3': tal_stoch[1]})
pdt.assert_frame_equal(stoch, tal_stochdf)
except AssertionError as ae:
col='corr'
try:
stochfk_corr = pandas_ta.utils.df_error_analysis(stoch.iloc[:,0], tal_stochdf.iloc[:,0], col='corr')
col='corr'
stochfk_corr = pandas_ta.utils.df_error_analysis(stoch.iloc[:,0], tal_stochdf.iloc[:,0], col=col)
self.assertGreater(stochfk_corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {stoch.iloc[:,0].name}: {ex}")
print(f"\n [!] {stoch.iloc[:,0].name}['{col}']: {ex}")
try:
stochfd_corr = pandas_ta.utils.df_error_analysis(stoch.iloc[:,1], tal_stochdf.iloc[:,1], col='corr')
stochfd_corr = pandas_ta.utils.df_error_analysis(stoch.iloc[:,1], tal_stochdf.iloc[:,1], col=col)
self.assertGreater(stochfd_corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f" [!] {stoch.iloc[:,1].name}: {ex}")
print(f" [!] {stoch.iloc[:,1].name}['{col}']: {ex}")
try:
stochsk_corr = pandas_ta.utils.df_error_analysis(stoch.iloc[:,2], tal_stochdf.iloc[:,2], col='corr')
stochsk_corr = pandas_ta.utils.df_error_analysis(stoch.iloc[:,2], tal_stochdf.iloc[:,2], col=col)
self.assertGreater(stochsk_corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f" [!] {stoch.iloc[:,2].name}: {ex}")
print(f" [!] {stoch.iloc[:,2].name}['{col}']: {ex}")
try:
stochsd_corr = pandas_ta.utils.df_error_analysis(stoch.iloc[:,3], tal_stochdf.iloc[:,3], col='corr')
stochsd_corr = pandas_ta.utils.df_error_analysis(stoch.iloc[:,3], tal_stochdf.iloc[:,3], col=col)
self.assertGreater(stochsd_corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f" [!] {stoch.iloc[:,3].name}: {ex}")
print(f" [!] {stoch.iloc[:,3].name}['{col}']: {ex}")
def test_trix(self):
trix = self.momentum.trix(self.close)
@@ -254,10 +265,11 @@ class TestMomentum(TestCase):
pdt.assert_series_equal(uo, tal_uo, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(uo, tal_uo, col='corr')
col='corr'
corr = pandas_ta.utils.df_error_analysis(uo, tal_uo, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {uo.name}: {ex}")
print(f"\n [!] {uo.name}['{col}']: {ex}")
def test_willr(self):
willr = self.momentum.willr(self.high, self.low, self.close)
@@ -269,7 +281,8 @@ class TestMomentum(TestCase):
pdt.assert_series_equal(willr, tal_willr, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(willr, tal_willr, col='corr')
col='corr'
corr = pandas_ta.utils.df_error_analysis(willr, tal_willr, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {willr.name}: {ex}")
print(f"\n [!] {willr.name}['{col}']: {ex}")
+40 -31
View File
@@ -18,7 +18,6 @@ class TestOverlap(TestCase):
cls.low = cls.data['low']
cls.close = cls.data['close']
cls.volume = cls.data['volume']
cls.correlation_threshold = CORRELATION_THRESHOLD
@classmethod
def tearDownClass(cls):
@@ -47,10 +46,11 @@ class TestOverlap(TestCase):
pdt.assert_series_equal(dema, tal_dema, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(dema, tal_dema, col='corr')
self.assertGreater(corr, self.correlation_threshold)
col='corr'
corr = pandas_ta.utils.df_error_analysis(dema, tal_dema, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {dema.name}: {ex}")
print(f"\n [!] {dema.name}['{col}']: {ex}")
def test_ema(self):
ema = self.overlap.ema(self.close, presma=False)
@@ -62,10 +62,11 @@ class TestOverlap(TestCase):
pdt.assert_series_equal(ema, tal_ema, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(ema, tal_ema, col='corr')
self.assertGreater(corr, self.correlation_threshold)
col = 'corr'
corr = pandas_ta.utils.df_error_analysis(ema, tal_ema, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {ema.name}: {ex}")
print(f"\n [!] {ema.name}['{col}']: {ex}")
def test_fwma(self):
fwma = self.overlap.fwma(self.close)
@@ -87,10 +88,11 @@ class TestOverlap(TestCase):
pdt.assert_series_equal(hlc3, tal_typicalprice, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(hlc3, tal_typicalprice, col='corr')
self.assertGreater(corr, self.correlation_threshold)
col = 'corr'
corr = pandas_ta.utils.df_error_analysis(hlc3, tal_typicalprice, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {hlc3.name}: {ex}")
print(f"\n [!] {hlc3.name}['{col}']: {ex}")
def test_hma(self):
hma = self.overlap.hma(self.close)
@@ -114,10 +116,11 @@ class TestOverlap(TestCase):
pdt.assert_series_equal(midpoint, tal_midpoint, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(midpoint, tal_midpoint, col='corr')
self.assertGreater(corr, self.correlation_threshold)
col = 'corr'
corr = pandas_ta.utils.df_error_analysis(midpoint, tal_midpoint, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {midpoint.name}: {ex}")
print(f"\n [!] {midpoint.name}['{col}']: {ex}")
def test_midprice(self):
midprice = self.overlap.midprice(self.high, self.low)
@@ -129,10 +132,11 @@ class TestOverlap(TestCase):
pdt.assert_series_equal(midprice, tal_midprice, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(midprice, tal_midprice, col='corr')
self.assertGreater(corr, self.correlation_threshold)
col = 'corr'
corr = pandas_ta.utils.df_error_analysis(midprice, tal_midprice, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {midprice.name}: {ex}")
print(f"\n [!] {midprice.name}['{col}']: {ex}")
def test_ohlc4(self):
ohlc4 = self.overlap.ohlc4(self.open, self.high, self.low, self.close)
@@ -159,10 +163,11 @@ class TestOverlap(TestCase):
pdt.assert_series_equal(sma, tal_sma, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(sma, tal_sma, col='corr')
self.assertGreater(corr, self.correlation_threshold)
col = 'corr'
corr = pandas_ta.utils.df_error_analysis(sma, tal_sma, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {sma.name}: {ex}")
print(f"\n [!] {sma.name}['{col}']: {ex}")
def test_t3(self):
t3 = self.overlap.t3(self.close)
@@ -174,10 +179,11 @@ class TestOverlap(TestCase):
pdt.assert_series_equal(t3, tal_t3, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(t3, tal_t3, col='corr')
self.assertGreater(corr, self.correlation_threshold)
col = 'corr'
corr = pandas_ta.utils.df_error_analysis(t3, tal_t3, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {t3.name}: {ex}")
print(f"\n [!] {t3.name}['{col}']: {ex}")
def test_tema(self):
tema = self.overlap.tema(self.close)
@@ -189,10 +195,11 @@ class TestOverlap(TestCase):
pdt.assert_series_equal(tema, tal_tema, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(tema, tal_tema, col='corr')
self.assertGreater(corr, self.correlation_threshold)
col = 'corr'
corr = pandas_ta.utils.df_error_analysis(tema, tal_tema, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {tema.name}: {ex}")
print(f"\n [!] {tema.name}['{col}']: {ex}")
def test_trima(self):
trima = self.overlap.trima(self.close)
@@ -204,10 +211,11 @@ class TestOverlap(TestCase):
pdt.assert_series_equal(trima, tal_trima, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(trima, tal_trima, col='corr')
self.assertGreater(corr, self.correlation_threshold)
col = 'corr'
corr = pandas_ta.utils.df_error_analysis(trima, tal_trima, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {trima.name}: {ex}")
print(f"\n [!] {trima.name}['{col}']: {ex}")
def test_vwap(self):
vwap = self.overlap.vwap(self.high, self.low, self.close, self.volume)
@@ -229,7 +237,8 @@ class TestOverlap(TestCase):
pdt.assert_series_equal(wma, tal_wma, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(wma, tal_wma, col='corr')
self.assertGreater(corr, self.correlation_threshold)
col = 'corr'
corr = pandas_ta.utils.df_error_analysis(wma, tal_wma, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {wma.name}: {ex}")
print(f"\n [!] {wma.name}['{col}']: {ex}")
+1 -1
View File
@@ -1,5 +1,5 @@
from .context import pandas_ta
from .data import sample_data, CORRELATION_THRESHOLD, VERBOSE
from .data import sample_data
from unittest import TestCase
from pandas import Series
+6 -4
View File
@@ -71,10 +71,11 @@ class TestStatistics(TestCase):
pdt.assert_series_equal(stdev, tal_stdev, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(stdev, tal_stdev, col='corr')
col = 'corr'
corr = pandas_ta.utils.df_error_analysis(stdev, tal_stdev, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {stdev.name}: {ex}")
print(f"\n [!] {stdev.name}['{col}']: {ex}")
def test_variance(self):
variance = self.stats.variance(self.close)
@@ -86,10 +87,11 @@ class TestStatistics(TestCase):
pdt.assert_series_equal(variance, tal_variance, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(variance, tal_variance, col='corr')
col = 'corr'
corr = pandas_ta.utils.df_error_analysis(variance, tal_variance, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {variance.name}: {ex}")
print(f"\n [!] {variance.name}['{col}']: {ex}")
def test_zscore(self):
zscore = self.stats.zscore(self.close)
+16 -12
View File
@@ -51,10 +51,11 @@ class TestVolatility(TestCase):
pdt.assert_series_equal(atr, tal_atr, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(atr, tal_atr, col='corr')
col = 'corr'
corr = pandas_ta.utils.df_error_analysis(atr, tal_atr, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {atr.name}: {ex}")
print(f"\n [!] {atr.name}['{col}']: {ex}")
def test_bbands(self):
bbands = self.volatility.bbands(self.close)
@@ -66,23 +67,24 @@ class TestVolatility(TestCase):
tal_bbandsdf = DataFrame({'BBL_20': tal_bbands[0], 'BBM_20': tal_bbands[1], 'BBU_20': tal_bbands[2]})
pdt.assert_frame_equal(bbands, tal_bbandsdf)
except AssertionError as ae:
col = 'corr'
try:
bbl_corr = pandas_ta.utils.df_error_analysis(bbands.iloc[:,0], tal_bbandsdf.iloc[:,0], col='corr')
bbl_corr = pandas_ta.utils.df_error_analysis(bbands.iloc[:,0], tal_bbandsdf.iloc[:,0], col=col)
self.assertGreater(bbl_corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {bbands.iloc[:,0].name}: {ex}")
print(f"\n [!] {bbands.iloc[:,0].name}['{col}']: {ex}")
try:
bbm_corr = pandas_ta.utils.df_error_analysis(bbands.iloc[:,1], tal_bbandsdf.iloc[:,1], col='corr')
bbm_corr = pandas_ta.utils.df_error_analysis(bbands.iloc[:,1], tal_bbandsdf.iloc[:,1], col=col)
self.assertGreater(bbm_corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f" [!] {bbands.iloc[:,1].name}: {ex}")
print(f" [!] {bbands.iloc[:,1].name}['{col}']: {ex}")
try:
bbu_corr = pandas_ta.utils.df_error_analysis(bbands.iloc[:,2], tal_bbandsdf.iloc[:,2], col='corr')
bbu_corr = pandas_ta.utils.df_error_analysis(bbands.iloc[:,2], tal_bbandsdf.iloc[:,2], col=col)
self.assertGreater(bbu_corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f" [!] {bbands.iloc[:,2].name}: {ex}")
print(f" [!] {bbands.iloc[:,2].name}['{col}']: {ex}")
def test_donchian(self):
donchian = self.volatility.donchian(self.close)
@@ -109,10 +111,11 @@ class TestVolatility(TestCase):
pdt.assert_series_equal(natr, tal_natr, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(natr, tal_natr, col='corr')
col = 'corr'
corr = pandas_ta.utils.df_error_analysis(natr, tal_natr, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {natr.name}: {ex}")
print(f"\n [!] {natr.name}['{col}']: {ex}")
def test_true_range(self):
true_range = self.volatility.true_range(self.high, self.low, self.close)
@@ -124,7 +127,8 @@ class TestVolatility(TestCase):
pdt.assert_series_equal(true_range, tal_true_range, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(true_range, tal_true_range, col='corr')
col = 'corr'
corr = pandas_ta.utils.df_error_analysis(true_range, tal_true_range, col=col)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
print(f"\n [!] {true_range.name}: {ex}")
print(f"\n [!] {true_range.name}['{col}']: {ex}")