Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
def alpha45(df):
    """
    Alpha#45
    (-1 * ((rank((sum(delay(close, 5), 20) / 20)) * correlation(close, volume, 2)) 
    * rank(correlation(sum(close, 5), sum(close, 20), 2)))) 
    """
    temp1 = u.rank((u.ts_sum(u.delay(df.close, 5), 20) / 20))
    temp2 = u.corr(df.close, df.volume, 2)
    temp3 = u.rank(u.corr(u.ts_sum(df.close, 5), u.ts_sum(df.close, 20), 2))
    return (-1 * ((temp1 * temp2) * temp3))
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
def orth_matrix(n=10):
    Y = utils.rand(n, 1)
    X = utils.zeros(n, n)
    if n > 2:
        for j in xrange(n - 1):
            x = utils.rand(n, 1)
            while abs(abs(utils.corr(x, Y)) - j / (n - 1.0)) > 0.005:
                x = utils.rand(n, 1)
            if utils.corr(x, Y) < 0:
                x *= -1
            X[:, j] = x.ravel()

    X[:, n - 1] = Y.ravel()

    return X, Y
Ejemplo n.º 12
0
def orth_matrix(n=10):
    Y = utils.rand(n, 1)
    X = utils.zeros(n, n)
    if n > 2:
        for j in xrange(n - 1):
            x = utils.rand(n, 1)
            while abs(abs(utils.corr(x, Y)) - j / (n - 1.0)) > 0.005:
                x = utils.rand(n, 1)
            if utils.corr(x, Y) < 0:
                x *= -1
            X[:, j] = x.ravel()

    X[:, n - 1] = Y.ravel()

    return X, Y
Ejemplo n.º 13
0
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)
Ejemplo n.º 14
0
def alpha40(df):
    """
    Alpha#40
    ((-1 * rank(stddev(high, 10))) * correlation(high, volume, 10))
    """
    return ((-1 * u.rank(u.stddev(df.high, 10))) *
            u.corr(df.high, df.volume, 10))
Ejemplo n.º 15
0
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))
Ejemplo n.º 16
0
def alpha50(df):
    """
    Alpha#50
    (-1 * ts_max(rank(correlation(rank(volume), rank(vwap), 5)), 5))
    """
    return (-1 *
            u.ts_max(u.rank(u.corr(u.rank(df.volume), u.rank(df.vwap), 5)), 5))
Ejemplo n.º 17
0
def alpha14(df):
    """
    Alpha#14
    ((-1 * rank(delta(returns, 3))) * correlation(open, volume, 10)) 
    """
    return ((-1 * u.rank(u.delta(df.returns, 3))) *
            u.corr(df.open, df.volume, 10))
Ejemplo n.º 18
0
def alpha22(df):
    """
    Alpha#22
    (-1 * (delta(correlation(high, volume, 5), 5) * rank(stddev(close, 20))))
    """
    return (-1 * (u.delta(u.corr(df.high, df.volume, 5), 5) *
                  u.rank(u.stddev(df.close, 20))))
Ejemplo n.º 19
0
def alpha2(df):
    """
    Alpha#2
    (-1 * correlation(rank(delta(log(volume), 2)), rank(((close - open) / open)), 6))
    """
    tmp_1 = u.rank(u.delta(np.log(df.volume), 2))
    tmp_2 = u.rank(((df.close - df.open) / df.open))
    return (-1 * u.corr(tmp_1, tmp_2, 6))
Ejemplo n.º 20
0
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))
Ejemplo n.º 21
0
def alpha37(df):
    """
    Alpha#37
    (rank(correlation(delay((open - close), 1), close, 200)) + rank((open - close))) 
    """
    return (u.rank(u.corr(u.delay(
        (df.open - df.close), 1), df.close, 200)) + u.rank(
            (df.open - df.close)))
Ejemplo n.º 22
0
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)
Ejemplo n.º 23
0
def alpha27(df):
    """
    Alpha#27
    ((0.5 < rank((sum(correlation(rank(volume), rank(vwap), 6), 2) / 2.0))) ? (-1 * 1) : 1) 
    """
    temp = np.where((0.5 < u.rank(
        (u.ts_sum(u.corr(u.rank(df.volume), u.rank(df.vwap), 6), 2) / 2.0))),
                    (-1 * 1), 1)
    return pd.Series(temp, index=df.index)
Ejemplo n.º 24
0
def alpha32(df):
    """
    Alpha#32
    (scale(((sum(close, 7) / 7) - close)) + 
    (20 * scale(correlation(vwap, delay(close, 5), 230)))) 
    """
    temp1 = u.scale(((u.ts_sum(df.close, 7) / 7) - df.close))
    temp2 = (20 * u.scale(u.corr(df.vwap, u.delay(df.close, 5), 230)))
    return temp1 + temp2
Ejemplo n.º 25
0
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)))
Ejemplo n.º 26
0
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))
Ejemplo n.º 27
0
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)
Ejemplo n.º 28
0
def alpha18(df):
    """
    Alpha#18
    (-1 * rank(((stddev(abs((close - open)), 5) + (close - open)) + 
    correlation(close, open, 10))))
    """
    temp1 = u.stddev(abs((df.close - df.open)), 5)
    temp2 = df.close - df.open
    temp3 = u.corr(df.close, df.open, 10)
    return (-1 * u.rank(temp1 + temp2 + temp3))
Ejemplo n.º 29
0
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)
Ejemplo n.º 30
0
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))
Ejemplo n.º 31
0
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)
Ejemplo n.º 32
0
def orth_matrix(n=10):
    Y = utils.rand(n, 1)
    X = utils.zeros(n, n)
    if n > 2:
        for j in xrange(n - 1):
            x = utils.rand(n, 1)
            while abs(abs(utils.corr(x, Y)) - j / (n - 1.0)) > 0.005:
                x = utils.rand(n, 1)
            if utils.corr(x, Y) < 0:
                x *= -1
            X[:, j] = x.ravel()

    X[:, n - 1] = Y.ravel()

    return X, Y


#def check_ortho(M, err_msg):
#    K = np.dot(M.T, M)
#    assert_array_almost_equal(K, np.diag(np.diag(K)), err_msg=err_msg)