Ejemplo n.º 1
0
def test_BBANDS():
    upper, middle, lower = func.BBANDS(series, timeperiod=20,
                                        nbdevup=2.0, nbdevdn=2.0,
                                        matype=talib.MA_Type.EMA)
    i = np.where(~np.isnan(upper))[0][0]
    assert_true(len(upper) == len(middle) == len(lower) == len(series))
    #assert_true(abs(upper[i + 0] - 98.0734) < 1e-3)
    assert_true(abs(middle[i + 0] - 92.8910) < 1e-3)
    assert_true(abs(lower[i + 0] - 87.7086) < 1e-3)
    #assert_true(abs(upper[i + 13] - 93.674) < 1e-3)
    assert_true(abs(middle[i + 13] - 87.679) < 1e-3)
    assert_true(abs(lower[i + 13] - 81.685) < 1e-3)
Ejemplo n.º 2
0
def test_pandas_series():
    import pandas
    input_df = pandas.DataFrame(ford_2012)
    output = talib.SMA(input_df['close'], 10)
    expected = pandas.Series(func.SMA(ford_2012['close'], 10),
                             index=input_df.index)
    pandas.util.testing.assert_series_equal(output, expected)

    # Test kwargs
    output = talib.SMA(real=input_df['close'], timeperiod=10)
    pandas.util.testing.assert_series_equal(output, expected)

    # Test talib.func API
    output = func.SMA(input_df['close'], timeperiod=10)
    pandas.util.testing.assert_series_equal(output, expected)

    # Test multiple outputs such as from BBANDS
    _, output, _ = talib.BBANDS(input_df['close'], 10)
    expected = pandas.Series(func.BBANDS(ford_2012['close'], 10)[1],
                             index=input_df.index)
    pandas.util.testing.assert_series_equal(output, expected)