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 alpha21(df): """ Alpha#21 ((((sum(close, 8) / 8) + stddev(close, 8)) < (sum(close, 2) / 2)) ? (-1 * 1) : (((sum(close,2) / 2) < ((sum(close, 8) / 8) - stddev(close, 8))) ? 1 : (((1 < (volume / adv20)) || ((volume /adv20) == 1)) ? 1 : (-1 * 1)))) """ decision1 = (u.ts_sum(df.close, 8) / 8 + u.stddev(df.close, 8)) < (u.ts_sum(df.close, 2) / 2) decision2 = (u.ts_sum(df.close, 2) / 2 < (u.ts_sum(df.close, 8) / 8) - u.stddev(df.close, 8)) decision3 = ((1 < (df.volume / u.adv(df, 20))) | ((df.volume / u.adv(df, 20)) == 1)) return np.where(decision1, (-1 * 1), np.where(decision2, 1, np.where(decision3, 1, (-1 * 1))))
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 alpha28(df): """ Alpha#28 scale(((correlation(adv20, low, 5) + ((high + low) / 2)) - close)) """ return u.scale(((u.corr(u.adv(df, 20), df.low, 5) + ((df.high + df.low) / 2)) - df.close))
def alpha25(df): """ Alpha#25 rank(((((-1 * returns) * adv20) * vwap) * (high - close))) """ return u.rank(((((-1 * df.returns) * u.adv(df, 20)) * df.vwap) * (df.high - df.close)))
def evaluate(self, board_old, board_new): if board_old.is_over(): return -INF if board_new.is_over(): return INF _adv = adv(board_new) - adv(board_old) _back = adv(board_new) - back(board_old) _cent = cent(board_new) - cent(board_old) _cntr = cntr(board_new) - cntr(board_old) _deny = deny(board_new) - deny(board_old) _kcent = kcent(board_new) - kcent(board_old) _mob = mob(board_new) - mob(board_old) _mobil = _mob - _deny _mov = mov(board_new) - mov(board_old) _thret = thret(board_new) - thret(board_old) undenied_mobility = 1 if _mobil > 0 else 0 total_mobility = 1 if _mob > 0 else 0 denial_of_occ = 1 if _deny > 0 else 0 control = 1 if _cent > 0 else 0 _demmo = 1 if denial_of_occ and not total_mobility else 0 _mode_2 = 1 if undenied_mobility and not denial_of_occ else 0 _mode_3 = 1 if not undenied_mobility and denial_of_occ else 0 _moc_2 = 1 if not undenied_mobility and control else 0 _moc_3 = 1 if undenied_mobility and not control else 0 _moc_4 = 1 if not undenied_mobility and not control else 0 return sum([ _moc_2 * (-1) * (2**18), _kcent * (2**16), _moc_4 * (-1) * (2**14), _mode_3 * (-1) * (2**13), _demmo * (-1) * (2**11), _mov * (2**8), _adv * (-1) * (2**8), _mode_2 * (-1) * (2**8), _back * (-1) * (2**6), _cntr * (2**5), _thret * (2**5), _moc_3 * (2**4), piece_score_diff(board_new, board_old.active) * (2**20), position_score(board_new, board_old.active) * (2**14), ])
def alpha39(df): """ Alpha#39 """ temp = (-1 * u.rank( (u.delta(df.close, 7) * (1 - u.rank(u.decay_linear((df.volume / u.adv(df, 20)), 9)))))) return (temp * (1 + u.rank(u.ts_sum(df.returns, 250))))
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 alpha75(df): """ Alpha#75(df) (rank(correlation(vwap, volume, 4.24304)) < rank(correlation(rank(low), rank(adv50), 12.4413))) """ temp1 = u.rank(u.corr(df.vwap, df.volume, 4)) temp2 = u.rank(u.corr(u.rank(df.low), u.rank(u.adv(df, 50)), 12)) return (temp1 < temp2)
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 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 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 alpha47(df): """ Alpha#47 ((((rank((1 / close)) * volume) / adv20) * ((high * rank((high - close))) / (sum(high, 5) / 5))) - rank((vwap - delay(vwap, 5)))) """ temp1 = ((u.rank((1 / df.close)) * df.volume) / u.adv(df, 20)) temp2 = ((df.high * u.rank( (df.high - df.close))) / (u.ts_sum(df.high, 5) / 5)) return ((temp1 * temp2) - u.rank((df.vwap - u.delay(df.vwap, 5))))
def alpha62(df): """ Alpha#62 ((rank(correlation(vwap, sum(adv20, 22.4101), 9.91009)) < rank(((rank(open) + rank(open)) < (rank(((high + low) / 2)) + rank(high))))) * -1) """ temp1 = u.rank(u.corr(df.vwap, u.ts_sum(u.adv(df, 20), 22), 10)) temp2 = u.rank(((u.rank(df.open) + u.rank(df.open)) < (u.rank( ((df.high + df.low) / 2)) + u.rank(df.high)))) return ((temp1 < temp2) * -1)
def alpha78(df): """ Alpha#78 (rank(correlation(sum(((low * 0.352233) + (vwap * (1 - 0.352233))), 19.7428), sum(adv40, 19.7428), 6.83313))^rank(correlation(rank(vwap), rank(volume), 5.77492))) """ temp1 = u.ts_sum(((df.low * 0.352233) + (df.vwap * (1 - 0.352233))), 20) temp2 = u.rank(u.corr(u.rank(df.vwap), u.rank(df.volume), 6)) temp3 = u.rank(u.corr(temp1, u.ts_sum(u.adv(df, 40), 20), 7)) return (temp3**temp2)
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 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 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 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 alpha99(df): """ Alpha#99 ((rank(correlation(sum(((high + low) / 2), 19.8975), sum(adv60, 19.8975), 8.8136)) < rank(correlation(low, volume, 6.28259))) * -1) """ temp1 = u.rank( u.corr(u.ts_sum(((df.high + df.low) / 2), 20), u.ts_sum(u.adv(df, 60), 20), 9)) temp2 = u.rank(u.corr(df.low, df.volume, 6)) return pd.Series(np.where(temp1 < temp2, temp1 * -1, temp2 * -1), index=df.index)
def alpha74(df): """ Alpha#74 ((rank(correlation(close, sum(adv30, 37.4843), 15.1365)) < rank(correlation(rank(((high * 0.0261661) + (vwap * (1 - 0.0261661)))), rank(volume), 11.4791))) * -1) """ temp1 = u.rank(u.corr(df.close, u.ts_sum(u.adv(df, 30), 37), 15)) temp2 = u.rank( u.corr(u.rank(((df.high * 0.0261661) + (df.vwap * (1 - 0.0261661)))), u.rank(df.volume), 11)) 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 alpha64(df): """ Alpha#64 ((rank(correlation(sum(((open * 0.178404) + (low * (1 - 0.178404))), 12.7054), sum(adv120, 12.7054), 16.6208)) < rank(delta(((((high + low) / 2) * 0.178404) + (vwap * (1 -0.178404))), 3.69741))) * -1) """ temp1 = u.ts_sum(((df.open * 0.178404) + (df.low * (1 - 0.178404))), 13) temp2 = u.rank(u.corr(temp1, u.ts_sum(u.adv(df, 120), 18), 17)) temp3 = u.rank( u.delta(((((df.high + df.low) / 2) * 0.178404) + (df.vwap * (1 - 0.178404))), 4)) return ((temp2 < temp3) * -1)
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 alpha81(df): """ Alpha#81 ((rank(Log(product(rank((rank(correlation(vwap, sum(adv10, 49.6054), 8.47743))^4)), 14.9655))) < rank(correlation(rank(vwap), rank(volume), 5.07914))) * -1) """ temp = u.rank( np.log( u.product( u.rank( u.rank(u.corr(df.vwap, u.ts_sum(u.adv(df, 10), 50), 8))**4), 15))) return ((temp < u.rank(u.corr(u.rank(df.vwap), u.rank(df.volume), 5))) * -1)
def alpha77(df): """ Alpha#77 min(rank(decay_linear(((((high + low) / 2) + high) - (vwap + high)), 20.0451)), rank(decay_linear(correlation(((high + low) / 2), adv40, 3.1614), 5.64125))) """ temp1 = u.rank( u.decay_linear( ((((df.high + df.low) / 2) + df.high) - (df.vwap + df.high)), 20.0451)) temp2 = u.rank( u.decay_linear(u.corr(((df.high + df.low) / 2), u.adv(df, 40), 3), 5.64125)) return pd.Series(np.where(temp1 > temp2, temp1, temp2), index=df.index)
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 alpha31(df): """ Alpha#31 ((rank(rank(rank(decay_linear((-1 * rank(rank(delta(close, 10)))), 10)))) + rank((-1 * delta(close, 3)))) + sign(scale(correlation(adv20, low, 12)))) """ temp1 = u.rank( u.rank( u.rank( u.decay_linear((-1 * u.rank(u.rank(u.delta(df.close, 10)))), 10)))) temp2 = u.rank((-1 * u.delta(df.close, 3))) + np.sign( u.scale(u.corr(u.adv(df, 20), df.low, 12))) return temp1 + temp2