示例#1
0
class TestAccumulationDistribution(unittest.TestCase):
    def setUp(self):
        """Create data to use for testing."""
        self.close_data = SampleData().get_sample_close_data()
        self.high_data = SampleData().get_sample_high_data()
        self.low_data = SampleData().get_sample_low_data()
        self.volume = SampleData().get_sample_volume()

        self.mf_expected = [1203861240.8599999, 1553716404.8666668,
        1694259812.96, 2662913259.9299998, 1103809271.55, 2054975406.8199999,
        1252707685.0466664, 1522731247.6133335, 897474013.69333339,
        1079485789.7, 866177879.22666669, 954220671.06666672,
        1090016254.4833333, 1088561820.8399999, 833822262.0, 825998757.75999987,
        829289393.70666659, 781406052.61333323, 973755157.96000004,
        1390664966.8599999, 1057136293.2866668, 784041982.43666673,
        1062708520.3800001, 1089529128.51, 955801301.51666665,
        982531236.06000018, 1146923211.8, 788836827.12, 1053134844.4499999,
        1071889105.8999999, 1010837958.1466668, 1097007225.5999999,
        899531907.94666684, 1004931373.25, 1300262999.5999999, 1088440513.75,
        1240619581.3, 1354530117.7133334, 1758135238.4100001,
        1579976044.0666666, 2773031331.8400002, 3023099141.4633331,
        2828683285.5900002, 1362235555.3733335, 1379509305.4166667,
        2019980276.5133333, 1082089890.5766666, 894367885.18000007,
        846860834.25999987, 1184169350.1166668, 1067126734.6266667,
        1109440058.9599998, 1069389730.9200001, 963469816.14666665,
        1132770199.5866666, 1637795356.4633331, 1085315009.8, 1233339463.23,
        1568715265.0799997, 1393974485.8966668, 847397473.43999994,
        975104887.13333333, 780912741.09333336, 615466230.10000002,
        908691541.62, 1182337603.4133334, 1030839973.4499999,
        1014268044.8266666, 2118621551.8600001, 1444090704.0,
        1448859443.4733334, 1702113981.8666663, 1295547462.3266666,
        1519551983.0699999, 1291809334.3066666, 1604462263.7166667,
        1367822609.2200003, 1348448307.26, 1354954842.8266668,
        2301419413.6266665, 1840989433.813333, 1262096267.8099997,
        2052241573.9733334, 485425652.6566667, 1036961757.5766666,
        1103874442.4733334, 1297856545.8166668, 1432535936.6399999,
        1213620641.7533331, 1427130539.7333331, 2344130494.0299997,
        2939222433.3399997, 2872064994.6299996, 4744647777.8299999,
        2495715536.2333331, 1417667030.7366667, 1605626189.8000002,
        1590079560.7, 1757610781.6000001, 1900954009.5466666,
        1902051350.4000001, 1805887362.3633335, 3513534927.48, 2370363923.0,
        1433884147.8399999, 1512777578.3199999, 1159366702.0800002,
        1278857534.4866664, 1067430292.2333332, 1142958189.8,
        1734217438.9833336, 800257863.29666674, 844187705.69333327,
        1032845968.5299999, 687174370.65333331, 1297206762.5, 1126704258.3,
        856233938.33999991, 809474362.18666673, 885615210.20000005,
        922039906.18000007, 1083024462.9599998, 1191653539.7766666,
        954953607.9466666, 1042492232.1333334, 963866806.58999991,
        1046194449.0533333]

    def test_money_flow(self):
        mf = money_flow.money_flow(self.close_data, self.high_data, self.low_data, self.volume)
        np.testing.assert_array_equal(mf, self.mf_expected)

    def test_money_flow_invalid_data(self):
        self.close_data.append(1)
        with self.assertRaises(Exception) as cm:
            money_flow.money_flow(self.close_data, self.high_data, self.low_data, self.volume)
        expected = ("Error: mismatched data lengths, check to ensure that all input data is the same length and valid")
        self.assertEqual(str(cm.exception), expected)
示例#2
0
class TestTypicalPrice(unittest.TestCase):
    def setUp(self):
        """Create data to use for testing."""
        self.close_data = SampleData().get_sample_close_data()
        self.high_data = SampleData().get_sample_high_data()
        self.low_data = SampleData().get_sample_low_data()

        self.tp_expected = [792.42999999999995, 802.86666666666667,
        804.61333333333334, 809.96999999999991, 807.61666666666667,
        809.68999999999994, 812.28666666666652, 815.05666666666673,
        812.59666666666669, 809.88666666666677, 815.84666666666669,
        817.94666666666672, 815.52333333333343, 807.71999999999991,
        809.66666666666663, 795.22666666666657, 791.40333333333331,
        776.2733333333332, 778.42000000000007, 764.65999999999997,
        764.31333333333339, 776.02333333333343, 789.42000000000007,
        785.71000000000004, 780.31666666666661, 779.13000000000011,
        784.9133333333333, 784.84666666666669, 775.96999999999991,
        786.21999999999991, 780.14333333333343, 775.19999999999993,
        753.2266666666668, 771.70333333333338, 780.18666666666661,
        805.73000000000002, 811.87333333333333, 801.88666666666666,
        781.03000000000009, 782.09666666666669, 788.48000000000002,
        805.62333333333333, 809.75666666666666, 819.56333333333339,
        817.06333333333339, 822.00666666666666, 828.43666666666661,
        835.50333333333344, 824.03666666666652, 821.82333333333338,
        827.11333333333334, 821.61999999999989, 806.84666666666669,
        804.60666666666668, 803.99666666666656, 811.95666666666659,
        809.61333333333334, 813.90333333333331, 800.75999999999988,
        803.03666666666675, 801.40333333333331, 802.7166666666667,
        800.14666666666665, 803.9666666666667, 802.64666666666665,
        810.02666666666664, 810.48333333333323, 802.69333333333327,
        815.21000000000004, 816.0, 805.07666666666671, 799.78666666666652,
        795.49666666666656, 797.88999999999999, 801.10666666666657,
        790.60333333333335, 788.78000000000009, 798.62, 788.29333333333341,
        802.70666666666659, 807.78666666666652, 808.00999999999988,
        796.85333333333335, 791.17666666666673, 789.77666666666664,
        791.77666666666664, 795.82333333333338, 793.09333333333325,
        791.31333333333316, 793.57333333333327, 796.26999999999998,
        796.90999999999997, 799.42999999999995, 802.87, 805.45666666666659,
        801.36333333333334, 805.80666666666673, 806.89999999999998,
        808.01666666666677, 808.6633333333333, 807.36000000000001,
        805.23666666666668, 806.80333333333328, 797.16666666666663, 798.88,
        800.11000000000001, 800.88000000000011, 791.46333333333325,
        765.80333333333328, 761.89999999999998, 757.54333333333341,
        757.55666666666673, 759.20666666666659, 754.46333333333325,
        756.90333333333331, 753.5, 753.0866666666667, 735.65999999999997,
        735.94666666666672, 729.61000000000001, 732.53000000000009,
        727.24666666666656, 717.77666666666664, 707.38666666666666,
        709.04333333333341, 704.95666666666659, 710.37666666666667]

    def test_typical_price(self):
        tp = typical_price.typical_price(self.close_data, self.high_data, self.low_data)
        np.testing.assert_array_equal(tp, self.tp_expected)

    def test_typical_price_invalid_data(self):
        self.close_data.append(1)
        with self.assertRaises(Exception) as cm:
            typical_price.typical_price(self.close_data, self.high_data, self.low_data)
        expected = ("Error: mismatched data lengths, check to ensure that all input data is the same length and valid")
        self.assertEqual(str(cm.exception), expected)
示例#3
0
class TestOnBalanceVolume(unittest.TestCase):
    def setUp(self):
        """Create data to use for testing."""
        self.close_data = SampleData().get_sample_close_data()
        self.volume = SampleData().get_sample_volume()

        self.obv_expected = [
            1.0, 1935212.0, 4040894.0, 7328563.0, 5961814.0, 8499792.0,
            10041991.0, 11910243.0, 10805791.0, 9472906.0, 10534598.0,
            11701203.0, 10364618.0, 9016921.0, 10046755.0, 9008059.0,
            7960187.0, 6953575.0, 8204513.0, 6385842.0, 5002723.0, 6013056.0,
            7359245.0, 5972564.0, 4747675.0, 3486613.0, 4947823.0, 3942739.0,
            2585554.0, 3948899.0, 2653191.0, 1238063.0, 43825.0, 1346050.0,
            3012655.0, 4363530.0, 5891625.0, 4202446.0, 1951399.0, 3971579.0,
            7488512.0, 11241009.0, 14734260.0, 16396408.0, 14708033.0,
            17165410.0, 18471593.0, 19542047.0, 18514349.0, 17073444.0,
            18363626.0, 17013318.0, 15687924.0, 14490482.0, 13081558.0,
            15098655.0, 13758120.0, 15273459.0, 13314426.0, 15050305.0,
            13992913.0, 15207669.0, 14231707.0, 14997244.0, 13865125.0,
            15324753.0, 16596636.0, 15333055.0, 17931921.0, 19701640.0,
            17901986.0, 15773776.0, 14145174.0, 16049637.0, 17662168.0,
            15632753.0, 13898654.0, 15587127.0, 13868281.0, 16735355.0,
            19014409.0, 20576390.0, 18000958.0, 17387409.0, 16074428.0,
            17468602.0, 19099437.0, 17293173.0, 15759494.0, 17557854.0,
            20501743.0, 24190017.0, 27782658.0, 33692267.0, 36790777.0,
            35021708.0, 37014278.0, 38984881.0, 41160097.0, 43510833.0,
            41154943.0, 38912264.0, 43267148.0, 40293662.0, 42088530.0,
            43979242.0, 45426858.0, 43811044.0, 42417174.0, 40917032.0,
            38627767.0, 37571400.0, 38683334.0, 37314353.0, 38222229.0,
            36500654.0, 35004539.0, 33840640.0, 34940549.0, 33726729.0,
            34985435.0, 33496223.0, 31836022.0, 30486048.0, 31956328.0,
            30589057.0, 32061789.0
        ]

    def test_obv(self):
        obv = on_balance_volume.on_balance_volume(self.close_data, self.volume)
        np.testing.assert_array_equal(obv, self.obv_expected)

    def test_obv_invalid_data(self):
        self.close_data.append(0)
        with self.assertRaises(Exception) as cm:
            on_balance_volume.on_balance_volume(self.close_data, self.volume)
        expected = "Error: mismatched data lengths, check to ensure that all input data is the same length and valid"
        self.assertEqual(str(cm.exception), expected)
class TestDirectionalIndicators(unittest.TestCase):
    def setUp(self):
        """Create data to use for testing."""
        self.close_data = SampleData().get_sample_close_data()
        self.high_data = SampleData().get_sample_high_data()
        self.low_data = SampleData().get_sample_low_data()

        self.positive_directional_movement_expected = [
            0, 10.389999999999986, 1.9500000000000455, 5.6299999999999955, 0,
            1.92999999999995, 2.6100000000000136, 2.6200000000000045, 0, 0,
            6.409999999999968, 1.9300000000000637, 0, 0, 2.4200000000000728, 0,
            0, 0, 2.2999999999999545, 0, 0, 11.530000000000086,
            13.739999999999895, 0, 0, 0, 5.439999999999941, 0, 0,
            9.81000000000006, 0, 0, 0, 18.379999999999995, 8.43999999999994,
            25.600000000000023, 6.1299999999999955, 0, 0, 0.34000000000003183,
            6.659999999999968, 17.519999999999982, 3.9500000000000455,
            9.620000000000005, 0, 4.9500000000000455, 6.67999999999995,
            6.899999999999977, 0, 0, 4.769999999999982, 0, 0, 0, 0,
            7.8700000000000045, 0, 4.310000000000059, 0, 2.509999999999991, 0,
            1.6499999999999773, 0, 3.5699999999999363, 0, 7.279999999999973,
            0.20000000000004547, 0, 12.670000000000073, 0.67999999999995, 0, 0,
            0, 2.2100000000000364, 3.599999999999909, 0, 0, 9.470000000000027,
            0, 14.670000000000073, 5.009999999999991, 0.36000000000001364, 0,
            0, 0, 1.490000000000009, 4.1099999999999, 0, 0, 2.1000000000000227,
            2.7200000000000273, 0.5099999999999909, 2.8799999999999955,
            3.6299999999999955, 2.67999999999995, 0, 4.1099999999999,
            1.1200000000000045, 1.25, 0.6200000000000045, 0, 0,
            1.2099999999999227, 0, 1.740000000000009, 0.9099999999999682,
            1.2300000000000182, 0, 0, 0, 0, 0, 1.3100000000000591, 0,
            2.6299999999999955, 0, 0, 0, 0.16999999999995907, 0,
            2.7000000000000455, 0, 0, 0, 1.9099999999999682, 0,
            5.7000000000000455
        ]

        self.negative_directional_movement_expected = [
            0, 0, 0, 0, 2.1700000000000728, 0, 0, 0, 2.240000000000009,
            2.8600000000000136, 0, 0, 2.439999999999941, 7.600000000000023, 0,
            14.430000000000064, 4.209999999999923, 14.6400000000001, 0,
            13.569999999999936, 0.6399999999999864, 0, 0, 3.240000000000009,
            5.5, 1.3199999999999363, 0, 0, 9.350000000000023, 0,
            5.8599999999999, 5.440000000000055, 21.75999999999999, 0, 0, 0, 0,
            10.100000000000023, 21.129999999999995, 0, 0, 0, 0, 0,
            2.730000000000018, 0, 0, 0, 11.100000000000023, 2.5299999999999727,
            0, 5.399999999999977, 15.5, 1.7100000000000364, 1.080000000000041,
            0, 2.1200000000000045, 0, 13.170000000000073, 0,
            0.9800000000000182, 0, 2.3899999999999864, 0, 1.7900000000000773,
            0, 0, 7.57000000000005, 0, 0, 10.839999999999918,
            5.490000000000009, 3.9700000000000273, 0, 0, 10.419999999999959,
            1.9800000000000182, 0, 10.120000000000005, 0, 0, 0,
            10.709999999999923, 6.050000000000068, 1.759999999999991, 0, 0,
            3.1299999999999955, 1.4800000000000182, 0, 0, 0, 0, 0, 0,
            3.689999999999941, 0, 0, 0, 0, 1.7000000000000455,
            2.1100000000000136, 0, 9.81000000000006, 0, 0, 0,
            9.040000000000077, 25.879999999999995, 3.6499999999999773,
            4.82000000000005, 0, 0, 4.710000000000036, 0, 3.3799999999999955,
            0.6399999999999864, 17.360000000000014, 0, 6.349999999999909, 0,
            5.340000000000032, 9.17999999999995, 10.670000000000073, 0,
            3.67999999999995, 0
        ]

        self.pdi_period_6_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, 17.17245993, 22.34368913,
            23.57568532, 21.3664846, 18.68190766, 30.78607353, 29.69853337,
            24.57613861, 19.41692593, 20.31205509, 12.95026625, 8.63862852,
            5.43198116, 5.79388242, 4.02329203, 3.22520994, 9.9921133,
            17.18109472, 14.40626259, 12.06687531, 10.0985882, 12.9820837,
            11.9385369, 10.94301187, 19.04670199, 17.10645221, 15.10913495,
            10.63037333, 22.45714669, 23.2089878, 31.23989143, 25.06202808,
            18.48205104, 15.20424809, 13.17587555, 14.38245103, 20.61384189,
            19.63889159, 20.6313393, 16.97525788, 16.60891728, 18.05079377,
            19.22459986, 17.22893117, 15.32039154, 17.03163344, 15.31391622,
            12.2956512, 10.38441109, 8.72022651, 12.83032279, 11.19141574,
            13.76350945, 12.17356566, 12.96181227, 11.30953289, 11.43545029,
            9.83177567, 13.57862577, 12.91268391, 21.26366754, 18.42660118,
            15.66738138, 31.02761477, 26.20788376, 21.42953827, 16.92693481,
            12.81773976, 12.35104846, 13.45005333, 11.38708826, 9.83313238,
            19.10158785, 16.29690792, 30.51435893, 29.48650644, 23.8610897,
            19.17796695, 15.5221913, 12.799587, 11.99985872, 13.83323059,
            12.80809723, 11.90756706, 13.71799765, 16.59868988, 15.92326873,
            18.45930389, 20.88960736, 21.22000487, 18.19837649, 22.26908561,
            21.35843931, 20.911531, 19.21386894, 16.50609783, 15.3470583,
            17.0388589, 12.89321658, 13.47788976, 12.570757, 12.59568964,
            9.29785548, 5.44570513, 3.50887115, 2.38033623, 1.71604366,
            2.1623727, 1.99498727, 3.89315676, 3.69393546, 3.47303828,
            2.71515231, 2.34616071, 1.80983659, 3.63000195, 2.90280805,
            2.48823796, 1.95703675, 2.99310996, 2.40886917, 6.09048059
        ]

        self.pdi_period_8_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            12.84476524, 13.96304263, 13.55268862, 21.45098964, 21.60062608,
            19.73122073, 17.17602708, 18.19149004, 13.01014933, 9.49887776,
            6.380009, 6.03799823, 4.41258806, 3.48581839, 7.56583328,
            12.2591115, 10.88751608, 9.73831828, 8.6864877, 10.13572008,
            9.00038007, 8.43561508, 12.89859492, 12.19732074, 11.42117359,
            9.32564335, 17.32057505, 18.67369813, 25.58091393, 22.10649176,
            17.53458861, 14.1852722, 11.74850059, 12.33811672, 16.61062459,
            16.23226351, 17.32367098, 15.16910778, 14.76135521, 14.70915491,
            14.68981437, 13.28379614, 12.14923166, 13.04729963, 12.14590806,
            10.80378591, 9.5095975, 8.34765736, 10.7302867, 9.7082254,
            10.594433, 9.61971968, 10.1958856, 9.50345605, 9.70219954,
            8.94750232, 10.33102091, 9.44928437, 13.66391887, 12.81202149,
            11.83017472, 20.07584789, 18.21899147, 16.33282596, 14.28013273,
            12.07487794, 11.87595887, 12.7004416, 10.5191214, 8.6957451,
            13.93208101, 12.72613563, 21.69167286, 22.22874858, 19.50558145,
            16.9222296, 14.69757703, 12.77779333, 12.1085504, 13.38348903,
            11.75411621, 10.31843813, 11.32121047, 12.86483312, 12.52305946,
            14.16633928, 16.00642705, 16.3895316, 14.2861356, 16.44414651,
            15.87543075, 15.35793012, 14.61632587, 13.48522723, 12.38948681,
            12.7451686, 11.08734197, 11.65588668, 11.19721034, 11.16458894,
            9.22205285, 6.12259108, 4.31082792, 3.25191814, 2.53744095,
            2.63369749, 2.1140582, 2.87420126, 2.71562928, 2.59996554,
            2.29828068, 2.11335075, 1.80843654, 2.86489709, 2.46142161,
            2.06507807, 1.66905275, 2.27104756, 1.97768954, 4.15227219
        ]

        self.pdi_period_10_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, 9.23796092, 15.5995123, 16.40825818, 15.90888348,
            14.90895578, 16.1807485, 12.28384969, 9.44483311, 6.68153207,
            6.22348195, 4.67433429, 3.68787643, 6.75746194, 9.99991825,
            8.62772646, 7.85688094, 7.23360865, 8.39261652, 7.73922191,
            7.11879706, 9.81349491, 9.38208089, 8.91130174, 7.82816511,
            13.48221055, 14.88002142, 20.59742968, 18.77397222, 15.70234562,
            13.29192855, 11.44190072, 11.41683073, 13.85433948, 13.48620514,
            14.48624857, 13.18851537, 13.0821946, 13.19017287, 13.11744946,
            11.56230575, 10.35806537, 10.73320087, 10.07749647, 9.36513023,
            8.63366317, 7.93337868, 9.33499044, 8.54933336, 9.19910811,
            8.50945759, 8.58747767, 8.04623548, 8.2305099, 7.84340488,
            8.74270827, 8.28512284, 10.7358965, 10.20131258, 9.7341179,
            14.90397082, 14.12850872, 13.06025751, 12.01211781, 10.78861374,
            10.78457648, 11.46714592, 10.06039425, 8.78167148, 11.99825462,
            10.53672855, 16.42508872, 17.25684654, 15.8554005, 14.40064092,
            13.06836317, 11.85021947, 11.45372658, 12.35840495, 11.18484707,
            10.18551662, 10.30943542, 10.73443819, 10.59925334, 11.63618884,
            12.86881587, 13.37773238, 12.2448139, 13.65021225, 13.02220293,
            12.62069281, 12.0621268, 11.15607388, 10.48568678, 10.80393103,
            9.91731286, 10.38219181, 10.18796769, 10.25310323, 8.94502008,
            6.61354932, 5.05227241, 3.93469587, 3.15677541, 3.13416339,
            2.62786862, 3.08810535, 2.63328955, 2.32763682, 2.1118975,
            1.99106827, 1.80419988, 2.48943087, 2.23677705, 1.96527941,
            1.67833889, 1.99976772, 1.73597824, 3.16818521
        ]

        self.ndi_period_6_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, 2.5923733, 2.6739039,
            2.25765683, 6.42575461, 11.48554738, 10.26052582, 8.49297409,
            12.32086135, 25.36417281, 20.29206827, 34.73464475, 28.26067756,
            31.12756748, 22.68505435, 24.77501448, 20.26984538, 16.77397286,
            14.0828462, 13.89447581, 15.19756665, 13.57650704, 12.28982335,
            11.30192293, 18.37189092, 16.63853606, 20.82543767, 24.18118692,
            36.55775221, 26.96984518, 20.51573288, 14.08388656, 9.90425555,
            11.8138514, 19.03283368, 16.30087656, 13.95802082, 11.90470381,
            10.22183058, 8.33364214, 8.15137653, 6.84043491, 6.04184767,
            5.22232067, 10.94683579, 11.25833631, 10.21637339, 13.00820144,
            21.01492078, 18.9302344, 16.64870457, 13.96340564, 13.73522997,
            12.61462794, 22.46058077, 19.72608661, 18.13966186, 15.73301658,
            15.95717761, 15.27139134, 16.90803792, 14.64139151, 12.49261706,
            21.57404737, 17.77263493, 14.46770852, 26.69003336, 28.21580466,
            26.05366008, 20.17610312, 15.87778011, 24.41167997, 23.24020572,
            19.9699335, 28.69200178, 23.94103206, 18.85174348, 15.01552561,
            22.82595723, 24.37690436, 21.80016034, 18.00950344, 14.90040717,
            17.10037193, 17.64106934, 16.26847628, 15.0253795, 13.68514299,
            11.81598791, 9.64768734, 7.86075892, 12.69203057, 10.80763685,
            9.42804572, 8.23333447, 7.10779159, 9.38798882, 13.27361589,
            12.24206696, 30.49859454, 23.60634101, 18.93331113, 15.45858494,
            26.59318714, 46.12312506, 33.05005186, 26.00140554, 18.74506069,
            14.86703641, 16.90599333, 15.92742851, 18.05892823, 17.60847835,
            29.78412757, 24.06789591, 23.82543514, 19.24759256, 19.50619078,
            23.99595546, 26.85455429, 21.8925964, 20.21998448, 17.00298171
        ]

        self.ndi_period_8_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, 1.21688582,
            3.6523134, 6.84422655, 6.67236319, 5.93459491, 8.74888223,
            17.92815525, 15.5833363, 27.0423641, 23.61411971, 26.19126936,
            19.2041072, 20.73615841, 16.66633071, 13.47000474, 11.76734413,
            11.80296643, 12.90355561, 12.08392381, 10.75289478, 9.54842272,
            13.44459518, 12.54287699, 15.107347, 17.37111957, 26.22212362,
            21.68289548, 18.10542083, 13.92080741, 10.74052326, 12.05854934,
            16.60111117, 13.62839176, 11.95754495, 10.77060681, 9.69826919,
            8.49296382, 8.31953497, 7.22458845, 6.17420613, 5.27895004,
            8.28742006, 8.41671015, 7.87038747, 9.35809862, 14.25166666,
            13.20230156, 12.00598228, 10.90010644, 10.73968639, 9.68530271,
            14.62658584, 13.69421725, 13.25888059, 12.30382905, 12.6952261,
            11.65872485, 11.77168431, 11.01740856, 10.21734746, 15.04013251,
            13.38816717, 11.80558415, 19.01515414, 20.89236945, 20.64784621,
            17.5504017, 14.98186856, 19.42956968, 17.32205934, 15.48472888,
            21.01492869, 18.90822611, 16.36141671, 14.17589493, 19.55761812,
            21.05688828, 19.48296367, 16.95233747, 14.89612456, 15.17980001,
            14.32058763, 13.58779091, 12.86541632, 12.09151368, 11.18703315,
            10.01320582, 8.72321242, 10.95756392, 9.71079804, 8.74810105,
            7.79788081, 7.10484381, 8.35717042, 10.02671206, 9.17472225,
            19.33394357, 16.83178092, 14.6630253, 12.78095517, 20.3023948,
            34.64724347, 26.79695286, 22.94956335, 17.90732713, 14.31330591,
            13.48644276, 11.43919777, 12.30830834, 12.0948933, 19.2088228,
            16.95977826, 17.58724412, 15.25719286, 15.62537469, 17.258048,
            18.40252711, 16.19716284, 15.64280003, 13.81978726
        ]

        self.ndi_period_10_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, 4.15544868, 4.61551901, 4.35605974, 6.51930975,
            13.55562287, 12.50272501, 21.71288972, 19.74078936, 22.29138346,
            17.05357195, 18.2833707, 14.65125133, 12.04619319, 10.30454995,
            9.84438834, 10.60316774, 10.16426734, 9.39949145, 8.6677081,
            11.03849605, 10.13090354, 11.76684573, 13.21549775, 19.57031502,
            17.24535171, 15.23684361, 12.61267555, 10.38533088, 11.46368108,
            15.16922417, 12.96261451, 11.16143402, 9.67030469, 8.78395402,
            7.98972071, 7.91110403, 7.15131082, 6.36397621, 5.57749269,
            7.36992742, 7.15901389, 6.66761238, 7.54300977, 10.81162599,
            10.39681026, 9.83055575, 9.0176576, 8.82274091, 8.26201493,
            11.38982632, 10.51383451, 10.14891803, 9.70923546, 10.06984929,
            9.56951005, 9.74919128, 9.21322642, 8.68271498, 11.64010235,
            10.86078492, 10.06133242, 14.5663087, 16.12267122, 16.44722376,
            14.77508562, 13.27545126, 16.66119448, 15.46760333, 13.55351659,
            16.38976002, 15.1542872, 13.79236112, 12.53838876, 16.4170659,
            17.76276337, 16.94664006, 15.35619125, 13.90608578, 14.1066874,
            13.57406884, 12.34820597, 11.22213442, 10.79480165, 10.19911148,
            9.43738339, 8.65153409, 10.13202568, 9.23026889, 8.34379998,
            7.59273782, 7.02043792, 7.59966392, 8.57733816, 8.12912603,
            14.62444472, 13.40237849, 12.26371512, 11.20588153, 16.50109118,
            28.01589467, 23.29544755, 20.30596278, 16.29131353, 13.65525305,
            13.08456347, 11.09341275, 10.50692447, 9.48213145, 13.92941996,
            12.78172674, 13.58201465, 12.29941353, 12.74053942, 14.02936805,
            15.10801004, 13.13423495, 12.40651749, 11.34282051
        ]

        self.adx_period_6_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, 73.76782014, 76.41654278,
            78.83164022, 70.76045107, 57.69017918, 55.76448404, 55.70895193,
            50.82380268, 43.06241038, 34.51272381, 36.66416226, 39.76401887,
            45.37515422, 47.89399657, 52.20101789, 55.78567267, 50.47144949,
            43.447372, 36.28329945, 32.03916018, 29.08341871, 24.61172374,
            20.91044057, 21.65838335, 19.14705308, 17.57621837, 18.50188508,
            24.61275979, 22.01919342, 19.36474044, 22.45682324, 25.94918316,
            25.29108759, 22.93488111, 20.87584473, 17.6415762, 19.1667842,
            21.23044453, 24.77111471, 26.49670987, 29.02499039, 32.49661081,
            36.62817734, 34.23871271, 31.07858091, 30.06724666, 26.41218477,
            26.3727615, 26.83603916, 27.5722316, 23.68132182, 21.43513024,
            18.58833262, 20.44069951, 20.48283681, 20.93453441, 20.08178823,
            20.69351214, 18.22245218, 17.41834785, 17.58926777, 17.85637572,
            17.52372151, 19.13006583, 20.75222451, 19.1155327, 20.09745801,
            22.42298075, 22.6953171, 20.29240626, 22.97414377, 25.90135997,
            21.95486869, 22.88763239, 21.08486333, 21.23750624, 21.49007493,
            19.3558743, 19.8286899, 20.85947667, 20.7205471, 17.88612705,
            17.29700051, 17.64810224, 16.12432329, 14.26610926, 13.14827215,
            14.61406508, 18.31401109, 22.91808104, 22.06930476, 24.16627104,
            26.59723404, 29.41446476, 32.17752621, 31.39615891, 27.37089263,
            25.53940518, 28.04501144, 27.92284562, 26.63503405, 23.89666922,
            27.94529684, 36.43439039, 43.82937485, 50.39552658, 55.86731968,
            58.99014215, 62.30680495, 62.04167517, 62.70760415, 63.43156065,
            66.74146724, 69.32380835, 72.08319131, 71.44697231, 71.88789007,
            73.44151466, 75.60375131, 75.6606507, 76.16883479, 71.34963535
        ]

        self.adx_period_8_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            82.69213454, 69.80705958, 55.82647992, 54.83656041, 55.36468478,
            51.55411247, 41.38384671, 34.97347929, 34.98439365, 36.28084667,
            40.26616688, 42.127769, 45.58452836, 48.51381184, 45.55932571,
            39.39211184, 34.46321387, 31.64830476, 29.57273494, 25.99806974,
            22.93195936, 22.92678291, 20.10487131, 18.87403035, 19.10614935,
            22.77325335, 21.28418192, 18.75669215, 20.13043706, 21.97302364,
            21.53242928, 19.79757988, 18.22974465, 16.12435877, 16.78101408,
            17.84181442, 19.9020043, 21.06669165, 22.72743794, 25.00612435,
            27.78298761, 27.20326774, 26.06784621, 25.90252254, 24.28124157,
            22.96337838, 22.12373876, 21.60414275, 18.99800901, 17.25159901,
            15.65375606, 16.27889175, 16.07428692, 16.127342, 15.58886986,
            15.80492311, 14.58343231, 14.12829274, 13.70243515, 13.39788039,
            13.21635705, 14.06261384, 14.97505552, 14.05153777, 14.64512764,
            16.08955434, 16.48885403, 15.45781253, 17.24481153, 19.23381197,
            17.48921451, 18.37385813, 16.9340164, 16.71778023, 16.60602661,
            15.43325627, 15.72736702, 16.35950174, 16.39802988, 15.01685133,
            14.72959512, 14.91879057, 14.19136097, 12.41770032, 11.08462366,
            11.16793701, 12.65114051, 14.88571613, 14.67321918, 16.05708448,
            17.66810701, 19.54067794, 21.42077435, 21.67787049, 20.28569225,
            19.78605608, 20.70130105, 20.38474956, 19.51191693, 17.9166967,
            20.36828544, 26.56789383, 32.28248418, 37.64437878, 42.33603538,
            45.65883688, 49.0636794, 50.41059667, 52.09043544, 53.65587457,
            56.77735466, 59.41012318, 62.15288011, 62.93155355, 64.16287414,
            65.97074505, 68.14552662, 69.05307004, 70.11548496, 68.07503858
        ]

        self.adx_period_10_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, 37.94785935, 46.57307644, 50.80545905, 48.20574644,
            37.59518728, 32.30825637, 31.43168004, 32.10693775, 35.66083635,
            37.32914545, 40.52791046, 43.21105069, 41.18843088, 36.04236479,
            32.33306404, 30.19041194, 28.58875108, 25.89084586, 23.55168652,
            23.32807871, 20.8873562, 19.82123798, 19.78076851, 22.2884113,
            21.20658549, 19.06610814, 19.59454012, 20.56258015, 20.04208764,
            18.63795538, 17.34807637, 15.66872117, 15.88717513, 16.42487071,
            17.70485646, 18.4523997, 19.56085336, 21.1242161, 23.07701907,
            22.98233059, 22.50398122, 22.59106158, 21.76138885, 20.28787214,
            19.17586556, 18.31954621, 16.64868768, 15.1315492, 14.1494444,
            14.18214204, 13.77051304, 13.54816133, 13.01561782, 12.95676039,
            12.11001027, 11.70973667, 11.30103224, 10.97437472, 10.76824683,
            11.2615787, 11.81767739, 11.18012765, 11.52358641, 12.4499539,
            12.76654715, 12.22021771, 13.46948218, 14.88079343, 14.00077233,
            14.77488781, 13.69920745, 13.44496244, 13.268603, 12.59577337,
            12.85891054, 13.34296414, 13.46430895, 12.70694118, 12.59148319,
            12.7585546, 12.38244107, 11.36613567, 10.32075872, 9.94677331,
            10.49049744, 11.58699292, 11.37245647, 12.16703836, 13.14006506,
            14.31358073, 15.52434512, 15.86810354, 15.282334, 15.16686456,
            15.56820543, 15.28118249, 14.67758205, 13.65378998, 15.25789873,
            19.91262204, 24.35696606, 28.67500183, 32.56121637, 35.5716483,
            38.66957743, 40.44753227, 42.394818, 44.213473, 47.15908364,
            49.74761149, 52.42765661, 53.81826799, 55.44956593, 57.44720013,
            59.70284513, 61.0898195, 62.52586245, 61.90667742
        ]

    def test_positive_directional_movement(self):
        pdm = directional_indicators.positive_directional_movement(
            self.high_data, self.low_data)
        np.testing.assert_allclose(pdm,
                                   self.positive_directional_movement_expected)

    def test_negative_directional_movement(self):
        ndm = directional_indicators.negative_directional_movement(
            self.high_data, self.low_data)
        np.testing.assert_allclose(ndm,
                                   self.negative_directional_movement_expected)

    def test_pdi_period_6(self):
        period = 6
        pdi = directional_indicators.positive_directional_index(
            self.close_data, self.high_data, self.low_data, period)
        np.testing.assert_allclose(pdi, self.pdi_period_6_expected)

    def test_pdi_period_8(self):
        period = 8
        pdi = directional_indicators.positive_directional_index(
            self.close_data, self.high_data, self.low_data, period)
        np.testing.assert_allclose(pdi, self.pdi_period_8_expected)

    def test_pdi_period_10(self):
        period = 10
        pdi = directional_indicators.positive_directional_index(
            self.close_data, self.high_data, self.low_data, period)
        np.testing.assert_allclose(pdi, self.pdi_period_10_expected)

    def test_pdi_invalid_period(self):
        period = 128
        with self.assertRaises(Exception) as cm:
            directional_indicators.positive_directional_index(
                self.close_data, self.high_data, self.low_data, period)
        expected = "Error: data_len < period"
        self.assertEqual(str(cm.exception), expected)

    def test_pdi_invalid_data(self):
        period = 6
        self.close_data.append(0)
        with self.assertRaises(Exception) as cm:
            directional_indicators.positive_directional_index(
                self.close_data, self.high_data, self.low_data, period)
        expected = (
            "Error: mismatched data lengths, check to ensure that all input data is the same length and valid"
        )
        self.assertEqual(str(cm.exception), expected)

    def test_ndi_period_6(self):
        period = 6
        ndi = directional_indicators.negative_directional_index(
            self.close_data, self.high_data, self.low_data, period)
        np.testing.assert_allclose(ndi, self.ndi_period_6_expected)

    def test_ndi_period_8(self):
        period = 8
        ndi = directional_indicators.negative_directional_index(
            self.close_data, self.high_data, self.low_data, period)
        np.testing.assert_allclose(ndi, self.ndi_period_8_expected)

    def test_ndi_period_10(self):
        period = 10
        ndi = directional_indicators.negative_directional_index(
            self.close_data, self.high_data, self.low_data, period)
        np.testing.assert_allclose(ndi, self.ndi_period_10_expected)

    def test_ndi_invalid_period(self):
        period = 128
        with self.assertRaises(Exception) as cm:
            directional_indicators.negative_directional_index(
                self.close_data, self.high_data, self.low_data, period)
        expected = "Error: data_len < period"
        self.assertEqual(str(cm.exception), expected)

    def test_ndi_invalid_data(self):
        period = 6
        self.close_data.append(0)
        with self.assertRaises(Exception) as cm:
            directional_indicators.negative_directional_index(
                self.close_data, self.high_data, self.low_data, period)
        expected = (
            "Error: mismatched data lengths, check to ensure that all input data is the same length and valid"
        )
        self.assertEqual(str(cm.exception), expected)

    def test_adx_period_6(self):
        period = 6
        adx = directional_indicators.average_directional_index(
            self.close_data, self.high_data, self.low_data, period)
        np.testing.assert_allclose(adx, self.adx_period_6_expected)

    def test_adx_period_8(self):
        period = 8
        adx = directional_indicators.average_directional_index(
            self.close_data, self.high_data, self.low_data, period)
        np.testing.assert_allclose(adx, self.adx_period_8_expected)

    def test_adx_period_10(self):
        period = 10
        adx = directional_indicators.average_directional_index(
            self.close_data, self.high_data, self.low_data, period)
        np.testing.assert_allclose(adx, self.adx_period_10_expected)

    def test_adx_invalid_period(self):
        period = 128
        with self.assertRaises(Exception) as cm:
            directional_indicators.average_directional_index(
                self.close_data, self.high_data, self.low_data, period)
        expected = "Error: data_len < period"
        self.assertEqual(str(cm.exception), expected)

    def test_adx_invalid_data(self):
        period = 6
        self.close_data.append(0)
        with self.assertRaises(Exception) as cm:
            directional_indicators.average_directional_index(
                self.close_data, self.high_data, self.low_data, period)
        expected = (
            "Error: mismatched data lengths, check to ensure that all input data is the same length and valid"
        )
        self.assertEqual(str(cm.exception), expected)
示例#5
0
class TestKeltnerBands(unittest.TestCase):
    def setUp(self):
        """Create data to use for testing."""
        self.close_data = SampleData().get_sample_close_data()
        self.high_data = SampleData().get_sample_high_data()
        self.low_data = SampleData().get_sample_low_data()

        self.bandwidth_period_6_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, 5.1283333333333303,
            5.0749999999999886, 5.0266666666666424, 4.8866666666666374,
            4.6966666666666397, 4.7299999999999613, 4.8099999999999836,
            4.9249999999999732, 4.923333333333308, 5.0466666666666429,
            5.0983333333333194, 5.1333333333333071, 5.0649999999999791,
            5.0033333333333303, 5.0066666666666606, 4.97999999999998,
            4.896666666666647, 4.8466666666666542, 4.7666666666666515,
            4.7216666666666542, 4.7866666666666715, 4.7116666666666829,
            4.7933333333333508, 4.8833333333333639, 4.9833333333333671,
            4.9600000000000177, 5.035000000000025, 5.1116666666666974,
            5.0950000000000273, 4.9233333333333462, 4.8866666666666561,
            4.9416666666666629, 4.8833333333333258, 5.0049999999999955,
            4.9116666666666715, 4.8900000000000245, 5.0016666666667033,
            5.0633333333333894, 5.0066666666667174, 4.8750000000000382,
            4.951666666666692, 5.0483333333333462, 4.9983333333333348,
            4.8749999999999813, 4.97999999999998, 4.911666666666652,
            4.8599999999999755, 4.9433333333333094, 4.8849999999999909,
            5.0550000000000068, 5.0083333333333444, 5.0083333333333444,
            5.0800000000000223, 4.9916666666666929, 5.1733333333333462,
            5.0316666666666761, 5.1183333333333394, 5.2166666666666783,
            5.1499999999999959, 5.1949999999999932, 5.1199999999999859,
            5.1766666666666383, 5.0549999999999686, 5.0366666666666333,
            5.121666666666651, 5.0049999999999768, 4.9749999999999845,
            4.9049999999999914, 4.8300000000000027, 4.8733333333333348,
            4.9366666666666674, 5.0666666666666815, 5.0566666666666906,
            5.0700000000000118, 5.1900000000000164, 5.1633333333333553,
            5.1333333333333639, 4.9150000000000205, 4.8666666666666929,
            5.0300000000000482, 4.9583333333333712, 4.89500000000002,
            4.9300000000000068, 5.0383333333333367, 5.0099999999999909,
            4.8933333333333167, 4.8449999999999891, 4.9500000000000073,
            4.9500000000000073, 5.071666666666677, 5.128333333333349,
            5.071666666666677, 5.1133333333333253, 5.0549999999999882,
            4.9216666666666429, 4.8266666666666538, 4.859999999999995,
            4.8533333333333148, 4.9033333333333262, 4.9049999999999914,
            4.8633333333333253, 4.8999999999999773, 4.82499999999997,
            4.8933333333333167, 4.8066666666666533, 4.8666666666666556,
            4.9733333333333194, 4.8233333333333235, 4.7783333333333262,
            4.7883333333333367, 4.9250000000000114, 4.9550000000000027,
            5.0516666666666952, 5.1850000000000405, 5.3100000000000209,
            5.2783333333333458, 5.2333333333333298, 5.041666666666667,
            4.9633333333333285, 5.036666666666652, 4.9716666666666542,
            5.0449999999999973
        ]

        self.center_band_period_6_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, 804.53111111111104,
            807.84055555555551, 809.87222222222215, 811.20277777777767,
            811.18888888888887, 812.56055555555565, 813.93666666666684,
            814.47611111111109, 813.25333333333344, 812.76499999999999,
            810.32166666666672, 806.24777777777774, 799.3022222222221,
            793.11833333333323, 785.94166666666661, 778.38277777777773,
            775.18222222222221, 774.8516666666668, 776.42444444444448,
            776.7405555555556, 779.15222222222235, 782.58555555555552,
            784.05611111111114, 781.81444444444458, 781.89944444444438,
            781.8705555555556, 781.21555555555551, 775.93444444444447,
            773.74388888888882, 774.44666666666672, 777.69833333333338,
            782.98666666666668, 787.43444444444447, 792.06833333333327,
            793.80055555555555, 795.18277777777791, 795.16499999999996,
            794.8122222222222, 797.75833333333333, 803.76388888888903,
            810.41555555555567, 817.07500000000016, 822.05499999999995,
            824.43499999999995, 824.81166666666684, 826.48666666666668,
            826.4222222222221, 822.82388888888875, 817.67444444444436,
            814.33444444444433, 812.68999999999994, 809.7733333333332,
            808.48722222222216, 807.47277777777765, 807.21111111111111,
            806.7788888888889, 805.23888888888894, 803.66111111111104, 802.005,
            802.31944444444446, 803.48444444444431, 804.99777777777774,
            804.99388888888882, 807.5044444444444, 809.50999999999988,
            809.91499999999996, 808.20833333333337, 805.71055555555552,
            804.90999999999997, 802.55944444444447, 798.32666666666648,
            795.61055555555549, 795.41611111111115, 794.21555555555551,
            795.01833333333343, 796.13166666666666, 799.03277777777782,
            800.37833333333322, 799.13777777777761, 799.38499999999988,
            797.56333333333316, 795.56944444444446, 793.08333333333337,
            792.15999999999997, 792.55944444444447, 793.64166666666654,
            794.49722222222215, 795.09833333333324, 796.72777777777765,
            799.08499999999992, 800.38333333333321, 801.97277777777765,
            803.63777777777784, 805.06888888888898, 806.03444444444449,
            806.3516666666668, 806.99722222222226, 807.1633333333333,
            805.54111111111115, 804.01833333333332, 802.59277777777777,
            801.51277777777784, 799.21722222222218, 792.38388888888892,
            786.50611111111095, 779.61666666666667, 772.52444444444438,
            765.57888888888886, 759.41222222222223, 757.92888888888876,
            756.5288888888889, 755.78611111111104, 752.13666666666666,
            748.25999999999988, 744.11777777777763, 740.05555555555554,
            735.68000000000018, 729.79500000000007, 725.08277777777778,
            720.59888888888884, 716.49000000000012, 712.79777777777781
        ]

        self.upper_band_period_6_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, 809.65944444444438,
            812.91555555555556, 814.89888888888879, 816.08944444444433,
            815.88555555555547, 817.29055555555556, 818.74666666666678,
            819.40111111111105, 818.17666666666673, 817.81166666666661,
            815.42000000000007, 811.38111111111107, 804.36722222222204,
            798.12166666666656, 790.94833333333327, 783.36277777777775,
            780.07888888888886, 779.69833333333349, 781.19111111111113,
            781.46222222222229, 783.93888888888898, 787.29722222222222,
            788.84944444444454, 786.6977777777779, 786.88277777777773,
            786.83055555555563, 786.25055555555559, 781.04611111111114,
            778.83888888888885, 779.37000000000012, 782.58500000000004,
            787.92833333333328, 792.31777777777779, 797.07333333333327,
            798.71222222222218, 800.0727777777779, 800.16666666666663,
            799.87555555555559, 802.7650000000001, 808.63888888888903,
            815.36722222222238, 822.12333333333345, 827.05333333333328,
            829.30999999999995, 829.79166666666686, 831.39833333333331,
            831.28222222222212, 827.76722222222202, 822.55944444444435,
            819.38944444444428, 817.69833333333327, 814.78166666666652,
            813.5672222222222, 812.46444444444433, 812.3844444444444,
            811.81055555555554, 810.35722222222228, 808.87777777777774,
            807.15499999999997, 807.51444444444451, 808.60444444444431,
            810.17444444444436, 810.04888888888877, 812.54111111111104,
            814.63166666666655, 814.91999999999996, 813.18333333333339,
            810.61555555555549, 809.74000000000001, 807.4327777777778,
            803.26333333333309, 800.67722222222221, 800.47277777777788,
            799.28555555555556, 800.20833333333348, 801.29500000000007,
            804.16611111111115, 805.29333333333329, 804.00444444444429,
            804.41499999999996, 802.52166666666653, 800.46444444444444,
            798.01333333333332, 797.19833333333327, 797.56944444444446,
            798.53499999999985, 799.34222222222218, 800.04833333333329,
            801.67777777777769, 804.15666666666664, 805.51166666666654,
            807.04444444444437, 808.75111111111119, 810.12388888888893,
            810.95611111111111, 811.17833333333351, 811.85722222222228,
            812.01666666666665, 810.44444444444446, 808.92333333333329,
            807.45611111111111, 806.41277777777782, 804.04222222222211,
            797.27722222222224, 791.31277777777757, 784.48333333333335,
            777.49777777777774, 770.40222222222224, 764.19055555555553,
            762.71722222222206, 761.45388888888897, 760.74111111111108,
            757.18833333333339, 753.44499999999994, 749.42777777777769,
            745.33388888888885, 740.91333333333353, 734.8366666666667,
            730.04611111111114, 725.63555555555547, 721.46166666666682,
            717.84277777777777
        ]

        self.lower_band_period_6_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, 799.40277777777771,
            802.76555555555547, 804.84555555555551, 806.31611111111101,
            806.49222222222227, 807.83055555555575, 809.12666666666689,
            809.55111111111114, 808.33000000000015, 807.71833333333336,
            805.22333333333336, 801.11444444444442, 794.23722222222216,
            788.1149999999999, 780.93499999999995, 773.40277777777771,
            770.28555555555556, 770.00500000000011, 771.65777777777782,
            772.01888888888891, 774.36555555555572, 777.87388888888881,
            779.26277777777773, 776.93111111111125, 776.91611111111104,
            776.91055555555556, 776.18055555555543, 770.82277777777779,
            768.64888888888879, 769.52333333333331, 772.81166666666672,
            778.04500000000007, 782.55111111111114, 787.06333333333328,
            788.88888888888891, 790.29277777777793, 790.1633333333333,
            789.74888888888881, 792.75166666666655, 798.88888888888903,
            805.46388888888896, 812.02666666666687, 817.05666666666662,
            819.55999999999995, 819.83166666666682, 821.57500000000005,
            821.56222222222209, 817.88055555555547, 812.78944444444437,
            809.27944444444438, 807.68166666666662, 804.76499999999987,
            803.40722222222212, 802.48111111111098, 802.03777777777782,
            801.74722222222226, 800.1205555555556, 798.44444444444434,
            796.85500000000002, 797.12444444444441, 798.3644444444443,
            799.82111111111112, 799.93888888888887, 802.46777777777777,
            804.38833333333321, 804.90999999999997, 803.23333333333335,
            800.80555555555554, 800.07999999999993, 797.68611111111113,
            793.38999999999987, 790.54388888888877, 790.35944444444442,
            789.14555555555546, 789.82833333333338, 790.96833333333325,
            793.8994444444445, 795.46333333333314, 794.27111111111094,
            794.35499999999979, 792.60499999999979, 790.67444444444448,
            788.15333333333342, 787.12166666666667, 787.54944444444448,
            788.74833333333322, 789.65222222222212, 790.1483333333332,
            791.7777777777776, 794.01333333333321, 795.25499999999988,
            796.90111111111094, 798.5244444444445, 800.01388888888903,
            801.11277777777786, 801.52500000000009, 802.13722222222225,
            802.30999999999995, 800.63777777777784, 799.11333333333334,
            797.72944444444443, 796.61277777777786, 794.39222222222224,
            787.4905555555556, 781.69944444444434, 774.75, 767.55111111111103,
            760.75555555555547, 754.63388888888892, 753.14055555555547,
            751.60388888888883, 750.831111111111, 747.08499999999992,
            743.07499999999982, 738.80777777777757, 734.77722222222224,
            730.44666666666683, 724.75333333333344, 720.11944444444441,
            715.5622222222222, 711.51833333333343, 707.75277777777785
        ]

    def test_bandwidth_period_6(self):
        period = 6
        bw = keltner_bands.band_width(self.high_data, self.low_data, period)
        np.testing.assert_array_equal(bw, self.bandwidth_period_6_expected)

    def test_bandwidth_invalid_period(self):
        period = 128
        with self.assertRaises(Exception) as cm:
            keltner_bands.band_width(self.high_data, self.low_data, period)
        expected = "Error: data_len < period"
        self.assertEqual(str(cm.exception), expected)

    def test_adx_invalid_data(self):
        period = 6
        self.high_data.append(0)
        with self.assertRaises(Exception) as cm:
            keltner_bands.band_width(self.high_data, self.low_data, period)
        expected = (
            "Error: mismatched data lengths, check to ensure that all input data is the same length and valid"
        )
        self.assertEqual(str(cm.exception), expected)

    def test_center_band_period_6(self):
        period = 6
        cb = keltner_bands.center_band(self.close_data, self.high_data,
                                       self.low_data, period)
        np.testing.assert_array_equal(cb, self.center_band_period_6_expected)

    def test_center_band_invalid_period(self):
        period = 128
        with self.assertRaises(Exception) as cm:
            keltner_bands.center_band(self.close_data, self.high_data,
                                      self.low_data, period)
        expected = "Error: data_len < period"
        self.assertEqual(str(cm.exception), expected)

    def test_center_band_invalid_data(self):
        period = 6
        self.high_data.append(0)
        with self.assertRaises(Exception) as cm:
            keltner_bands.center_band(self.close_data, self.high_data,
                                      self.low_data, period)
        expected = (
            "Error: mismatched data lengths, check to ensure that all input data is the same length and valid"
        )
        self.assertEqual(str(cm.exception), expected)

    def test_upper_band_period_6(self):
        period = 6
        ub = keltner_bands.upper_band(self.close_data, self.high_data,
                                      self.low_data, period)
        np.testing.assert_array_equal(ub, self.upper_band_period_6_expected)

    def test_upper_band_invalid_period(self):
        period = 128
        with self.assertRaises(Exception) as cm:
            keltner_bands.upper_band(self.close_data, self.high_data,
                                     self.low_data, period)
        expected = "Error: data_len < period"
        self.assertEqual(str(cm.exception), expected)

    def test_upper_band_invalid_data(self):
        period = 6
        self.high_data.append(0)
        with self.assertRaises(Exception) as cm:
            keltner_bands.upper_band(self.close_data, self.high_data,
                                     self.low_data, period)
        expected = (
            "Error: mismatched data lengths, check to ensure that all input data is the same length and valid"
        )
        self.assertEqual(str(cm.exception), expected)

    def test_lower_band_period_6(self):
        period = 6
        lb = keltner_bands.lower_band(self.close_data, self.high_data,
                                      self.low_data, period)
        np.testing.assert_array_equal(lb, self.lower_band_period_6_expected)

    def test_lower_band_invalid_period(self):
        period = 128
        with self.assertRaises(Exception) as cm:
            keltner_bands.lower_band(self.close_data, self.high_data,
                                     self.low_data, period)
        expected = "Error: data_len < period"
        self.assertEqual(str(cm.exception), expected)

    def test_lower_band_invalid_data(self):
        period = 6
        self.high_data.append(0)
        with self.assertRaises(Exception) as cm:
            keltner_bands.lower_band(self.close_data, self.high_data,
                                     self.low_data, period)
        expected = (
            "Error: mismatched data lengths, check to ensure that all input data is the same length and valid"
        )
        self.assertEqual(str(cm.exception), expected)
class TestVolumeAdjustedMovingAverage(unittest.TestCase):
    def setUp(self):
        """Create data to use for testing."""
        self.data = SampleData().get_sample_close_data()
        self.volume = SampleData().get_sample_volume()

        self.vama_period_6_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, 1478.9191875054275,
            1485.927186808339, 1481.5016007215124, 1366.7993111951894,
            1138.8694586412714, 1104.5954746648379, 946.13218234680642,
            922.69615745159228, 860.19234823594797, 851.01270826797952,
            814.52285941994569, 809.25274879392748, 784.37148213332409,
            767.63455656795804, 811.03606148752976, 843.21832305088628,
            837.16612745364034, 870.76143285494197, 915.14630307187133,
            912.57722758238197, 853.85373491494772, 866.79378217966894,
            867.49811110979647, 866.11607176770769, 863.5489849618649,
            871.46180722287988, 887.95647051455398, 852.32426551175479,
            883.44731862017727, 919.04705742390377, 921.41424015751136,
            954.54602411468341, 991.66033186814582, 1115.2830631048744,
            1198.0811152077529, 1410.0360135410599, 1688.4865741012773,
            1917.1424186877423, 1918.215991981376, 1863.7584773034105,
            1927.1044736459551, 1683.7393249812376, 1377.4150362863936,
            1092.0562540338792, 1066.3837072149215, 1021.3411547574237,
            890.20747328187588, 888.356659646195, 898.26650178239595,
            939.43758775767458, 1004.7245110554386, 1007.3387471873044,
            1025.2579322831325, 1097.1247314592636, 1159.1093366126613,
            1117.9856657734301, 1022.656119613738, 978.87751023106409,
            889.88464891293279, 794.88497827399135, 764.4152968456541,
            790.89402217758141, 796.51098752736198, 988.95246020718866,
            1108.2127792905665, 1185.9608029702306, 1260.7753536472812,
            1298.8107370130183, 1371.5779119720773, 1252.6776082892834,
            1275.7345100594448, 1264.0660910988249, 1213.205355799653,
            1221.8284473877932, 1334.4140503461745, 1413.5084939839417,
            1364.267853677329, 1462.8134739920863, 1338.5495082201121,
            1292.7409830621648, 1120.3240028607488, 1042.070664276355,
            1066.6367277768802, 945.90523804624581, 1081.45407292,
            1269.747257474032, 1533.9443831606586, 1760.6716632526666,
            2237.3265316109864, 2421.8750893134115, 2420.4617394966749,
            2314.0598765661589, 2119.8674343893481, 1959.3815471892437,
            1550.0654801862522, 1464.6625306458172, 1520.5901717759809,
            1795.2756210211048, 1907.5933571913313, 1860.944723016886,
            1805.126768052927, 1698.1865657801293, 1622.2922744439393,
            1270.0950505698008, 1093.3852208107576, 1136.6440474786677,
            1034.0660867815934, 988.69422130572536, 953.29818762303705,
            898.57477175906968, 920.74196327817174, 833.27760880848825,
            841.336106693754, 836.30404073311945, 815.09746179658714,
            848.88045047538014, 818.06047207122549, 827.3865324195159,
            841.57797918328015, 875.12940427704518, 886.40358446891844,
            904.25282780430268
        ]

        self.vama_period_8_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            1408.8543552519286, 1375.7604268867276, 1324.5505796637972,
            1235.1339565915534, 1050.6618869955378, 1049.1192141116881,
            944.80922579981882, 899.57456798145813, 824.31652368762207,
            816.97403479060688, 784.78840461457708, 796.39852553902801,
            843.48713515536122, 839.96619218092849, 807.04685810089143,
            831.78557823082872, 860.25598735352139, 873.89188463036885,
            895.59882474157894, 914.33561138971174, 849.39339531759163,
            848.95888976844481, 880.04313048468998, 874.4171654063224,
            875.20645032359084, 869.14588983674128, 871.58858309651373,
            888.1488462016207, 920.48022727047601, 940.73962966655426,
            971.28996050330147, 1052.0118317482372, 1104.1820666164131,
            1306.4326572235996, 1524.259668881301, 1689.3111506144332,
            1718.8912743712001, 1733.9211716397826, 1805.76517294977,
            1732.7748536308718, 1658.7601096902813, 1450.8263309840481,
            1252.3141242064335, 1062.0702236920436, 1034.7587839251446,
            1001.2234903879599, 887.13163079261199, 892.6000280663759,
            972.79623028321737, 998.53209355711249, 1003.9144527263028,
            1058.0611729143397, 1088.808028290701, 1064.8217826618022,
            1066.0884436567239, 1028.1120354121547, 917.78455611942354,
            898.72084622935495, 893.17605171259197, 835.14875070054063,
            794.1396818427495, 931.3371312374735, 981.95205087704494,
            1054.0333157837299, 1171.3440802633534, 1213.0930697548106,
            1249.511643187567, 1277.6748208212503, 1341.3696927761073,
            1260.3685389524574, 1250.0885126451683, 1239.9938030679825,
            1304.7406657117369, 1363.6981385494425, 1335.8871490550457,
            1417.9704382295595, 1297.1997612656689, 1261.4999720404876,
            1235.0796510075586, 1228.8798012158638, 1135.0541571280751,
            1067.2679962762875, 1085.0894256976721, 1116.7003096519468,
            1381.6258072129685, 1579.8278113587401, 1972.8060536907533,
            2102.1213150540802, 2100.4581844875179, 2142.8162885418819,
            2160.4358283149795, 2097.0535286451486, 1984.8968764599485,
            1880.1144655989433, 1562.9059146112641, 1672.8666873226514,
            1775.7845415859722, 1757.2171634831939, 1748.8413767076324,
            1684.2182295421076, 1617.0760103045293, 1526.9410772656393,
            1455.3808283620544, 1263.2434833263662, 1093.695923900329,
            1030.030353258737, 978.20457498211192, 927.23223174984457,
            929.21809498772882, 935.63040200538171, 904.6590883125765,
            804.77534819957566, 813.97810624335727, 822.37190362708566,
            827.78980832387003, 882.23922250071632, 845.28610024140767,
            836.16419480099341, 847.77871457473054, 873.33349393047308
        ]

        self.vama_period_10_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, 1297.8229874996732, 1268.6359200655111, 1216.8482981427048,
            1164.6452517636903, 1028.6975808282014, 1005.3373312035613,
            899.18519064838404, 862.63125725686439, 798.57022698979188,
            805.1463989873514, 831.9975425359562, 848.51104023519042,
            833.80555771248441, 831.47042249887397, 831.54259989134607,
            842.08511057599299, 855.59606783295749, 883.0356602666352,
            883.6815350983677, 890.55933161872395, 863.05035397594725,
            859.03120107918915, 886.0702736695057, 871.97335986072301,
            864.66214442735122, 894.44122952363671, 903.58665712148536,
            911.68254624019778, 960.56760612451512, 1021.473554663023,
            1065.381422574884, 1217.5857533145449, 1383.9047192735197,
            1550.5734381457903, 1581.4288101412344, 1588.3004065907273,
            1668.7955626679504, 1655.1017338344773, 1615.357541924468,
            1536.6373527031933, 1502.4103653455356, 1355.0834913205458,
            1189.8281021763094, 1037.8302784095483, 1003.3878478050798,
            982.0448189757517, 948.98238779122585, 949.2431446441858,
            978.53383977435317, 1040.8713648647793, 1059.0232254437237,
            1040.0315255853552, 1028.4515755903431, 1003.5556549951074,
            973.50472805267532, 954.13979917456948, 914.83769691785278,
            910.16469057952168, 891.20340873688076, 938.65229224386235,
            942.96679365941839, 994.92488149264955, 1057.7092373379787,
            1102.1246266486942, 1180.2193665723676, 1213.3278702530376,
            1249.758321587693, 1278.8281228453959, 1307.7258583013536,
            1241.850218957057, 1315.9401292057323, 1349.8564848612643,
            1311.8538216057216, 1377.2297650328367, 1287.9088160501744,
            1265.8882438207859, 1222.6938248865147, 1216.6592287677822,
            1223.9126447920576, 1211.6758394279082, 1136.1328295944695,
            1179.6315019148399, 1324.4997425765125, 1395.3741423241304,
            1763.1788588265822, 1889.1563031786561, 1916.215471576025,
            1942.8250292887228, 1956.4381665439935, 2003.4599278099292,
            2044.3457031863334, 2006.1054670817273, 1908.2029447452187,
            1963.5874039497855, 1758.5982618922003, 1666.9017080320132,
            1675.1447203200848, 1636.5814806101096, 1609.6578487779732,
            1550.0155059781198, 1484.5901062669034, 1470.0906181317237,
            1383.2302693234524, 1152.632640780882, 1037.0807470369969,
            972.59353522343008, 953.95922340205038, 951.14524394873911,
            914.6565686733411, 892.35803487887301, 870.10809162849478,
            799.9353770214575, 824.35585457582965, 854.3606306170135,
            847.62444360948689, 878.29081438965818, 849.50506434294255,
            842.52050841894618
        ]

    def test_vama_period_6(self):
        period = 6
        vama = volume_adjusted_moving_average.volume_adjusted_moving_average(
            self.data, self.volume, period)
        np.testing.assert_array_equal(vama, self.vama_period_6_expected)

    def test_vama_period_8(self):
        period = 8
        vama = volume_adjusted_moving_average.volume_adjusted_moving_average(
            self.data, self.volume, period)
        np.testing.assert_array_equal(vama, self.vama_period_8_expected)

    def test_vama_period_10(self):
        period = 10
        vama = volume_adjusted_moving_average.volume_adjusted_moving_average(
            self.data, self.volume, period)
        np.testing.assert_array_equal(vama, self.vama_period_10_expected)

    def test_vama_invalid_data(self):
        self.data.append(1)
        period = 6
        with self.assertRaises(Exception) as cm:
            volume_adjusted_moving_average.volume_adjusted_moving_average(
                self.data, self.volume, period)
        expected = (
            "Error: mismatched data lengths, check to ensure that all input data is the same length and valid"
        )
        self.assertEqual(str(cm.exception), expected)

    def test_vama_invalid_period(self):
        period = 128
        with self.assertRaises(Exception) as cm:
            volume_adjusted_moving_average.volume_adjusted_moving_average(
                self.data, self.volume, period)
        expected = "Error: data_len < period"
        self.assertEqual(str(cm.exception), expected)
示例#7
0
class TestVolumeIndex(unittest.TestCase):
    def setUp(self):
        """Create data to use for testing."""
        self.close_data = SampleData().get_sample_close_data()
        self.volume = SampleData().get_sample_volume()

        self.pvi_expected = [
            1.0, 1.0131617136727868, 1.0152943403369297, 1.0220581740172878,
            1.0220581740172878, 1.0244368189382491, 1.0244368189382491,
            1.028220752029624, 1.028220752029624, 1.0248545154752871,
            1.0248545154752871, 1.0276690488102527, 1.0244650041655374,
            1.0151167327315447, 1.0151167327315447, 0.9972084407513031,
            0.99256833708695491, 0.99256833708695491, 0.99517706110413839,
            0.97758096185097998, 0.97758096185097998, 0.97758096185097998,
            0.99466607532561435, 0.99006720628561307, 0.99006720628561307,
            0.9885444164271886, 0.99615836571931071, 0.99615836571931071,
            0.98495031479002748, 0.99788463403910965, 0.99788463403910965,
            0.99171806061919043, 0.99171806061919043, 1.0161153624211521,
            1.027359450785359, 1.027359450785359, 1.0355085426193171,
            1.0228194246619016, 0.99612764186303671, 0.99612764186303671,
            1.0040616159726605, 1.0257877152198811, 1.0257877152198811,
            1.0257877152198811, 1.0230216079786347, 1.0289668610989608,
            1.0289668610989608, 1.0289668610989608, 1.0289668610989608,
            1.0259326287949169, 1.0259326287949169, 1.0189863197822924,
            1.0189863197822924, 1.0189863197822924, 1.0183277653623486,
            1.0280667720726715, 1.0280667720726715, 1.0339082770092849,
            1.0168155256078024, 1.0168155256078024, 1.0168155256078024,
            1.0187952720226248, 1.0187952720226248, 1.0187952720226248,
            1.016996041509638, 1.0263976544718645, 1.0263976544718645,
            1.0263976544718645, 1.0421392044955968, 1.0421392044955968,
            1.0281920752436917, 1.0214867246418142, 1.0214867246418142,
            1.0248001127276287, 1.0248001127276287, 1.0110249205679784,
            1.0110249205679784, 1.0110249205679784, 0.99793812043944774,
            1.0161128254535388, 1.0161128254535388, 1.0161128254535388,
            1.0020913185554337, 1.0020913185554337, 1.0001286681336989,
            1.0027497561162737, 1.0076880378225743, 1.0043958500183741,
            1.0043958500183741, 1.0073152364142319, 1.011110438728847,
            1.0115673861647203, 1.0115673861647203, 1.0154889254595501,
            1.0154889254595501, 1.0154889254595501, 1.0215347849615932,
            1.0215347849615932, 1.0229904134885814, 1.0233574850301697,
            1.0220790634542931, 1.0220790634542931, 1.0242368747726398,
            1.0242368747726398, 1.0242368747726398, 1.0257753069682629,
            1.0257753069682629, 1.0134804497418848, 1.0134804497418848,
            1.0083590544889585, 1.0026421481601104, 1.0026421481601104,
            1.0049716578506291, 0.99852579865015956, 0.99852579865015956,
            0.99368537269643453, 0.99368537269643453, 0.99368537269643453,
            0.99368537269643453, 0.98515032029708494, 0.98924228371006429,
            0.98207121911504114, 0.96934966949449142, 0.96934966949449142,
            0.97169334499548909, 0.97169334499548909, 0.97908212385343263
        ]

        self.nvi_expected = [
            1.0, 1.0, 1.0, 1.0, 0.99737014309878635, 0.99737014309878635,
            1.0004742987659747, 1.0004742987659747, 0.99716065719744162,
            0.99716065719744162, 1.0043145436667653, 1.0043145436667653,
            1.0043145436667653, 1.0043145436667653, 1.0062413756294879,
            1.0062413756294879, 1.0062413756294879, 0.98680231838995269,
            0.98680231838995269, 0.98680231838995269, 0.98663450803834407,
            1.001543812354337, 1.001543812354337, 1.001543812354337,
            0.9944189699523458, 0.9944189699523458, 0.9944189699523458,
            0.99416561480076548, 0.99416561480076548, 0.99416561480076548,
            0.98635048365765376, 0.98635048365765376, 0.95843298325586723,
            0.95843298325586723, 0.95843298325586723, 0.98950906327275012,
            0.98950906327275012, 0.98950906327275012, 0.98950906327275012,
            0.99088989143683581, 0.99088989143683581, 0.99088989143683581,
            0.99632731175782552, 1.0082109045860519, 1.0082109045860519,
            1.0082109045860519, 1.0161210862361918, 1.024938792602782,
            1.0106146186998928, 1.0106146186998928, 1.0173304832838312,
            1.0173304832838312, 0.99918797201758558, 0.99641396346902655,
            0.99641396346902655, 0.99641396346902655, 0.99371355483156543,
            0.99371355483156543, 0.99371355483156543, 0.99665482086415003,
            0.99435889590200588, 0.99435889590200588, 0.99137380024919031,
            0.99593195460701656, 0.99593195460701656, 0.99593195460701656,
            0.99675568915703361, 0.98682169637474004, 0.98682169637474004,
            0.9880204711359688, 0.9880204711359688, 0.9880204711359688,
            0.98259721740583439, 0.98259721740583439, 0.98661148727656012,
            0.98661148727656012, 0.98443970883380372, 0.99704600899003337,
            0.99704600899003337, 0.99704600899003337, 1.0034417876586332,
            1.0034790446217512, 1.0034790446217512, 0.99659080642219422,
            0.99659080642219422, 0.99659080642219422, 0.99659080642219422,
            0.99659080642219422, 0.99417854456756283, 0.99417854456756283,
            0.99417854456756283, 0.99417854456756283, 0.9975467383944433,
            0.9975467383944433, 1.000864645328748, 0.99560818602833268,
            0.99560818602833268, 0.99695467086972778, 0.99695467086972778,
            0.99695467086972778, 0.99695467086972778, 0.994176709793965,
            0.994176709793965, 0.98225048254896785, 0.98430800315838363,
            0.98430800315838363, 0.98531676754696274, 0.98531676754696274,
            0.9535660945461697, 0.9535660945461697, 0.9535660945461697,
            0.95340247863870453, 0.95340247863870453, 0.95340247863870453,
            0.95677675074268698, 0.95677675074268698, 0.956510065780109,
            0.93419742391107474, 0.93441331173792364, 0.93441331173792364,
            0.93441331173792364, 0.93441331173792364, 0.93441331173792364,
            0.92071826863351425, 0.92071826863351425, 0.91541969388983713,
            0.91541969388983713
        ]

    def test_pvi(self):
        pvi = volume_index.positive_volume_index(self.close_data, self.volume)
        print(list(pvi))
        np.testing.assert_array_equal(pvi, self.pvi_expected)

    def test_pvi_invalid_data(self):
        self.close_data.append(1)
        with self.assertRaises(Exception) as cm:
            volume_index.positive_volume_index(self.close_data, self.volume)
        expected = (
            "Error: mismatched data lengths, check to ensure that all input data is the same length and valid"
        )
        self.assertEqual(str(cm.exception), expected)

    def test_nvi(self):
        nvi = volume_index.negative_volume_index(self.close_data, self.volume)
        np.testing.assert_array_equal(nvi, self.nvi_expected)

    def test_nvi_invalid_data(self):
        self.close_data.append(1)
        with self.assertRaises(Exception) as cm:
            volume_index.negative_volume_index(self.close_data, self.volume)
        expected = (
            "Error: mismatched data lengths, check to ensure that all input data is the same length and valid"
        )
        self.assertEqual(str(cm.exception), expected)
示例#8
0
class TestAccumulationDistribution(unittest.TestCase):
    def setUp(self):
        """Create data to use for testing."""
        self.close_data = SampleData().get_sample_close_data()
        self.high_data = SampleData().get_sample_high_data()
        self.low_data = SampleData().get_sample_low_data()
        self.volume = SampleData().get_sample_volume()

        self.ad_expected = [
            0.0, 15862.38524593231, -36477.702708130804, -104733.80651442676,
            40104.71949712043, 23939.254528920741, -62106.183239279555,
            112915.24595464926, 39956.002218866488, -260.35553975040239,
            -116475.2497883655, -154687.74497142577, -292093.679550856,
            -133194.90662509997, -263680.69609877974, -299353.08397758257,
            -261929.08397757346, -320893.80364286253, -471609.22532958613,
            -708827.18185129401, -694912.50378286431, -792540.18692894513,
            -777300.311457203, -699904.16262002871, -790925.63820386841,
            -889485.5941157171, -805433.69146085251, -833917.85340419237,
            -833917.85340416594, -883999.91462867253, -1022927.0306024188,
            -1054143.0894259787, -1058939.2259721591, -1021271.5606829068,
            -913860.42762679141, -1035092.7994216527, -935298.84023796313,
            -792598.06027727341, -709809.99197603366, -577648.68356478063,
            -712915.33741098049, -1014517.9000277666, -729489.82981907623,
            -732989.08876652108, -437866.62941692042, -292705.11886841164,
            -208275.03902052308, -57775.565753187257, -41895.022706843985,
            -197234.22345034953, -217259.22123303646, -336135.09482219844,
            -340737.15732219425, -345832.65519452997, -282367.61014945683,
            -503852.77093379293, -542493.46938165138, -293054.95086318324,
            -349241.3657770899, -310266.53503439715, -427254.58609822171,
            -379701.86011959275, -245746.2914921554, -197685.67265809805,
            -201802.46902173068, -174468.61134385251, 12276.114846627315,
            -21316.018077706984, -411927.14032219525, -465339.18257566751,
            -517829.09090903884, -526077.9668780705, -638881.56860968971,
            -535937.62266374112, -422292.58075894287, -585404.44057200733,
            -641343.11799134617, -442699.23563839833, -237900.56329794819,
            -15646.76484828876, 257481.51413010465, 266545.23366587964,
            296702.51703821769, 382165.68335837772, 433020.58124570741,
            559763.67215474963, 556301.17746264767, 683881.16259275773,
            671412.22763338394, 702418.43452995166, 1269915.1092287663,
            1369598.1903099443, 1813632.4712087966, 1418193.9507626847,
            1357868.9773113495, 1173146.9130543284, 1370686.1802957729,
            1559763.227204062, 1799516.493737207, 1532620.7033441989,
            1699573.5379898732, 1690914.5457118889, 2050665.8326683058,
            2199638.0771572837, 2242714.9091572445, 2255814.5304043461,
            2304978.8473854959, 2178583.2490768656, 2209187.1812126297,
            2279663.6510112993, 2416336.1883247532, 2392955.8321879292,
            2448552.5321879075, 2399441.1061789142, 2494347.2758041751,
            2406478.6085073589, 2498297.9406373627, 2479423.9027995183,
            2386354.6797225843, 2295492.9138876535, 2280017.0204450153,
            2238485.2116801129, 2242266.9907233468, 2141284.6836367347,
            2083933.3361190266, 2027200.0996044902, 1922004.9567473496
        ]

    def test_accumulation_distribution(self):
        ad = accumulation_distribution.accumulation_distribution(
            self.close_data, self.high_data, self.low_data, self.volume)
        np.testing.assert_array_equal(ad, self.ad_expected)

    def test_ad_invalid_data(self):
        self.close_data.append(1)
        with self.assertRaises(Exception) as cm:
            accumulation_distribution.accumulation_distribution(
                self.close_data, self.high_data, self.low_data, self.volume)
        expected = (
            "Error: mismatched data lengths, check to ensure that all input data is the same length and valid"
        )
        self.assertEqual(str(cm.exception), expected)
示例#9
0
class TestUltimateOscillator(unittest.TestCase):
    def setUp(self):
        """Create data to use for testing."""
        self.close_data = SampleData().get_sample_close_data()
        self.low_data = SampleData().get_sample_close_data()

        self.buying_pressure_expected = [
            np.nan, 10.42999999999995, 1.6900000000000546, 5.3599999999999,
            0.0, 1.8799999999999955, 2.5200000000000955, 3.0, 0.0, 0.0,
            5.8099999999999454, 2.2400000000000091, 0.0, 0.0,
            1.5500000000000682, 0.0, 0.0, 0.0, 2.0400000000000773, 0.0, 0.0,
            11.549999999999955, 13.560000000000059, 0.0, 0.0, 0.0, 6.0, 0.0,
            0.0, 10.189999999999941, 0.0, 0.0, 0.0, 18.529999999999973,
            8.5399999999999636, 25.300000000000068, 6.3899999999999864, 0.0,
            0.0, 1.0900000000000318, 6.2299999999999045, 17.060000000000059,
            4.4199999999999591, 9.6599999999999682, 0.0, 4.75,
            6.4499999999999318, 7.1900000000000546, 0.0, 0.0,
            5.4600000000000364, 0.0, 0.0, 0.0, 0.0, 7.6899999999999409, 0.0,
            4.5999999999999091, 0.0, 2.3700000000000045, 0.0,
            1.5599999999999454, 0.0, 3.67999999999995, 0.0, 7.4199999999999591,
            0.67000000000007276, 0.0, 12.310000000000059, 0.99000000000000909,
            0.0, 0.0, 0.0, 2.5800000000000409, 3.2599999999999909, 0.0, 0.0,
            10.100000000000023, 0.0, 14.360000000000014, 5.1499999999999773,
            0.029999999999972715, 0.0, 0.0, 0.0, 2.0699999999999363,
            3.9000000000000909, 0.0, 0.0, 2.3000000000000682,
            2.9900000000000091, 0.36000000000001364, 2.6999999999999318,
            3.1000000000000227, 2.6699999999999591, 0.0, 4.7699999999999818,
            1.0899999999999181, 1.1500000000000909, 0.28999999999996362, 0.0,
            0.0, 1.6999999999999318, 0.0, 1.6699999999999591,
            1.2000000000000455, 0.82000000000005002, 0.0, 0.0, 0.0, 0.0, 0.0,
            1.7599999999999909, 0.0, 2.6700000000000728, 0.0, 0.0, 0.0,
            0.16999999999995907, 0.0, 3.0299999999999727, 0.0, 0.0, 0.0,
            1.7100000000000364, 0.0, 5.3600000000000136
        ]

        self.avg7_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, np.nan, np.nan, np.nan, 0.18285945290392161,
            0.17145073700542943, 0.15453960077269807, 0.12936261959304679,
            0.10297114662662256, 0.029821386419073698, 0.022715768159960414,
            0.018412144835368464, 0.015601234192343416, 0.054152056104558616,
            0.10631216226799316, 0.10686031408666936, 0.11433023118709769,
            0.11238922209291925, 0.1528446497003047, 0.18089312710780328,
            0.12651186857253763, 0.11760860090076951, 0.13190483949812562,
            0.14903801896345339, 0.13901768847672979, 0.23107249175315753,
            0.25934433075798669, 0.34266308813058027, 0.25421822272215994,
            0.21007472024596915, 0.17943628423977778, 0.17878480105149971,
            0.1425744355491588, 0.1691657866948259, 0.11353077816492431,
            0.13277635848926303, 0.14278289278289255, 0.17248812422657755,
            0.19396190247993231, 0.19893164109567038, 0.13310650159875353,
            0.12119248217757606, 0.11282997445359086, 0.12742426670940871,
            0.10842415985467771, 0.075671472154095198, 0.034142071035517994,
            0.083709975173467344, 0.081318409498484845, 0.07646363466683169,
            0.076841315493309137, 0.10145328719723098, 0.11559690900488793,
            0.13831329410761362, 0.078944932901433493, 0.12354548214104888,
            0.089424206815510443, 0.18482538121003361, 0.17043856284362588,
            0.1774966711051926, 0.3159275780635013, 0.33100079218378725,
            0.28421472229604133, 0.24376068376068427, 0.14164047450065997,
            0.14590224182285974, 0.16077278454430941, 0.052554632194521556,
            0.043922984356197507, 0.12061138014527868, 0.12381544197607612,
            0.2472661987922315, 0.27055724751008314, 0.2460363575994024,
            0.25881942018861354, 0.25171974522293006, 0.15659560827055607,
            0.16597542242703478, 0.08320274606372656, 0.045224994346875796,
            0.049687890137328668, 0.077594295364985078, 0.1200682448283229,
            0.14544999374139592, 0.17482517482517632, 0.18074191002367831,
            0.23811129848229276, 0.22028081123244889, 0.24577777777777615,
            0.20731018910527554, 0.20986984815618095, 0.1797551918580656,
            0.14542007001166771, 0.11823777129899547, 0.1692365550958991,
            0.076839237057219192, 0.085602420359493697, 0.08254076086956369,
            0.087202718006794869, 0.076890156918687488, 0.051881798055635704,
            0.026432664756447399, 0.021497232741043142, 0.0099102193003978573,
            0.010931740180500995, 0.0066994023828555816, 0.017134016631212758,
            0.019600035395098022, 0.022937917464920292, 0.025534612945991457,
            0.029924538121259552, 0.020594633792603553, 0.045656062845142745,
            0.022322985699336825, 0.018800305504964063, 0.016608709191882141,
            0.024853209151649978, 0.023520071453381679, 0.050111634830067107
        ]

        self.avg14_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, np.nan, 0.05877669935803001, 0.056880583558724981,
            0.052965424682047853, 0.068760907504363089, 0.068904116122672943,
            0.070771893727853252, 0.06805074971164933, 0.10146008919940978,
            0.1194548790076001, 0.14377757546046646, 0.13004025261989025,
            0.12887750189146424, 0.12773536028359114, 0.12790365174681664,
            0.12541313820603447, 0.15009890799144396, 0.15045174000707989,
            0.14112148176104269, 0.13315254608705171, 0.13175950691940916,
            0.13646490201261172, 0.11930393747234914, 0.10640036532314273,
            0.075790079217650699, 0.075046068241216887, 0.075420313010639409,
            0.075898947573572365, 0.075625061764996462, 0.070281945758032802,
            0.060398241804797845, 0.056576309357062357, 0.05210946737030292,
            0.054573184543134388, 0.053725452751519603, 0.045020688745651995,
            0.037538525470097041, 0.039446152726478494, 0.048612176046618223,
            0.040766157943254645, 0.061077576570533691, 0.068680374932521451,
            0.074837571187935617, 0.11290729274647651, 0.098579978875718566,
            0.10346420323325607, 0.093772230485675456, 0.098375114488279722,
            0.10420234018264843, 0.12213654316343796, 0.11665911835748806,
            0.1164306162422783, 0.14033834586466207, 0.13706124247319762,
            0.15476856383722606, 0.16265180835446427, 0.15564773452456926,
            0.11177173679855333, 0.10743050929570633, 0.10615444454417611,
            0.11122630331753533, 0.12315051399370143, 0.1158362140898796,
            0.10644467029353745, 0.11537173985818221, 0.12745403552508602,
            0.099485967880974746, 0.1114145635220955, 0.07671158480703319,
            0.070519785496477624, 0.073479389927215782, 0.0948673917191378,
            0.099919140579877497, 0.10541875753685792, 0.099403266331658607,
            0.08487538138447509, 0.08567314614830801, 0.094225047886864338,
            0.087578345181507727, 0.084882253079701306, 0.091857471887277289,
            0.086060606060605699, 0.071950534007869119, 0.053328290468986128,
            0.047190509836004375, 0.026083519957844675, 0.020242435019709067,
            0.020027996123613487, 0.017552042419481478, 0.02218256567801407,
            0.020500187883595779, 0.015863402817121765, 0.014364562694594036,
            0.010693805023827019, 0.0079791540918928722, 0.010453629999040943,
            0.010154648779578898, 0.010133878765340266, 0.010060388702829557,
            0.012295945234333899, 0.012240832481455308, 0.016931853867894968
        ]

        self.avg28_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            0.069232148696688686, 0.072185568081458706, 0.07111563776319689,
            0.067257744021141527, 0.066289554523854419, 0.066510187481011715,
            0.066532356891463904, 0.058478265151365845, 0.054542485439007048,
            0.044062503108246408, 0.041089591403223658, 0.045023910946792971,
            0.045615275813295497, 0.045404112377850032, 0.049083135881322702,
            0.041303441084462898, 0.039480629156550123, 0.034942227848644418,
            0.035436262056434659, 0.034795822512018529, 0.033684186801298227,
            0.030419416599665631, 0.031216610869720027, 0.03821326034878969,
            0.03597063519000384, 0.046608983248370692, 0.051819139453852948,
            0.053840812977340065, 0.056002976320742234, 0.052501577023339893,
            0.05479408591915725, 0.055197525027577979, 0.061227859762562814,
            0.062141168524147264, 0.064284028138425958, 0.066746195699613153,
            0.071531028986951031, 0.070121732720404006, 0.074971565777834079,
            0.072496449441125974, 0.076837254967589419, 0.078577459325012061,
            0.070610313503805103, 0.072037525652301274, 0.074757200367932528,
            0.076562423888158176, 0.078507030293948663, 0.077247334973349638,
            0.077262083300444484, 0.078989132773832404, 0.083291963152959114,
            0.07286361063950178, 0.075559984402755381, 0.055529549444119225,
            0.046953261398437175, 0.045665408244291772, 0.044225580140312956,
            0.042866483588335245, 0.043821365135752285, 0.039849780930523701,
            0.03712771267619025, 0.035948126071597065, 0.034833026704577129,
            0.030714043131261602, 0.026447151261099689, 0.024789014309496881,
            0.02392019876960871, 0.020086847876420795, 0.01682439537329122,
            0.015856047068738097, 0.012735281747817804, 0.01123423767672913,
            0.013379463377165625
        ]

        self.uo_expected = [
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan,
            np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, 4.9480617764975188,
            7.5403136054989117, 7.2791699210180134, 6.8190173918439161,
            6.8971597940479965, 8.2824891681853536, 8.8423052914617077,
            9.8115498931716356, 6.417350321395686, 9.0781254823668345,
            6.8616962078824963, 12.949722698971353, 12.353289672183456,
            12.929513416778452, 21.980114766118298, 22.3209509653007,
            19.760970354388967, 17.107563198039031, 11.41069127193763,
            11.811563859553633, 13.157834447220168, 6.7708026013246849,
            6.2824254397009529, 11.447649609417551, 11.505069829152911,
            19.217298658453554, 20.847882088615915, 19.27545303462983,
            18.783201866747184, 18.20345109294961, 12.76407725842477,
            13.450740305296968, 9.1477124572124566, 6.7816224870201376,
            6.7989275610687931, 8.6838122410845422, 11.524458276434498,
            12.155623477827673, 14.24430560175329, 13.555532273570078,
            16.718885998424511, 15.809421201560561, 17.763660115045507,
            15.73023661761655, 16.07248725809103, 14.205567485481968,
            11.856258187279566, 10.307781606656395, 13.466548563682421,
            8.0214681623674942, 8.5066592964333783, 8.3820228270330155,
            8.5213152650163746, 7.2427320733515348, 5.1591004936993183,
            3.5111012420298584, 2.6054507288596414, 1.7570318689906403,
            1.8229188300711889, 1.4535925042986997, 2.1432701508152774,
            2.2192663345597241, 2.2615928885500258, 2.3083088614916503,
            2.3933273399113135, 1.7589408237670978, 3.2493101449751656,
            1.8526869747560841, 1.6041910703404001, 1.463023732027511,
            1.9534286974726502, 1.8542312636166636, 3.538424434760342
        ]

    def test_buying_pressure(self):
        bp = ultimate_oscillator.buying_pressure(self.close_data,
                                                 self.low_data)
        np.testing.assert_array_equal(bp, self.buying_pressure_expected)

    def test_average_7(self):
        avg7 = ultimate_oscillator.average_7(self.close_data, self.low_data)
        np.testing.assert_array_equal(avg7, self.avg7_expected)

    def test_average_14(self):
        avg14 = ultimate_oscillator.average_14(self.close_data, self.low_data)
        np.testing.assert_array_equal(avg14, self.avg14_expected)

    def test_average_28(self):
        avg28 = ultimate_oscillator.average_28(self.close_data, self.low_data)
        np.testing.assert_array_equal(avg28, self.avg28_expected)

    def test_ultimate_oscillator(self):
        uo = ultimate_oscillator.ultimate_oscillator(self.close_data,
                                                     self.low_data)
        np.testing.assert_array_equal(uo, self.uo_expected)

    def test_uo_invalid_data(self):
        self.close_data.append(0)
        with self.assertRaises(Exception) as cm:
            ultimate_oscillator.ultimate_oscillator(self.close_data,
                                                    self.low_data)
        expected = "Error: mismatched data lengths, check to ensure that all input data is the same length and valid"
        self.assertEqual(str(cm.exception), expected)
示例#10
0
class TestChaikinMoneyFlow(unittest.TestCase):
    def setUp(self):
        """Create data to use for testing."""
        self.close_data = SampleData().get_sample_close_data()
        self.high_data = SampleData().get_sample_high_data()
        self.low_data = SampleData().get_sample_low_data()
        self.volume = SampleData().get_sample_volume()

        self.cmf_period_6_expected = [np.nan, np.nan, np.nan, np.nan, np.nan,
        0.003312520909302368, -0.0048613550605095908, 0.0076368288342983631,
        0.0065287223745628502, 0.010712462475030939, -0.016573767174777168,
        -0.022118018755417572, -0.029221567084304925, -0.033484757183585401,
        -0.041735293635758459, -0.042843154065898718, -0.020876675876256596,
        -0.024415870658692791, -0.026707069318664234, -0.080030925467134043,
        -0.057147769053649287, -0.065604808877281429, -0.065939141131154788,
        -0.046243722522452443, -0.039084580765582945, -0.023732518823802458,
        -0.014371385759892283, -0.0053841310735424572, -0.0073566431080532707,
        -0.023993372933344703, -0.029960428245405232, -0.020848896421251553,
        -0.033221845069711479, -0.023632410244811587, -0.0097050088230458322,
        -0.018370449199058135, 0.010361413074362698, 0.02995516308307368,
        0.035669013751713101, 0.042225745231989881, 0.016262549780505727,
        0.0013941588013852452, 0.012306879131758812, 0.0035702426675349218,
        0.016855940611040648, 0.017195749786707487, 0.035142495645697887,
        0.081928386974877379, 0.074639303829334827, 0.059587959294833265,
        0.025673521303580357, -0.0058017021658257461, -0.017649987961487128,
        -0.037743680456322731, -0.030009726186828133, -0.035697538763242824,
        -0.037644159883863451, 0.0048928404466888412, -0.00090102511926272368,
        0.0035648800422953685, -0.015052762227444404, 0.014071386096076447,
        0.03508329543861937, 0.012371868491255654, 0.021424949522295789,
        0.020558640966843865, 0.064448403594026746, 0.052176586584946193,
        -0.019569995625100225, -0.028186526955462123, -0.031094787908345023,
        -0.032460504024932439, -0.058198150002280631, -0.043503190797697537,
        -0.00095594109778578086, -0.010813889014902886, -0.011190581326110635,
        0.0078677120282683397, 0.037517542650319986, 0.044658480463605946,
        0.055190082593348115, 0.071897357104455467, 0.073915056586359301,
        0.07101148964635963, 0.059849856842446009, 0.059094210936938292,
        0.03287724077897463, 0.044715034918426266, 0.045192127365791333,
        0.033795150822328299, 0.075347022889300272, 0.060429544725187107,
        0.081840951426436659, 0.037721963312571133, 0.032639794237848713,
        0.022413515752428483, 0.0050258198847992113, 0.010372825841295268,
        -0.00083449577106293733, 0.0085669902231504426, 0.027089129950182974,
        0.03956141033382661, 0.044011605196096544, 0.038891332225638738,
        0.027574878189471158, 0.046321405729603714, 0.041172145145542835,
        0.034642007487542176, 0.014260177160802688, 0.0082988065208204845,
        0.017126773507882866, 0.014741503914037739, 0.016010639972291973,
        0.025326112362985931, 0.034629648875386297, 0.014997042039988612,
        0.01069599087866673, 0.011127907594170367, -0.0080168866293592808,
        -0.013671648032558471, -0.026946141394489087, -0.021756121749873004,
        -0.032467558230566636, -0.041891312663086974, -0.035822604814123339,
        -0.031212648439507711, -0.040638532850568315]

        self.cmf_period_8_expected = [np.nan, np.nan, np.nan, np.nan, np.nan,
        np.nan, np.nan, 0.0081185024674913005, 0.0025371802819565883,
        -0.0010644977834666388, -0.0056728301312701027, -0.0041694952276188808,
        -0.027797521862243494, -0.014603048497697219, -0.019669640273245477,
        -0.043772436549748425, -0.032246251569552471, -0.035485601011810967,
        -0.038497579799628007, -0.056104562803820458, -0.040592663917418982,
        -0.06878156913062386, -0.051868037982436971, -0.039076571889279231,
        -0.050731239889772968, -0.053229551728136919, -0.030648158861072514,
        -0.012411553304442827, -0.013827755337462506, -0.0087894337832712336,
        -0.02372021526121806, -0.034115196226625788, -0.025887629022838941,
        -0.012678892347838255, -0.010229402522448557, -0.018380015220900599,
        -0.0091200962156104716, 0.0079882390294293473, 0.025256686134179286,
        0.036646526288534528, 0.022578841768494146, 0.00037994399427053205,
        0.0094056760373523677, 0.015170928752505568, 0.024780406255827572,
        0.023985104430904548, 0.025206632383119276, 0.027437965711461888,
        0.040771722434282294, 0.057773298969144654, 0.042888453362141608,
        0.034118953538708363, 0.0086195557061872017, -0.0053082066228187265,
        -0.0073276947410392933, -0.040339954980860432, -0.044024960336941268,
        -0.008372116834863547, -0.010894944701009993, 0.002069543889197569,
        -0.0070732478803152863, -0.0027650689324161004, 0.003099300977691961,
        0.028980930474517174, 0.032897879595979874, 0.011512894812962913,
        0.037606534276955164, 0.03161087470746074, 0.0014348407984348796,
        -0.0076208128785508226, -0.02255891656436438, -0.024463692779761438,
        -0.031399038040626388, -0.025163213707663782, -0.029551186437460762,
        -0.03645993477631073, -0.015706223008120388, 0.0015586402908818618,
        0.019379406270457197, 0.033617486164410258, 0.056610182531136054,
        0.051801585060995865, 0.043696289983268924, 0.064339502557726136,
        0.073499010373059309, 0.069989285678150617, 0.055791870559251916,
        0.053098040911644169, 0.03330390300209949, 0.034414825993031972,
        0.074668764622390055, 0.06129901630246664, 0.075081747905173607,
        0.037480226477018132, 0.032889925186722319, 0.020106235192252808,
        0.028204580027412218, 0.034341643352812236, 0.021887527518800701,
        0.0071316698495589425, -0.0052750838209651082, 0.015188886014108748,
        0.036061294242859893, 0.050278602384032256, 0.043130532971042447,
        0.034563264668915718, 0.026040168606977436, 0.034587936909265836,
        0.02876909144339216, 0.03469067860193259, 0.024532129642417532,
        0.014883586477139587, 0.016726987370967537, 0.012188281555131105,
        0.016841358495234233, 0.020078868602802388, 0.02524487617720117,
        0.017970496234460627, -0.0030203029703223822, -0.0096650004775112285,
        -0.016473215917856138, -0.015549623508933264, -0.022702905873274063,
        -0.024710955783392941, -0.038703957202912316, -0.041452776726492772,
        -0.041157742958483921]

        self.cmf_period_10_expected = [np.nan, np.nan, np.nan, np.nan, np.nan,
        np.nan, np.nan, np.nan, np.nan, 0.00097005442845879376,
        -0.0064199268473497896, -0.00981630771032585, -0.01539385491408015,
        -0.0019407376530060584, -0.021201955642506994, -0.025200322249567,
        -0.016200232414935737, -0.037811531108227089, -0.044026758965205533,
        -0.058534077028334068, -0.046548203377963476, -0.051983201626286779,
        -0.039512066195189634, -0.046003067307706036, -0.042132407072485917,
        -0.046334449727507415, -0.04133207922271704, -0.039018647891641382,
        -0.027334922695207469, -0.013686335276416654, -0.025804171596085258,
        -0.019944595085910129, -0.021723804450678588, -0.024950741592236047,
        -0.0092280984329375388, -0.010856808489330882, -0.0096349938344056571,
        0.0029175322839710091, 0.0082428396230406504, 0.019496326105300225,
        0.017285768031592645, 0.001954688027274251, 0.014596209539885734,
        0.012571839892109608, 0.020738139163870514, 0.030856858152494813,
        0.03049958536258458, 0.031648221684272407, 0.030366540308311901,
        0.01776324429095813, 0.025830127055555277, 0.040411485921986831,
        0.026592245316573945, 0.027352531826117733, 0.011207243951777237,
        -0.015716720734726072, -0.024814013216715024, -0.016909757167403869,
        -0.020703472631734419, -0.0074657409934277136, -0.014086706455012497,
        -0.0029493218051483677, 0.006586361206931457, 0.010589147609965469,
        0.0058748142910560203, 0.025036458880156737, 0.042389180311841836,
        0.021170442660274864, -0.00465179736632976, -0.011478833549338071,
        -0.0063553451892820632, -0.0096521313596829271, -0.024853981082800104,
        -0.019947952803719058, -0.012644857452069816, -0.02282098981637035,
        -0.035389803360523206, -0.022302450718866752, 0.0096606229097797279,
        0.023530102149541612, 0.039575306318488879, 0.041663203623864616,
        0.046846269401670804, 0.049147804760104809, 0.046532703832447543,
        0.064532281083369877, 0.067884435413460148, 0.063432902363722246,
        0.0517389246620805, 0.043502469230294938, 0.058961336245194944,
        0.057160593743307196, 0.074671739501174617, 0.04045293665095788,
        0.033758229773749648, 0.022087082552981425, 0.028947816115888845,
        0.030952954384161221, 0.038982492918535165, 0.028150926559148217,
        0.014865469834815303, 0.01170230670122519, 0.0083995509197173843,
        0.030907101733504111, 0.036899328396437309, 0.04492090321100161,
        0.039661457831712481, 0.026671091384831067, 0.018272102875036875,
        0.034633486248171697, 0.033332625706768454, 0.034554336623121552,
        0.02330355950897256, 0.012915875614998074, 0.01725568578495628,
        0.010453027043024619, 0.013367439404347276, 0.021473243280857524,
        0.012916789497828559, 0.0011786722377113861, -0.010994206543604062,
        -0.012037897092003943, -0.015417115757289098, -0.01932122426096974,
        -0.029475944251071699, -0.027951042217520154, -0.042543393896090208]

    def test_cmf_period_6(self):
        period = 6
        cmf = chaikin_money_flow.chaikin_money_flow(self.close_data, self.high_data, self.low_data, self.volume, period)
        np.testing.assert_array_equal(cmf, self.cmf_period_6_expected)

    def test_cmf_period_8(self):
        period = 8
        cmf = chaikin_money_flow.chaikin_money_flow(self.close_data, self.high_data, self.low_data, self.volume, period)
        np.testing.assert_array_equal(cmf, self.cmf_period_8_expected)

    def test_cmf_period_10(self):
        period = 10
        cmf = chaikin_money_flow.chaikin_money_flow(self.close_data, self.high_data, self.low_data, self.volume, period)
        np.testing.assert_array_equal(cmf, self.cmf_period_10_expected)

    def test_cmf_invalid_period(self):
        period = 128
        with self.assertRaises(Exception) as cm:
            chaikin_money_flow.chaikin_money_flow(self.close_data, self.high_data, self.low_data, self.volume, period)
        expected = "Error: data_len < period"
        self.assertEqual(str(cm.exception), expected)

    def test_cmf_invalid_data(self):
        self.close_data.append(1)
        period = 6
        with self.assertRaises(Exception) as cm:
            chaikin_money_flow.chaikin_money_flow(self.close_data, self.high_data, self.low_data, self.volume, period)
        expected = ("Error: mismatched data lengths, check to ensure that all input data is the same length and valid")
        self.assertEqual(str(cm.exception), expected)