Ejemplo n.º 1
0
def ppwfilter(funddf, indexdf, rf, ratio):


    length = len(funddf.index)

    '''
    tran_index = []
    for i in range(0, length):
        if i % 4 == 0:
            tran_index.append(i)

    funddf = funddf.iloc[tran_index]
    funddfr = funddf.pct_change()

    indexdf = indexdf.iloc[tran_index]
    indexdfr = indexdf.pct_change()
    '''


    funddfr = funddf.pct_change().fillna(0.0)
    indexdfr = indexdf.pct_change().fillna(0.0)

    ppw = {}
    cols = funddfr.columns
    for col in cols:
        p = []
        m = []
        rs = funddfr[col].values
        indexrs = indexdfr.values
        for i in range(0, len(rs)):
            if isnan(rs[i]):
                continue
            else:
                p.append(rs[i] - rf)
                m.append(indexrs[i] - rf)


        ppw[col] = fin.ppw(p, m)


    x = ppw
    sorted_x = sorted(x.iteritems(), key=lambda x : x[1], reverse=True)
    sorted_ppw = sorted_x


    result = []
    for i in range(0, (int)(len(sorted_ppw) * ratio)):
        result.append(sorted_ppw[i])

    #print result
    return result
Ejemplo n.º 2
0
def ppwmeasure(funddf, indexdf, rf):


    length = len(funddf.index)

    '''
    tran_index = []
    for i in range(0, length):
        if i % 4 == 0:
            tran_index.append(i)

    funddf = funddf.iloc[tran_index]
    funddfr = funddf.pct_change()

    indexdf = indexdf.iloc[tran_index]
    indexdfr = indexdf.pct_change()
    '''

    funddfr = funddf.pct_change().fillna(0.0)
    indexdfr = indexdf.pct_change().fillna(0.0)


    ppw = {}
    cols = funddfr.columns
    for col in cols:
        p = []
        m = []
        rs = funddfr[col].values
        indexrs = indexdfr.values
        for i in range(0, len(rs)):
            if isnan(rs[i]):
                continue
            else:
                p.append(rs[i] - rf)
                m.append(indexrs[i] - rf)
        #print p
        #print m

        ppw[col] = fin.ppw(p, m)

    return ppw