def test_commodity_channel_index_invalid_period(self):
     period = 128
     with self.assertRaises(Exception) as cm:
         commodity_channel_index.commodity_channel_index(
             self.close_data, self.high_data, self.low_data, period)
     expected = "Error: data_len < period"
     self.assertEqual(str(cm.exception), expected)
 def test_commodity_channel_index_invalid_data(self):
     period = 6
     self.close_data.append(1)
     with self.assertRaises(Exception) as cm:
         commodity_channel_index.commodity_channel_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)
Exemple #3
0
def cci(dataframe, period) -> ndarray:
    from pyti.commodity_channel_index import commodity_channel_index

    return commodity_channel_index(dataframe['close'], dataframe['high'],
                                   dataframe['low'], period)
Exemple #4
0
def cci(df, period):
    return commodity_channel_index(df['close'].tolist(), df['high'].tolist(),
                                   df['low'].tolist(), period)
 def test_cci_period_10(self):
     period = 10
     cci = commodity_channel_index.commodity_channel_index(
         self.close_data, self.high_data, self.low_data, period)
     np.testing.assert_array_equal(cci, self.cci_period_10_expected)
Exemple #6
0
wma = weighted_moving_average(close, period)

from pyti.momentum import momentum
mome = momentum(close, period)

from pyti.relative_strength_index import relative_strength_index
rsi = relative_strength_index(close, period)

from pyti.moving_average_convergence_divergence import moving_average_convergence_divergence
macd = moving_average_convergence_divergence(close,
                                             short_period=1,
                                             long_period=10)

from pyti.commodity_channel_index import commodity_channel_index
cci = commodity_channel_index(close,
                              high_data=high,
                              low_data=low,
                              period=period)

from pyti.williams_percent_r import williams_percent_r
willr = williams_percent_r(close)

from pyti.accumulation_distribution import accumulation_distribution
acd = accumulation_distribution(close_data=close,
                                low_data=low,
                                high_data=high,
                                volume=volume)

X = []
Y = []
for _ in range(10, len(open) - 1):
    tmp = []
def convert(str):
    period = 10
    dataset_train = pd.read_csv(str)

    x = dataset_train.iloc[:, 4].values

    try:
        open = dataset_train.iloc[:, 1].values
    except Exception:
        open = read_float_with_comma(dataset_train.iloc[:, 1].values)
    try:
        high = dataset_train.iloc[:, 2].values
    except Exception:
        high = read_float_with_comma(dataset_train.iloc[:, 2].values)
    try:
        low = dataset_train.iloc[:, 3].values
    except Exception:
        low = read_float_with_comma(dataset_train.iloc[:, 3].values)
    try:
        close = dataset_train.iloc[:, 4].values
    except Exception:
        close = read_float_with_comma(dataset_train.iloc[:, 4].values)
    try:
        volume = dataset_train.iloc[:, 5].values
    except Exception:
        volume = read_float_with_comma(dataset_train.iloc[:, 5].values)

    from pyti.simple_moving_average import simple_moving_average
    sma = simple_moving_average(close, period)

    from pyti.weighted_moving_average import weighted_moving_average
    wma = weighted_moving_average(close, period)

    from pyti.momentum import momentum
    mome = momentum(close, period)

    from pyti.relative_strength_index import relative_strength_index
    rsi = relative_strength_index(close, period)

    from pyti.moving_average_convergence_divergence import moving_average_convergence_divergence
    macd = moving_average_convergence_divergence(close,
                                                 short_period=1,
                                                 long_period=10)

    from pyti.commodity_channel_index import commodity_channel_index
    cci = commodity_channel_index(close,
                                  high_data=high,
                                  low_data=low,
                                  period=period)

    from pyti.williams_percent_r import williams_percent_r
    willr = williams_percent_r(close)

    from pyti.accumulation_distribution import accumulation_distribution
    acd = accumulation_distribution(close_data=close,
                                    low_data=low,
                                    high_data=high,
                                    volume=volume)

    X = []
    Y = []
    for _ in range(10, len(open)):
        tmp = []
        tmp.append(sma[_])
        tmp.append(wma[_])
        tmp.append(mome[_])
        tmp.append(rsi[_])
        tmp.append(macd[_])
        tmp.append(cci[_])
        tmp.append(willr[_])
        X.append(tmp)
        Y.append([close[_]])

    X, Y = np.array(X), np.array(Y)
    return X, Y