def alpha43(df): """ Alpha#43 (ts_rank((volume / adv20), 20) * ts_rank((-1 * delta(close, 7)), 8)) """ return (u.ts_rank((df.volume / u.adv(df, 20)), 20) * u.ts_rank( (-1 * u.delta(df.close, 7)), 8))
def alpha26(df): """ Alpha#26 (-1 * ts_max(correlation(ts_rank(volume, 5), ts_rank(high, 5), 5), 3)) """ return ( -1 * u.ts_max(u.corr(u.ts_rank(df.volume, 5), u.ts_rank(df.high, 5), 5), 3))
def alpha35(df): """ Alpha#35 ((Ts_Rank(volume, 32) * (1 - Ts_Rank(((close + high) - low), 16))) * (1 - Ts_Rank(returns, 32))) """ return ((u.ts_rank(df.volume, 32) * (1 - u.ts_rank(((df.close + df.high) - df.low), 16))) \ * (1 - u.ts_rank(df.returns, 32)))
def alpha17(df): """ Alpha#17 (((-1 * rank(ts_rank(close, 10))) * rank(delta(delta(close, 1), 1))) * rank(ts_rank((volume / adv20), 5))) """ temp1 = (-1 * u.rank(u.ts_rank(df.close, 10))) temp2 = u.rank(u.delta(u.delta(df.close, 1), 1)) temp3 = u.rank(u.ts_rank((df.volume / u.adv(df, 20)), 5)) return ((temp1 * temp2) * temp3)
def alpha94(df): """ Alpha#94 ((rank((vwap - ts_min(vwap, 11.5783)))^Ts_Rank(correlation(Ts_Rank(vwap, 19.6462), Ts_Rank(adv60, 4.02992), 18.0926), 2.70756)) * -1) """ temp1 = u.rank((df.vwap - u.ts_min(df.vwap, 12))) temp2 = u.ts_rank( u.corr(u.ts_rank(df.vwap, 20), u.ts_rank(u.adv(df, 60), 4), 18), 3) return ((temp1**temp2) * -1)
def alpha71(df): """ Alpha#71 max(Ts_Rank(decay_linear(correlation(Ts_Rank(close, 3.43976), Ts_Rank(adv180, 12.0647), 18.0175), 4.20501), 15.6948), Ts_Rank(decay_linear((rank(((low + open) - (vwap + vwap)))^2), 16.4662), 4.4388)) """ temp1 = u.corr(u.ts_rank(df.close, 3), u.ts_rank(u.adv(df, 180), 12), 18) temp2 = u.ts_rank( u.decay_linear((u.rank(((df.low + df.open) - (df.vwap + df.vwap)))**2), 16.4662), 4) return pd.Series(np.where(temp1 > temp2, temp1, temp2), df.index)
def alpha96(df): """ Alpha#96 (max(Ts_Rank(decay_linear(correlation(rank(vwap), rank(volume), 3.83878), 4.16783), 8.38151), Ts_Rank(decay_linear(Ts_ArgMax(correlation(Ts_Rank(close, 7.45404), Ts_Rank(adv60, 4.13242), 3.65459), 12.6556), 14.0365), 13.4143)) * -1) """ temp1 = u.ts_rank( u.decay_linear(u.corr(u.rank(df.vwap), u.rank(df.volume), 4), 4.16783), 8) temp2 = u.corr(u.ts_rank(df.close, 7), u.ts_rank(u.adv(df, 60), 4), 4) temp3 = u.ts_rank(u.decay_linear(u.ts_argmax(temp2, 13), 14.0365), 13) return pd.Series(np.where(temp1 > temp3, temp1, temp3), index=df.index)
def alpha92(df): """ Alpha#92 min(Ts_Rank(decay_linear(((((high + low) / 2) + close) < (low + open)), 14.7221), 18.8683), Ts_Rank(decay_linear(correlation(rank(low), rank(adv30), 7.58555), 6.94024), 6.80584)) """ temp1 = u.ts_rank( u.decay_linear(((((df.high + df.low) / 2) + df.close) < (df.low + df.open)), 14.7221), 19) temp2 = u.ts_rank( u.decay_linear(u.corr(u.rank(df.low), u.rank(u.adv(df, 30)), 8), 6.94024), 7) return pd.Series(np.where(temp1 < temp2, temp1, temp2), index=df.index)
def alpha85(df): """ Alpha#85 (rank(correlation(((high * 0.876703) + (close * (1 - 0.876703))), adv30, 9.61331))^rank(correlation(Ts_Rank(((high + low) / 2), 3.70596), Ts_Rank(volume, 10.1595), 7.11408))) """ temp1 = u.rank( u.corr(((df.high * 0.876703) + (df.close * (1 - 0.876703))), u.adv(df, 30), 10)) temp2 = u.rank( u.corr(u.ts_rank(((df.high + df.low) / 2), 4), u.ts_rank(df.volume, 10), 7)) return (temp1**temp2)
def alpha72(df): """ Alpha#72 (rank(decay_linear(correlation(((high + low) / 2), adv40, 8.93345), 10.1519)) / rank(decay_linear(correlation(Ts_Rank(vwap, 3.72469), Ts_Rank(volume, 18.5188), 6.86671),2.95011))) """ temp1 = u.rank( u.decay_linear(u.corr(((df.high + df.low) / 2), u.adv(df, 40), 9), 10)) temp2 = u.rank( u.decay_linear( u.corr(u.ts_rank(df.vwap, 4), u.ts_rank(df.volume, 19), 7), 2.95011)) return (temp1 / temp2)
def alpha88(df): """ Alpha#88 min(rank(decay_linear(((rank(open) + rank(low)) - (rank(high) + rank(close))), 8.06882)), Ts_Rank(decay_linear(correlation(Ts_Rank(close, 8.44728), Ts_Rank(adv60, 20.6966), 8.01266), 6.65053), 2.61957)) """ temp1 = u.rank( u.decay_linear(((u.rank(df.open) + u.rank(df.low)) - (u.rank(df.high) + u.rank(df.close))), 8)) temp2 = u.ts_rank( u.decay_linear( u.corr(u.ts_rank(df.close, 8), u.ts_rank(u.adv(df, 60), 21), 8), 6.65053), 3) return pd.Series(np.where(temp1 < temp2, temp1, temp2), index=df.index)
def alpha38(df): """ Alpha#38 ((-1 * rank(Ts_Rank(close, 10))) * rank((close / open))) """ return ((-1 * u.rank(u.ts_rank(df.close, 10))) * u.rank( (df.close / df.open)))
def alpha84(df): """ Alpha#84 SignedPower(Ts_Rank((vwap - ts_max(vwap, 15.3217)), 20.7127), delta(close, 4.96796)) """ return (u.ts_rank((df.vwap - u.ts_max(df.vwap, 15)), 21)**u.delta(df.close, 5))
def alpha86(df): """ Alpha#86 ((Ts_Rank(correlation(close, sum(adv20, 14.7444), 6.00049), 20.4195) < rank(((open + close) - (vwap + open)))) * -1) """ temp1 = u.ts_rank(u.corr(df.close, u.ts_sum(u.adv(df, 20), 15), 6), 20) temp2 = u.rank(((df.open + df.close) - (df.vwap + df.open))) return ((temp1 < temp2) * -1)
def alpha95(df): """ Alpha#95 (rank((open - ts_min(open, 12.4105))) < Ts_Rank((rank(correlation(sum(((high + low) / 2), 19.1351), sum(adv40, 19.1351), 12.8742))^5), 11.7584)) """ temp1 = u.rank((df.open - u.ts_min(df.open, 12))) temp2 = u.corr(u.ts_sum(((df.high + df.low) / 2), 19), u.ts_sum(u.adv(df, 40), 19), 13) return (temp1 < u.ts_rank((u.rank(temp2)**5), 12))
def alpha7(df): """ Alpha#7 ((adv20 < volume) ? ((-1 * ts_rank(abs(delta(close, 7)), 60)) * sign(delta(close, 7))) : (-1 * 1)) """ iftrue = ((-1 * u.ts_rank(abs(u.delta(df.close, 7)), 60)) * np.sign(u.delta(df.close, 7))) return pd.Series(np.where(u.adv(df, 20) < df.volume, iftrue, (-1 * 1)), index=df.index)
def alpha52(df): """ Alpha#52 ((((-1 * ts_min(low, 5)) + delay(ts_min(low, 5), 5)) * rank(((sum(returns, 240) - sum(returns, 20)) / 220))) * ts_rank(volume, 5)) """ temp1 = ((-1 * u.ts_min(df.low, 5)) + u.delay(u.ts_min(df.low, 5), 5)) temp2 = u.rank( ((u.ts_sum(df.returns, 240) - u.ts_sum(df.returns, 20)) / 220)) return ((temp1 * temp2) * u.ts_rank(df.volume, 5))
def alpha68(df): """ Alpha#68 ((Ts_Rank(correlation(rank(high), rank(adv15), 8.91644), 13.9333) < rank(delta(((close * 0.518371) + (low * (1 - 0.518371))), 1.06157))) * -1) """ temp1 = u.ts_rank(u.corr(u.rank(df.high), u.rank(u.adv(df, 15)), 9), 14) temp2 = u.rank( u.delta(((df.close * 0.518371) + (df.low * (1 - 0.518371))), 1)) return u.rank( u.delta(((df.close * 0.518371) + (df.low * (1 - 0.518371))), 1))
def alpha73(df): """ Alpha#73 (max(rank(decay_linear(delta(vwap, 4.72775), 2.91864)), Ts_Rank(decay_linear(((delta(((open * 0.147155) + (low * (1 - 0.147155))), 2.03608) / ((open * 0.147155) + (low * (1 - 0.147155)))) * -1), 3.33829), 16.7411)) * -1) """ temp1 = u.rank(u.decay_linear(u.delta(df.vwap, 5), 2.91864)) temp2 = u.delta(((df.open * 0.147155) + (df.low * (1 - 0.147155))), 2) temp3 = ((df.open * 0.147155) + (df.low * (1 - 0.147155))) temp4 = u.ts_rank(u.decay_linear(((temp2 / temp3) * -1), 2), 17) return pd.Series(np.where(temp1 > temp4, temp1 * -1, temp4 * -1), df.index)
def alpha66(df): """ Alpha#66 ((rank(decay_linear(delta(vwap, 3.51013), 7.23052)) + Ts_Rank(decay_linear(((((low * 0.96633) + (low * (1 - 0.96633))) - vwap) / (open - ((high + low) / 2))), 11.4157), 6.72611)) * -1) """ temp1 = u.rank(u.decay_linear(u.delta(df.vwap, 4), 7.23052)) temp2 = (((df.low * 0.96633) + (df.low * (1 - 0.96633))) - df.vwap) temp3 = (df.open - ((df.high + df.low) / 2)) return ((temp1 + u.ts_rank(u.decay_linear( (temp2 / temp3), 11.4157), 7)) * -1)
def alpha98(df): """ Alpha#98 (rank(decay_linear(correlation(vwap, sum(adv5, 26.4719), 4.58418), 7.18088)) - rank(decay_linear(Ts_Rank(Ts_ArgMin(correlation(rank(open), rank(adv15), 20.8187), 8.62571), 6.95668), 8.07206))) """ temp1 = u.ts_rank( u.ts_argmin(u.corr(u.rank(df.open), u.rank(u.adv(df, 15)), 21), 9), 7) temp2 = u.rank(u.decay_linear(temp1, 8.07206)) temp3 = u.rank( u.decay_linear(u.corr(df.vwap, u.ts_sum(u.adv(df, 5), 26), 5), 7)) return (temp3 - temp2)
def alpha36(df): """ Alpha#36 (((((2.21 * rank(correlation((close - open), delay(volume, 1), 15))) + (0.7 * rank((open - close)))) + (0.73 * rank(Ts_Rank(delay((-1 * returns), 6), 5)))) + rank(abs(correlation(vwap, adv20, 6)))) + (0.6 * rank((((sum(close, 200) / 200) - open) * (close - open))))) """ temp1 = (2.21 * u.rank(u.corr((df.close - df.open), u.delay(df.volume, 1), 15))) temp2 = (0.7 * u.rank((df.open - df.close))) temp3 = (0.73 * u.rank(u.ts_rank(u.delay((-1 * df.returns), 6), 5))) temp4 = u.rank(abs(u.corr(df.vwap, u.adv(df, 20), 6))) temp5 = (0.6 * u.rank( (((sum(df.close, 200) / 200) - df.open) * (df.close - df.open)))) return ((((temp1 + temp2) + temp3) + temp4) + temp5)
def alpha29(df): """ Alpha#29 (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)) """ temp1 = u.scale( np.log( u.ts_sum( u.ts_min( u.rank(u.rank((-1 * u.rank(u.delta((df.close - 1), 5))))), 2), 1))) temp2 = u.product(u.rank(u.rank(temp1)), 1) temp3 = u.ts_rank(u.delay((-1 * df.returns), 6), 5) return (np.where(temp1 < temp2, temp1, temp2) + temp3)
def alpha4(df): """ Alpha #4 (-1 * Ts_Rank(rank(low), 9)) """ return (-1 * u.ts_rank(u.rank(df.low), 9))