예제 #1
0
 def alpha_41(self):
     """
     formula: (rank((vwap - close)) / rank((vwap + close)))
     :return:
     """
     return _utils.rank((self.vwap - self.close)) / _utils.rank(
         (self.vwap + self.close))
예제 #2
0
 def alpha_16(self):
     """
     formula:(-1 * rank(covariance(rank(high), rank(volume), 5)))
     :return: dataframe rank of cov rank
     """
     return -1 * _utils.rank(
         _utils.covariance(_utils.rank(self.high), _utils.rank(self.volume),
                           5)).fillna(method='backfill')
예제 #3
0
 def alpha_15(self):
     """
     formula: (-1 * sum(rank(correlation(rank(high), rank(volume), 3)), 3))
     """
     df = _utils.correlation(_utils.rank(self.high),
                             _utils.rank(self.volume), 3)
     df = df.replace([-np.inf, np.inf], 0).fillna(method='backfill')
     return (-1 * _utils.ts_sum(_utils.rank(df), 3)).fillna(method='ffill')
예제 #4
0
 def alpha_5(self):
     """
     formula for alpha5: (rank((open - (sum(vwap, 10) / 10)))*(-1*abs(rank((close - vwap)))))
     :return time series rank of a window rank
     """
     return (_utils.rank(self.open -
                         (_utils.ts_sum(self.vwap, window=10) / 10)) * -1 *
             abs(_utils.rank(self.close - self.vwap)))
예제 #5
0
 def alpha_2(self):
     """
     formula for alpha2: (-1*correlation(rank(delta(log(volume), 2)), rank(((close - open) / open)), 6))
     :return: time series df of all stocks
     """
     x1 = _utils.rank(_utils.delta(np.log(self.volume), period=2))
     x2 = _utils.rank((self.close - self.open) / self.open)
     return -1 * _utils.correlation(x1, x2, window=6)
예제 #6
0
 def alpha_13(self):
     """
     formula: (-1 * rank(covariance(rank(close), rank(volume), 5)))
     :return: dataframe backfilled
     """
     df = -1 * _utils.rank(
         _utils.covariance(
             _utils.rank(self.close), _utils.rank(self.volume), window=5))
     return df.fillna(method='backfill')
예제 #7
0
 def alpha_34(self):
     """
     formula: rank(((1 - rank((stddev(returns, 2) / stddev(returns, 5)))) + (1 - rank(delta(close, 1)))))
     :return:
     """
     inner = _utils.stddev(self.returns, 2) / _utils.stddev(self.returns, 5)
     inner = inner.replace([-np.inf, np.inf], 1).fillna(value=1)
     return _utils.rank(2 - _utils.rank(inner) -
                        _utils.rank(_utils.delta(self.close, 1)))
예제 #8
0
 def alpha_36(self):
     """
     formula: (rank(correlation(delay((open - close), 1), close, 200)) + rank((open - close)))
     :return:dataframe, need long range
     """
     return (_utils.rank(
         _utils.correlation(_utils.delay(self.open - self.close, 1),
                            self.close, 200)) +
             _utils.rank(self.open - self.close)).fillna(method='backfill')
예제 #9
0
 def alpha_37(self):
     """
     formula:  ((-1 * rank(Ts_Rank(close, 10))) * rank((close / open)))
     :return:
     """
     inner = self.close / self.open
     inner = inner.replace([-np.inf, np.inf], 1).fillna(value=1)
     return -1 * _utils.rank(_utils.ts_rank(self.open,
                                            10)) * _utils.rank(inner)
예제 #10
0
 def alpha_11(self):
     """
     formula: ((rank(ts_max((vwap - close), 3)) + rank(ts_min((vwap - close), 3)))*rank(delta(volume, 3)))
     :return:df backfilled
     """
     df = (_utils.rank(_utils.ts_max(self.vwap - self.close, window=3)) +
           _utils.rank(_utils.ts_min(self.vwap - self.close, window=3))
           ) * _utils.delta(self.volume, period=3)
     return df.fillna(method='backfill')
예제 #11
0
 def alpha_3(self):
     """
     data size should increse to see the difference
     formula for alpha3: (-1*correlation(rank(open), rank(volume), 10))
     :return:time series df of all stocks
     """
     df = -1 * _utils.correlation(
         _utils.rank(self.open), _utils.rank(self.volume), window=10)
     return df.replace([-np.inf, np.inf], 0)
예제 #12
0
 def alpha_48(self):
     """
     formula: (-1 * ts_max(rank(correlation(rank(volume), rank(vwap), 5)), 5))
     :return:
     """
     df = (-1 * _utils.ts_max(
         _utils.rank(
             _utils.correlation(_utils.rank(self.volume),
                                _utils.rank(self.vwap), 5)), 5))
     return df.fillna(method='bfill')
예제 #13
0
 def alpha_20(self):
     """
     formula: (((-1 * rank((open - delay(high, 1)))) *
     rank((open - delay(close, 1)))) *
     rank((open -delay(low, 1))))
     """
     return -1 * (_utils.rank(self.open - _utils.delay(self.high, 1)) *
                  _utils.rank(self.open - _utils.delay(self.close, 1)) *
                  _utils.rank(self.open - _utils.delay(self.low, 1))
                  ).fillna(method='backfill')
예제 #14
0
 def alpha_27(self):
     """
     formula: ((0.5 < rank((sum(correlation(rank(volume), rank(vwap), 6), 2) / 2.0))) ? (-1* 1) : 1)
     :return replaced nan to -1
     """
     alpha = _utils.rank((_utils.ts_ma(
         _utils.correlation(_utils.rank(self.volume),
                            _utils.rank(self.vwap), 6), 2)))
     alpha[alpha > 0.5] = -1
     alpha[alpha <= 0.5] = 1
     return alpha.fillna(-1)
예제 #15
0
 def alpha_38(self):
     """
     formula:  ((-1 * rank((delta(close, 7) * (1 - rank(decay_linear_pn((volume / adv20), 9)))))) *
     (1 +rank(sum(returns, 250))))
     :return:
     """
     adv20 = _utils.ts_ma(self.volume, 20)
     return ((-1 * _utils.rank(
         _utils.delta(self.close, 7) *
         (1 - _utils.rank(_utils.decay_linear_pn(
             (self.volume / adv20), 9))))) *
             (1 + _utils.rank(_utils.ts_ma(self.returns, 250))))
예제 #16
0
 def alpha_17(self):
     """
     formula: (((-1 * rank(ts_rank(close, 10))) *
     rank(delta(delta(close, 1), 1)))
     *rank(ts_rank((volume / adv20), 5)))
     :return:
     """
     adv20 = _utils.ts_ma(self.volume, 20)
     return -1 * (
         _utils.rank(_utils.ts_rank(self.close, 10)) * _utils.rank(
             _utils.delta(_utils.delta(self.close, period=1), period=1)) *
         _utils.rank(_utils.ts_rank(self.volume / adv20, window=5)))
예제 #17
0
 def alpha_46(self):
     """
     formula: ((((rank((1 / close)) * volume) / adv20) * ((high * rank((high - close)))
     / (sum(high, 5) /5))) - rank((vwap - delay(vwap, 5))))
     :return:
     """
     adv20 = _utils.ts_ma(self.volume, 20)
     df = ((((_utils.rank((1 / self.close)) * self.volume) / adv20) *
            ((self.high * _utils.rank((self.high - self.close))) /
             (_utils.ts_ma(self.high, 5) / 5))) - _utils.rank(
                 (self.vwap - _utils.delay(self.vwap, 5))))
     return df.fillna(method='backfill')
예제 #18
0
 def alpha_44(self):
     """
     formula: (-1 * ((rank((sum(delay(close, 5), 20) / 20)) * correlation(close, volume, 2))
     *rank(correlation(sum(close, 5), sum(close, 20), 2))))
     :return: dataframe, need more stock and long range
     """
     df = _utils.correlation(self.close, self.volume, 2)
     df = df.replace([-np.inf, np.inf], 0).fillna(value=0)
     df = -1 * (_utils.rank(_utils.ts_ma(_utils.delay(self.close, 5), 20)) *
                df * _utils.rank(
                    _utils.correlation(_utils.ts_sum(self.close, 5),
                                       _utils.ts_sum(self.close, 20), 2)))
     return df.fillna(method='backfill')
예제 #19
0
 def alpha_39(self):
     """
     formula: ((-1 * rank(stddev(high, 10))) * correlation(high, volume, 10))
     :return:
     """
     return -1 * _utils.rank(_utils.stddev(
         self.high, 10)) * _utils.correlation(self.high, self.volume, 10)
예제 #20
0
 def alpha_4(self):
     """
     formula for alpha4: (-1*Ts_Rank(rank(low), 9))
     :return time series rank of a window rank
     """
     df = -1 * _utils.ts_rank(_utils.rank(self.low), 9)
     return df.replace([-np.inf, np.inf], 0)
예제 #21
0
 def alpha_22(self):
     """
     formula: (-1 * (delta(correlation(high, volume, 5), 5) * rank(stddev(close, 20))))
     """
     df = _utils.correlation(self.high, self.volume, 5)
     df = df.replace([-np.inf, np.inf], 0).fillna(value=0)
     return -1 * _utils.delta(df, 5) * _utils.rank(
         _utils.stddev(self.close, 20))
예제 #22
0
 def alpha_19(self):
     """
     formula: ((-1 * sign(((close - delay(close, 7)) + delta(close, 7)))) * (1 + rank((1 + sum(returns,250)))))
     be careful with the time range, less than 250 will be nan
     """
     return ((-1 * np.sign((self.close - _utils.delay(self.close, 7)) +
                           _utils.delta(self.close, 7))) *
             (1 + _utils.rank(1 + _utils.ts_sum(self.returns, 250))))
예제 #23
0
 def alpha_43(self):
     """
     formula: (-1 * correlation(high, rank(volume), 5))
     :return:
     """
     df = _utils.correlation(self.high, _utils.rank(self.volume), 5)
     df = df.replace([-np.inf, np.inf], 0).fillna(value=0)
     return -1 * df
예제 #24
0
 def alpha_14(self):
     """
     formula:((-1 * rank(delta(returns, 3))) * correlation(open, volume, 10))
     :return: dataframe need a lot stock to prevent inf
     """
     df = _utils.correlation(self.open, self.volume, window=10)
     df = df.replace([-np.inf, np.inf], 0).fillna(method='backfill')
     return -1 * _utils.rank(_utils.delta(self.returns, period=3)) * df
예제 #25
0
 def alpha_29(self):
     """
     formula: (min(product(rank(rank(scale(log(sum(ts_min(rank(
     rank((-1*rank(delta((close - 1), 5))))), 2), 1))))), 1), 5) +
      ts_rank(delay((-1* returns), 6), 5))
     """
     df = _utils.ts_min(
         _utils.rank(
             _utils.rank(
                 _utils.scale(
                     np.log(
                         _utils.ts_sum(
                             _utils.rank(
                                 _utils.rank(-1 * _utils.rank(
                                     _utils.delta(self.close - 1, 5)))),
                             2))))), 5) + _utils.ts_rank(
                                 _utils.delay(-1 * self.returns, 6), 5)
     return df.fillna(method='backfill')
예제 #26
0
 def alpha_18(self):
     """
     formula:  (-1 * rank(((stddev(abs((close - open)), 5) + (close - open)) + correlation(close, open,10))))
     :return
     """
     df = _utils.correlation(self.close, self.open, 10)
     df = df.replace([-np.inf, np.inf], 0).fillna(value=0)
     return -1 * _utils.rank(
         _utils.stddev(abs(self.close - self.open), window=5) + self.close -
         self.open) + df
예제 #27
0
 def alpha_50(self):
     """
     formula: ((((-1 * ts_min(low, 5)) + delay(ts_min(low, 5), 5)) * rank(((sum(returns, 240) -sum(returns, 20))
     / 220))) * ts_rank(volume, 5))
     :return: long range data needed
     """
     return ((
         (-1 * _utils.delta(_utils.ts_min(self.low, 5), 5)) * _utils.rank(
             ((_utils.ts_sum(self.returns, 240) -
               _utils.ts_sum(self.returns, 20)) / 220))) *
             _utils.ts_rank(self.volume, 5))
예제 #28
0
 def alpha_30(self):
     """
     formula: (((1.0 - rank(((sign((close - delay(close, 1))) + sign((delay(close, 1) - delay(close, 2)))) +
      sign((delay(close, 2) - delay(close, 3))))))* sum(volume, 5)) / sum(volume, 20))
     """
     delta_close = _utils.delta(self.close, 1)  # (close - delay(close, 1)
     inner = np.sign(delta_close) + np.sign(_utils.delay(
         delta_close, 1)) + np.sign(_utils.delay(delta_close, 2))
     df = (1.0 - _utils.rank(inner)) * _utils.ts_sum(
         self.volume, 5) / _utils.ts_sum(self.volume, 20)
     return df.fillna(method='backfill')
예제 #29
0
 def alpha_8(self):
     """
     formula: (-1*rank(((sum(open, 5)*sum(returns, 5)) - delay((sum(open, 5)*sum(returns, 5)), 10))))
     """
     df = -1 * _utils.rank(
         _utils.ts_sum(self.open, window=5) *
         _utils.ts_sum(self.returns, window=5) -
         _utils.delay(_utils.ts_sum(self.open, window=5) *
                      _utils.ts_sum(self.returns, window=5),
                      period=10))
     return df.fillna(method='backfill')
예제 #30
0
 def alpha_10(self):
     """
     formula: rank(((0 < ts_min(delta(close, 1), 4)) ? delta(close, 1) : ((ts_max(delta(close, 1), 4) < 0) ?
      delta(close, 1) : (-1*delta(close, 1)))))
     """
     delta_close = _utils.delta(self.close, period=1)
     condition_1 = _utils.ts_min(delta_close, window=4) > 0
     condition_2 = _utils.ts_max(delta_close, window=4) < 0
     alpha = -1 * delta_close
     alpha[condition_1 | condition_2] = delta_close
     return _utils.rank(alpha)