# from typing import List

# TODO 没有ts_min, ts_max操作符
ALPHA_101_FORMULAS = [
    # Original formulas adapted for WorldQuant Brain syntax
    "rank(ts_arg_max(power(if_else(returns < 0, ts_std_dev(returns, 20), close), 2), 5)) - 0.5",
    "-1 * ts_corr(rank(ts_delta(log(volume), 2)), rank((close - open) / open), 6)",
    "-1 * ts_corr(rank(open), rank(volume), 10)",
    "-1 * ts_rank(rank(low), 9)",
    "rank(open - (ts_mean(vwap, 10))) * (-1 * abs(rank(close - vwap)))",
    "-1 * ts_corr(open, volume, 10)",
    "if_else(ts_mean(volume, 20) < volume, -1 * ts_rank(abs(ts_delta(close, 7)), 60) * sign(ts_delta(close, 7)), -1)",
    "-1 * rank((ts_sum(open, 5) * ts_sum(returns, 5)) - ts_delay((ts_sum(open, 5) * ts_sum(returns, 5)), 10))",
    "if_else(0 < ts_min(ts_delta(close, 1), 5), ts_delta(close, 1), if_else(ts_max(ts_delta(close, 1), 5) < 0, ts_delta(close, 1), -1 * ts_delta(close, 1)))",
    "rank(if_else(0 < ts_min(ts_delta(close, 1), 4), ts_delta(close, 1), if_else(ts_max(ts_delta(close, 1), 4) < 0, ts_delta(close, 1), -1 * ts_delta(close, 1))))",
    "(rank(ts_max(vwap - close, 3)) + rank(ts_min(vwap - close, 3))) * rank(ts_delta(volume, 3))",
    "sign(ts_delta(volume, 1)) * (-1 * ts_delta(close, 1))",
    "-1 * rank(ts_covariance(rank(close), rank(volume), 5))",
    "-1 * rank(ts_delta(returns, 3)) * ts_corr(open, volume, 10)",
    "-1 * ts_sum(rank(ts_corr(rank(high), rank(volume), 3)), 3)",
    "-1 * rank(ts_covariance(rank(high), rank(volume), 5))",
    "-1 * rank(ts_rank(close, 10)) * rank(ts_delta(ts_delta(close, 1), 1)) * rank(ts_rank(volume / ts_mean(volume, 20), 5))",
    "-1 * rank(ts_std_dev(abs(close - open), 5) + (close - open) + ts_corr(close, open, 10))",
    "-1 * sign(ts_delta(close, 7) + ts_delta(close, 7)) * (1 + rank(1 + ts_sum(returns, 250)))",
    "-1 * rank(open - ts_delay(high, 1)) * rank(open - ts_delay(close, 1)) * rank(open - ts_delay(low, 1))",

    # Next batch (21-40)
    "if_else((ts_mean(close, 8) / 8 + ts_std_dev(close, 8)) < (ts_mean(close, 2) / 2), -1, if_else((ts_mean(close, 2) / 2) < ((ts_mean(close, 8) / 8) - ts_std_dev(close, 8)), 1, if_else(1 < (volume / ts_mean(volume, 20)), 1, -1)))",
    "-1 * (ts_delta(ts_corr(high, volume, 5), 5) * rank(ts_std_dev(close, 20)))",
    "if_else((ts_mean(high, 20) / 20) < high, -1 * ts_delta(high, 2), 0)",
    "if_else((ts_delta(ts_mean(close, 100) / 100, 100) / ts_delay(close, 100)) < 0.05, -1 * (close - ts_min(close, 100)), -1 * ts_delta(close, 3))",
    "rank(((-1 * returns) * ts_mean(volume, 20) * vwap * (high - close)))",
    "-1 * ts_max(ts_corr(ts_rank(volume, 5), ts_rank(high, 5), 5), 3)",
    "if_else(0.5 < rank((ts_sum(ts_corr(rank(volume), rank(vwap), 6), 2) / 2.0)), -1, 1)",
    "scale(((ts_corr(ts_mean(volume, 20), low, 5) + ((high + low) / 2)) - close))",
    "(min(product(rank(rank(scale(log(ts_sum(ts_min(rank(rank(-1 * rank(ts_delta(close - 1, 5)))), 2), 1)))), 1), 5) + ts_rank(ts_delay(-1 * returns, 6), 5))",
    "(1.0 - rank(((sign(close - ts_delay(close, 1)) + sign(ts_delay(close, 1) - ts_delay(close, 2))) + sign(ts_delay(close, 2) - ts_delay(close, 3))))) * ts_sum(volume, 5) / ts_sum(volume, 20)",
    "(rank(rank(rank(ts_decay_linear(-1 * rank(rank(ts_delta(close, 10))), 10)))) + rank(-1 * ts_delta(close, 3))) + sign(scale(ts_corr(ts_mean(volume, 20), low, 12)))",
    "scale((ts_mean(close, 7) / 7 - close)) + (20 * scale(ts_corr(vwap, ts_delay(close, 5), 230)))",
    "rank(-1 * (1 - (open / close)))",
    "rank((1 - rank(ts_std_dev(returns, 2) / ts_std_dev(returns, 5))) + (1 - rank(ts_delta(close, 1))))",
    "(ts_rank(volume, 32) * (1 - ts_rank((close + high - low), 16))) * (1 - ts_rank(returns, 32))",
    "(((2.21 * rank(ts_corr((close - open), ts_delay(volume, 1), 15))) + (0.7 * rank((open- close)))) + (0.73 * rank(ts_rank(ts_delay(-1 * returns, 6), 5)))) + rank(abs(ts_corr(vwap, ts_mean(volume, 20), 6))) + (0.6 * rank((ts_mean(close, 200) / 200 - open) * (close - open)))",
    "rank(ts_corr(ts_delay(open - close, 1), close, 200)) + rank(open - close)",
    "-1 * rank(ts_rank(close, 10)) * rank(close / open)",
    "-1 * rank(ts_delta(close, 7) * (1 - rank(ts_decay_linear(volume / ts_mean(volume, 20), 9))))) * (1 + rank(ts_sum(returns, 250)))",
    "-1 * rank(ts_std_dev(high, 10)) * ts_corr(high, volume, 10)",

    # Next batch (41-60)
    "power((high * low), 0.5) - vwap",
    "rank((vwap - close)) / rank((vwap + close))",
    "ts_rank((volume / ts_mean(volume, 20)), 20) * ts_rank((-1 * ts_delta(close, 7)), 8)",
    "-1 * ts_corr(high, rank(volume), 5)",
    "-1 * ((rank(ts_mean(ts_delay(close, 5), 20) / 20) * ts_corr(close, volume, 2)) * rank(ts_corr(ts_sum(close, 5), ts_sum(close, 20), 2)))",
    "if_else(0.25 < (ts_delta(ts_delay(close, 20), 10) / 10 - ts_delta(ts_delay(close, 10), 10) / 10), -1, if_else((ts_delta(ts_delay(close, 20), 10) / 10 - ts_delta(ts_delay(close, 10), 10) / 10) < 0, 1, -1 * ts_delta(close, 1)))",
    "((rank(1 / close) * volume / ts_mean(volume, 20)) * ((high * rank(high - close)) / (ts_mean(high, 5) / 5))) - rank(ts_delta(vwap, 5))",
    "(ts_corr(ts_delta(close, 1), ts_delta(ts_delay(close, 1), 1), 250) * ts_delta(close, 1)) / close",
    "if_else((ts_delta(ts_delay(close, 20), 10) / 10 - ts_delta(ts_delay(close, 10), 10) / 10) < -0.1, 1, -1 * ts_delta(close, 1))",
    "-1 * ts_max(rank(ts_corr(rank(volume), rank(vwap), 5)), 5)",

    # Batch (61-80)
    "if_else((ts_delta(ts_delay(close, 20), 10) / 10 - ts_delta(ts_delay(close, 10), 10) / 10) < -0.05, 1, -1 * ts_delta(close, 1))",
    "-1 * ((ts_min(low, 5) - ts_delay(ts_min(low, 5), 5)) * rank((ts_sum(returns, 240) - ts_sum(returns, 20)) / 220)) * ts_rank(volume, 5)",
    "-1 * ts_delta((((close - low) - (high - close)) / (close - low)), 9)",
    "-1 * ((low - close) * power(open, 5)) / ((low - high) * power(close, 5))",
    "-1 * ts_corr(rank((close - ts_min(low, 12)) / (ts_max(high, 12) - ts_min(low, 12))), rank(volume), 6)",
    "-1 * (rank((ts_sum(returns, 10) / ts_sum(ts_sum(returns, 2), 3))) * rank(returns))",
    "-1 * ((close - vwap) / ts_decay_linear(rank(ts_arg_max(close, 30)), 2))",
    "-1 * ts_rank(ts_decay_linear(ts_corr(vwap, volume, 4), 8), 6)",
    "-1 * ts_rank(ts_decay_linear(ts_corr(((vwap * 0.728317) + (vwap * (1 - 0.728317))), volume, 4), 16), 8)",
    "-1 * (2 * scale(rank(((close - low) - (high - close)) / (high - low) * volume)) - scale(rank(ts_arg_max(close, 10))))",
    "if_else(rank(vwap - ts_min(vwap, 16)) < rank(ts_corr(vwap, ts_mean(volume, 180), 18)), 1, -1)",
    "if_else(rank(ts_corr(vwap, ts_sum(ts_mean(volume, 20), 22), 10)) < rank(((rank(open) + rank(open)) < (rank((high + low) / 2) + rank(high)))), 1, -1)",
    "-1 * (rank(ts_decay_linear(ts_delta(close, 2), 8)) - rank(ts_decay_linear(ts_corr(((vwap * 0.318108) + (open * (1 - 0.318108))), ts_sum(ts_mean(volume, 180), 37), 14), 12)))",
    "-1 * if_else(rank(ts_corr(ts_sum(((open * 0.178404) + (low * (1 - 0.178404))), 13), ts_sum(ts_mean(volume, 120), 13), 17)) < rank(ts_delta(((high + low) / 2 * 0.178404) + (vwap * (1 - 0.178404)), 4)), 1, -1)",
    "-1 * if_else(rank(ts_corr(((open * 0.00817205) + (vwap * (1 - 0.00817205))), ts_sum(ts_mean(volume, 60), 9), 6)) < rank(open - ts_min(open, 14)), 1, -1)",
    "-1 * (rank(ts_decay_linear(ts_delta(vwap, 4), 7)) + ts_rank(ts_decay_linear(((low * 0.96633) + (low * (1 - 0.96633)) - vwap) / (open - (high + low) / 2), 11), 7))",
    "-1 * power(rank(high - ts_min(high, 2)), rank(ts_corr(vwap, ts_mean(volume, 120), 6)))",
    "-1 * if_else(ts_rank(ts_corr(rank(high), rank(ts_mean(volume, 15)), 9), 14) < rank(ts_delta((close * 0.518371) + (low * (1 - 0.518371)), 1)), 1, -1)",
    "-1 * power(rank(ts_max(ts_delta(vwap, 3), 5)), ts_rank(ts_corr(((close * 0.490655) + (vwap * (1 - 0.490655))), ts_mean(volume, 20), 5), 9))",
    "-1 * power(rank(ts_delta(vwap, 1)), ts_rank(ts_corr(close, ts_mean(volume, 50), 18), 18))",

    # Batch (81-101)
    "max(ts_rank(ts_decay_linear(ts_corr(ts_rank(close, 3), ts_rank(ts_mean(volume, 180), 12), 18), 4), ts_rank(ts_decay_linear(rank((low + open) - (vwap + vwap)), 16), 4))",
    "rank(ts_decay_linear(ts_corr((high + low) / 2, ts_mean(volume, 40), 9), 10)) / rank(ts_decay_linear(ts_corr(ts_rank(vwap, 4), ts_rank(volume, 19), 7), 3))",
    "max(rank(ts_decay_linear(ts_delta(vwap, 5), 3)), ts_rank(ts_decay_linear(((ts_delta(((open * 0.147155) + (low * (1 - 0.147155))), 2) / ((open * 0.147155) + (low * (1 - 0.147155)))) * -1), 3), 17)) * -1",
    "-1 * if_else(rank(ts_corr(close, ts_sum(ts_mean(volume, 30), 37), 15)) < rank(ts_corr(rank((high * 0.0261661) + (vwap * (1 - 0.0261661))), rank(volume), 11)), 1, -1)",
    "if_else(rank(ts_corr(vwap, volume, 4)) < rank(ts_corr(rank(low), rank(ts_mean(volume, 50)), 12)), 1, -1)",
    "-1 * max(rank(ts_decay_linear(ts_delta(vwap, 1), 12)), ts_rank(ts_decay_linear(ts_rank(ts_corr(low, ts_mean(volume, 81), 8), 20), 17), 19))",
    "min(rank(ts_decay_linear(((high + low) / 2 + high - (vwap + high)), 20)), rank(ts_decay_linear(ts_corr((high + low) / 2, ts_mean(volume, 40), 3), 6)))",
    "power(rank(ts_corr(ts_sum(((low * 0.352233) + (vwap * (1 - 0.352233))), 20), ts_sum(ts_mean(volume, 40), 20), 7)), rank(ts_corr(rank(vwap), rank(volume), 6)))",
    "if_else(rank(ts_delta(((close * 0.60733) + (open * (1 - 0.60733))), 1)) < rank(ts_corr(ts_rank(vwap, 4), ts_rank(ts_mean(volume, 150), 9), 15)), 1, -1)",
    "-1 * power(rank(sign(ts_delta(((open * 0.868128) + (high * (1 - 0.868128))), 4))), ts_rank(ts_corr(high, ts_mean(volume, 10), 5), 6))",
    "-1 * if_else(rank(log(product(rank(ts_corr(vwap, ts_sum(ts_mean(volume, 10), 50), 8)), 15))) < rank(ts_corr(rank(vwap), rank(volume), 5)), 1, -1)",
    "-1 * min(rank(ts_decay_linear(ts_delta(open, 1), 15)), ts_rank(ts_decay_linear(ts_corr(volume, ((open * 0.634196) + (open * (1 - 0.634196))), 17), 7), 13))",
    "((rank(ts_delay((high - low) / (ts_sum(close, 5) / 5), 2)) * rank(rank(volume))) / ((high - low) / (ts_sum(close, 5) / 5)) / (vwap - close))",
    "power(ts_rank((vwap - ts_max(vwap, 15)), 21), ts_delta(close, 5))",
    "power(rank(ts_corr(((high * 0.876703) + (close * (1 - 0.876703))), ts_mean(volume, 30), 10)), rank(ts_corr(ts_rank((high + low) / 2, 4), ts_rank(volume, 7), 7)))",
    "-1 * if_else(ts_rank(ts_corr(close, ts_sum(ts_mean(volume, 20), 15), 6), 20) < rank((open + close) - (vwap + open)), 1, -1)",
    "-1 * max(rank(ts_decay_linear(ts_delta(((close * 0.369701) + (vwap * (1 - 0.369701))), 2), 3)), ts_rank(ts_decay_linear(abs(ts_corr(ts_mean(volume, 81), close, 13)), 5), 14))",
    "min(rank(ts_decay_linear(((rank(open) + rank(low)) - (rank(high) + rank(close))), 8)), ts_rank(ts_decay_linear(ts_corr(ts_rank(close, 8), ts_rank(ts_mean(volume, 60), 21), 8), 7), 3))",
    "(ts_rank(ts_decay_linear(ts_corr(((low * 0.967285) + (low * (1 - 0.967285))), ts_mean(volume, 10), 7), 6), 4) - ts_rank(ts_decay_linear(ts_delta(vwap, 3), 10), 15))",
    "-1 * power(rank(close - ts_max(close, 5)), ts_rank(ts_corr(ts_mean(volume, 40), low, 5), 3))",
    "-1 * (ts_rank(ts_decay_linear(ts_decay_linear(ts_corr(close, volume, 10), 16), 4), 5) - rank(ts_decay_linear(ts_corr(vwap, ts_mean(volume, 30), 4), 3)))",
    "min(ts_rank(ts_decay_linear(((high + low) / 2 + close < (low + open)), 15), 19), ts_rank(ts_decay_linear(ts_corr(rank(low), rank(ts_mean(volume, 30)), 8), 7), 7))",
    "(ts_rank(ts_decay_linear(ts_corr(vwap, ts_mean(volume, 81), 17), 20), 8) / rank(ts_decay_linear(ts_delta(((close * 0.524434) + (vwap * (1 - 0.524434))), 3), 16)))",
    "-1 * power(rank(vwap - ts_min(vwap, 12)), ts_rank(ts_corr(ts_rank(vwap, 20), ts_rank(ts_mean(volume, 60), 4), 18), 3))",
    "if_else(rank(open - ts_min(open, 12)) < ts_rank(rank(ts_corr(ts_sum((high + low) / 2, 19), ts_sum(ts_mean(volume, 40), 19), 13)), 12), 1, -1)",
    "-1 * max(ts_rank(ts_decay_linear(ts_corr(rank(vwap), rank(volume), 4), 4), 8), ts_rank(ts_decay_linear(ts_arg_max(ts_corr(ts_rank(close, 7), ts_rank(ts_mean(volume, 60), 4), 13), 14), 13))",
    "-1 * (rank(ts_decay_linear(ts_delta(((low * 0.721001) + (vwap * (1 - 0.721001))), 3), 20)) - ts_rank(ts_decay_linear(ts_rank(ts_corr(ts_rank(low, 8), ts_rank(ts_mean(volume, 60), 17), 5), 19), 7))",
    "(rank(ts_decay_linear(ts_corr(vwap, ts_sum(ts_mean(volume, 5), 26), 5), 7)) - rank(ts_decay_linear(ts_rank(ts_arg_min(ts_corr(rank(open), rank(ts_mean(volume, 15)), 21), 9), 8)))",
    "-1 * if_else(rank(ts_corr(ts_sum((high + low) / 2, 20), ts_sum(ts_mean(volume, 60), 20), 9)) < rank(ts_corr(low, volume, 6)), 1, -1)",
    "-1 * (1.5 * scale(rank(((close - low) - (high - close)) / (high - low) * volume)) - scale(rank(ts_arg_min(close, 30))))",
    "divide(subtract(close, open), add(subtract(high, low), 0.001))"
]