From b4c337f7d1eda38d3b455e3473206783e953010a Mon Sep 17 00:00:00 2001 From: Dario Lopez Padial Date: Tue, 10 Dec 2019 20:29:29 +0100 Subject: [PATCH] adding kama indicator tests --- ta/tests/__init__.py | 7 +++--- ta/tests/data/cs-kama.csv | 50 +++++++++++++++++++++++++++++++++++++++ ta/tests/momentum.py | 26 +++++++++++++++++--- 3 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 ta/tests/data/cs-kama.csv diff --git a/ta/tests/__init__.py b/ta/tests/__init__.py index df6f2af5..69f50782 100644 --- a/ta/tests/__init__.py +++ b/ta/tests/__init__.py @@ -1,10 +1,11 @@ -from ta.tests.momentum import (TestMFIIndicator, TestRateOfChangeIndicator, - TestRSIIndicator, TestStochasticOscillator, +from ta.tests.momentum import (TestKAMA, TestMFIIndicator, + TestRateOfChangeIndicator, TestRSIIndicator, + TestStochasticOscillator, TestUltimateOscillator, TestWilliamsRIndicator) from ta.tests.trend import (TestADXIndicator, TestCCIIndicator, TestMACDIndicator, TestPSARIndicator, TestVortexIndicator) -from ta.tests.utils import TestGeneral +# from ta.tests.utils import TestGeneral from ta.tests.volatility import TestAverageTrueRange, TestBollingerBands from ta.tests.volume import (TestAccDistIndexIndicator, TestEaseOfMovementIndicator, diff --git a/ta/tests/data/cs-kama.csv b/ta/tests/data/cs-kama.csv new file mode 100644 index 00000000..e0fb22c2 --- /dev/null +++ b/ta/tests/data/cs-kama.csv @@ -0,0 +1,50 @@ +Date,Close,ABS (Close - Close 10 periods ago),ABS (Close - Prior Close),ER,2/(fastest + 1),2/(slowest + 1),SC,KAMA +28/05/2015,110.460000,,,,,,, +29/05/2015,109.800000,,0.660000,,,,, +01/06/2015,110.170000,,0.370000,,,,, +02/06/2015,109.820000,,0.350000,,,,, +03/06/2015,110.150000,,0.330000,,,,, +04/06/2015,109.310000,,0.840000,,,,, +05/06/2015,109.050000,,0.260000,,,,, +08/06/2015,107.940000,,1.110000,,,,, +09/06/2015,107.760000,,0.180000,,,,, +10/06/2015,109.240000,,1.480000,,,,,109.240000 +11/06/2015,109.400000,1.060000,0.160000,0.184669,0.064516,0.666667,0.030876,109.244940 +12/06/2015,108.500000,1.300000,0.900000,0.217391,0.064516,0.666667,0.038188,109.216492 +15/06/2015,107.960000,2.210000,0.540000,0.359350,0.064516,0.666667,0.078904,109.117350 +16/06/2015,108.550000,1.270000,0.590000,0.198748,0.064516,0.666667,0.033927,109.098101 +17/06/2015,108.850000,1.300000,0.300000,0.204403,0.064516,0.666667,0.035193,109.089370 +18/06/2015,110.440000,1.130000,1.590000,0.158931,0.064516,0.666667,0.025669,109.124040 +19/06/2015,109.890000,0.840000,0.550000,0.113514,0.064516,0.666667,0.017654,109.137562 +22/06/2015,110.700000,2.760000,0.810000,0.388732,0.064516,0.666667,0.089157,109.276864 +23/06/2015,110.790000,3.030000,0.090000,0.432240,0.064516,0.666667,0.105488,109.436482 +24/06/2015,110.220000,0.980000,0.570000,0.160656,0.064516,0.666667,0.026003,109.456856 +25/06/2015,110.000000,0.600000,0.220000,0.097403,0.064516,0.666667,0.015170,109.465096 +26/06/2015,109.270000,0.770000,0.730000,0.128548,0.064516,0.666667,0.020142,109.461166 +29/06/2015,106.690000,1.270000,2.580000,0.158157,0.064516,0.666667,0.025520,109.390445 +30/06/2015,107.070000,1.480000,0.380000,0.189258,0.064516,0.666667,0.031854,109.316529 +01/07/2015,107.920000,0.930000,0.850000,0.111111,0.064516,0.666667,0.017272,109.292409 +02/07/2015,107.950000,2.490000,0.030000,0.365639,0.064516,0.666667,0.081046,109.183612 +06/07/2015,107.700000,2.190000,0.250000,0.336406,0.064516,0.666667,0.071333,109.077781 +07/07/2015,107.970000,2.730000,0.270000,0.457286,0.064516,0.666667,0.115513,108.949818 +08/07/2015,106.090000,4.700000,1.880000,0.605670,0.064516,0.666667,0.184230,108.422953 +09/07/2015,106.030000,4.190000,0.060000,0.577931,0.064516,0.666667,0.170171,108.015742 +10/07/2015,107.650000,2.350000,1.620000,0.271676,0.064516,0.666667,0.052032,107.996712 +13/07/2015,109.540000,0.270000,1.890000,0.027523,0.064516,0.666667,0.006575,108.006859 +14/07/2015,110.260000,3.570000,0.720000,0.449057,0.064516,0.666667,0.112169,108.259591 +15/07/2015,110.380000,3.310000,0.120000,0.430429,0.064516,0.666667,0.104781,108.481770 +16/07/2015,111.940000,4.020000,1.560000,0.478571,0.064516,0.666667,0.124389,108.911936 +17/07/2015,113.590000,5.640000,1.650000,0.562874,0.064516,0.666667,0.162773,109.673398 +20/07/2015,113.980000,6.280000,0.390000,0.618110,0.064516,0.666667,0.190717,110.494740 +21/07/2015,113.910000,5.940000,0.070000,0.596386,0.064516,0.666667,0.179462,111.107650 +22/07/2015,112.620000,6.530000,1.290000,0.696905,0.064516,0.666667,0.234409,111.462159 +23/07/2015,112.200000,6.170000,0.420000,0.634121,0.064516,0.666667,0.199231,111.609159 +24/07/2015,111.100000,3.450000,1.100000,0.374593,0.064516,0.666667,0.084145,111.566316 +27/07/2015,110.180000,0.640000,0.920000,0.077670,0.064516,0.666667,0.012384,111.549147 +28/07/2015,111.130000,0.870000,0.950000,0.102715,0.064516,0.666667,0.015968,111.542454 +29/07/2015,111.550000,1.170000,0.420000,0.133409,0.064516,0.666667,0.020981,111.542613 +30/07/2015,112.080000,0.140000,0.530000,0.018088,0.064516,0.666667,0.005686,111.545668 +31/07/2015,111.950000,1.640000,0.130000,0.263666,0.064516,0.666667,0.049855,111.565826 +03/08/2015,111.600000,2.380000,0.350000,0.385113,0.064516,0.666667,0.087860,111.568829 +04/08/2015,111.390000,2.520000,0.210000,0.398734,0.064516,0.666667,0.092790,111.552235 +05/08/2015,112.250000,0.370000,0.860000,0.062818,0.064516,0.666667,0.010474,111.559544 diff --git a/ta/tests/momentum.py b/ta/tests/momentum.py index 5aaac903..87be36a1 100644 --- a/ta/tests/momentum.py +++ b/ta/tests/momentum.py @@ -2,9 +2,9 @@ import pandas as pd -from ta.momentum import (MFIIndicator, ROCIndicator, RSIIndicator, - StochasticOscillator, UltimateOscillator, - WilliamsRIndicator, roc) +from ta.momentum import (KAMAIndicator, MFIIndicator, ROCIndicator, + RSIIndicator, StochasticOscillator, + UltimateOscillator, WilliamsRIndicator, roc) from ta.tests.utils import TestIndicator @@ -136,3 +136,23 @@ def test_wr(self): target = 'Williams_%R' result = self._indicator.wr() pd.testing.assert_series_equal(self._df[target].tail(), result.tail(), check_names=False) + + +class TestKAMA(unittest.TestCase): + """ + https://school.stockcharts.com/doku.php?id=technical_indicators:kaufman_s_adaptive_moving_average + """ + + _filename = 'ta/tests/data/cs-kama.csv' + + def setUp(self): + self._df = pd.read_csv(self._filename, sep=',') + self._indicator = KAMAIndicator(close=self._df['Close'], n=10, pow1=2, pow2=30, fillna=False) + + def tearDown(self): + del(self._df) + + def test_kama(self): + target = 'KAMA' + result = self._indicator.kama() + pd.testing.assert_series_equal(self._df[target].tail(), result.tail(), check_names=False)