def alpha55(df): """ Alpha#55 (-1 * correlation(rank(((close - ts_min(low, 12)) / (ts_max(high, 12) - ts_min(low, 12)))), rank(volume), 6)) """ temp1 = (df.close - u.ts_min(df.low, 12)) temp2 = (u.ts_max(df.high, 12) - u.ts_min(df.low, 12)) return (-1 * u.corr(u.rank((temp1 / temp2)), u.rank(df.volume), 6))
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 alpha61(df): """ Alpha#61 (rank((vwap - ts_min(vwap, 16.1219))) < rank(correlation(vwap, adv180, 17.9282))) Rounded the days to int since partial lookback """ return (u.rank((df.vwap - u.ts_min(df.vwap, 16))) < u.rank( u.corr(df.vwap, u.adv(df, 180), 18)))
def alpha65(df): """ Alpha#65 ((rank(correlation(((open * 0.00817205) + (vwap * (1 - 0.00817205))), sum(adv60, 8.6911), 6.40374)) < rank((open - ts_min(open, 13.635)))) * -1) """ temp1 = (df.open * 0.00817205) + (df.vwap * (1 - 0.00817205)) temp2 = u.rank((df.open - u.ts_min(df.open, 14))) return ((u.rank(u.corr(temp1, u.ts_sum(u.adv(df, 60), 9), 6)) < temp2) * -1)
def alpha11(df): """ Alpha#11 ((rank(ts_max((vwap - close), 3)) + rank(ts_min((vwap - close), 3))) * rank(delta(volume, 3))) """ temp1 = u.rank(u.ts_max((df.vwap - df.close), 3)) temp2 = u.rank(u.ts_min((df.vwap - df.close), 3)) temp3 = u.rank(u.delta(df.volume, 3)) return temp1 + (temp2 * temp3)
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 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 alpha9(df): """ Alpha#9 ((0 < ts_min(delta(close, 1), 5)) ? delta(close, 1) : ((ts_max(delta(close, 1), 5) < 0) ? delta(close, 1) : (-1 * delta(close, 1)))) """ tempd1 = u.delta(df.close, 1) tempmin = u.ts_min(tempd1, 5) tempmax = u.ts_max(tempd1, 5) return pd.Series( np.where(tempmin > 0, tempd1, np.where(tempmax < 0, tempd1, (-1 * tempd1))), df.index)
def alpha24(df): """ Alpha#24 Can be shortened without the || (or operator) and just use the <= statement. ((((delta((sum(close, 100) / 100), 100) / delay(close, 100)) < 0.05) || ((delta((sum(close, 100) / 100), 100) / delay(close, 100)) == 0.05)) ? (-1 * (close - ts_min(close, 100))) : (-1 * delta(close, 3))) """ decision = u.delta( (u.ts_sum(df.close, 100) / 100), 100) / u.delay(df.close, 100) <= 0.05 if_true = (-1 * (df.close - u.ts_min(df.close, 100))) if_false = (-1 * u.delta(df.close, 3)) return pd.Series(np.where(decision, if_true, if_false), df.index)
def alpha10(df): """ Alpha#10 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))))) """ tempd1 = u.delta(df.close, 1) tempmin = u.ts_min(tempd1, 4) tempmax = u.ts_max(tempd1, 4) return u.rank( pd.Series( np.where(tempmin > 0, tempd1, np.where(tempmax < 0, tempd1, (-1 * tempd1))), df.index))
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)