forked from twopirllc/pandas-ta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_indicator_statistics.py
124 lines (101 loc) · 4.2 KB
/
test_indicator_statistics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from .config import error_analysis, sample_data, CORRELATION, CORRELATION_THRESHOLD, VERBOSE
from .context import pandas_ta
from unittest import skip, TestCase
import pandas.testing as pdt
from pandas import DataFrame, Series
import talib as tal
class TestStatistics(TestCase):
@classmethod
def setUpClass(cls):
cls.data = sample_data
cls.data.columns = cls.data.columns.str.lower()
cls.open = cls.data["open"]
cls.high = cls.data["high"]
cls.low = cls.data["low"]
cls.close = cls.data["close"]
if "volume" in cls.data.columns:
cls.volume = cls.data["volume"]
@classmethod
def tearDownClass(cls):
del cls.open
del cls.high
del cls.low
del cls.close
if hasattr(cls, "volume"):
del cls.volume
del cls.data
def setUp(self): pass
def tearDown(self): pass
def test_entropy(self):
result = pandas_ta.entropy(self.close)
self.assertIsInstance(result, Series)
self.assertEqual(result.name, "ENTP_10")
def test_kurtosis(self):
result = pandas_ta.kurtosis(self.close)
self.assertIsInstance(result, Series)
self.assertEqual(result.name, "KURT_30")
def test_mad(self):
result = pandas_ta.mad(self.close)
self.assertIsInstance(result, Series)
self.assertEqual(result.name, "MAD_30")
def test_median(self):
result = pandas_ta.median(self.close)
self.assertIsInstance(result, Series)
self.assertEqual(result.name, "MEDIAN_30")
def test_quantile(self):
result = pandas_ta.quantile(self.close)
self.assertIsInstance(result, Series)
self.assertEqual(result.name, "QTL_30_0.5")
def test_skew(self):
result = pandas_ta.skew(self.close)
self.assertIsInstance(result, Series)
self.assertEqual(result.name, "SKEW_30")
def test_stdev(self):
result = pandas_ta.stdev(self.close, talib=False)
self.assertIsInstance(result, Series)
self.assertEqual(result.name, "STDEV_30")
try:
expected = tal.STDDEV(self.close, 30)
pdt.assert_series_equal(result, expected, check_names=False)
except AssertionError:
try:
corr = pandas_ta.utils.df_error_analysis(result, expected, col=CORRELATION)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
error_analysis(result, CORRELATION, ex)
result = pandas_ta.stdev(self.close)
self.assertIsInstance(result, Series)
self.assertEqual(result.name, "STDEV_30")
def test_tos_sdtevall(self):
result = pandas_ta.tos_stdevall(self.close)
self.assertIsInstance(result, DataFrame)
self.assertEqual(result.name, "TOS_STDEVALL")
self.assertEqual(len(result.columns), 7)
result = pandas_ta.tos_stdevall(self.close, length=30)
self.assertIsInstance(result, DataFrame)
self.assertEqual(result.name, "TOS_STDEVALL_30")
self.assertEqual(len(result.columns), 7)
result = pandas_ta.tos_stdevall(self.close, length=30, stds=[1, 2])
self.assertIsInstance(result, DataFrame)
self.assertEqual(result.name, "TOS_STDEVALL_30")
self.assertEqual(len(result.columns), 5)
def test_variance(self):
result = pandas_ta.variance(self.close, talib=False)
self.assertIsInstance(result, Series)
self.assertEqual(result.name, "VAR_30")
try:
expected = tal.VAR(self.close, 30)
pdt.assert_series_equal(result, expected, check_names=False)
except AssertionError:
try:
corr = pandas_ta.utils.df_error_analysis(result, expected, col=CORRELATION)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
error_analysis(result, CORRELATION, ex)
result = pandas_ta.variance(self.close)
self.assertIsInstance(result, Series)
self.assertEqual(result.name, "VAR_30")
def test_zscore(self):
result = pandas_ta.zscore(self.close)
self.assertIsInstance(result, Series)
self.assertEqual(result.name, "ZS_30")