示例#1
0
 def add_indicators(self):
     self.candles = self.candles.drop(['Open_time', 'Close_time'], axis=1)
     self.candles['EMA - 15'] = ema(self.candles['Close'].tolist(), 15)
     self.candles['aaron down'] = aroon_down(self.candles['Close'].tolist(), 25)
     self.candles['aaron up'] = aroon_up(self.candles['Close'].tolist(), 25)
     self.candles['tenkansen'] = tenkansen(self.candles['Close'].tolist())
     self.candles['kijunsen'] = kijunsen(self.candles['Close'].tolist())
     self.candles['momentun'] = momentum(self.candles['Close'], 15)
     return self.candles
示例#2
0
def preProcessCalculation(df, limit):
    df = df.reset_index()
    adx = np.array(
        average_directional_index(df['close'], df['high'], df['low'], limit))
    mfi = np.array(
        money_flow_index(df['close'], df['high'], df['low'], df['volume'],
                         limit - 1))
    atr = np.array(average_true_range(df['close'], limit))
    obv = np.array(on_balance_volume(df['close'], df['volume']))
    rocr = np.array(rate_of_change(df['close'], limit))
    mom = np.array(momentum(df['close'], limit))
    return adx, mfi, atr, obv, rocr, mom
示例#3
0
ans = simple_moving_average(read_float_with_comma(x), 10)

open = dataset_train.iloc[:, 1].values
high = dataset_train.iloc[:, 2].values
low = dataset_train.iloc[:, 3].values
close = read_float_with_comma(dataset_train.iloc[:, 4].values)
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)
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
示例#5
0
 def test_momentum_invalid_period(self):
     period = 128
     with self.assertRaises(Exception) as cm:
         momentum.momentum(self.data, period)
     expected = "Error: data_len < period"
     self.assertEqual(str(cm.exception), expected)
示例#6
0
 def test_momentum_period_10(self):
     period = 10
     mom = momentum.momentum(self.data, period)
     np.testing.assert_array_equal(mom, self.momentum_period_10_expected)