Exemplo n.º 1
0
def genRollAutocorr():
    output = {}
    for ind in standardIndices+HFIndices_raw:
        ROR, indNew = getIndData(ind, 'ROR')
        Date, indNew = getIndData(ind, 'Date')
        end = len(ROR)
        rollingac = []
        upbound = []
        lowbound = []
        for i in range(36, end):
            sampleY = ROR[i-36:i]
            #sampleX = Date[i]
            r, se = autocorr(sampleY, 1)
            rollingac.append(r[-1])
            upbound.append(r+1.96*se)
            lowbound.append(r-1.96*se)
        rAC = np.array(rollingac)
        uB = np.array(upbound)
        lB = np.array(lowbound)
        tAxis = Date[36:]
        print len(tAxis), len(rAC)
        #fig, ax = plt.subplots()
        #ax.plot_date(tAxis, rAC, linestyle='--')
        #ax.set_title('%s'%(indNew))
        #ax.annotate('Test', (mdates.date2num(tAxis[1]), rAC[1]), xytext=(15, 15), textcoords='offset points', arrowprops=dict(arrowstyle='-|>'))
        
        #fig.autofmt_xdate()
        #plt.show()
        output[indNew] = [rAC, uB, lB]
Exemplo n.º 2
0
def genRollAutocorr():
    output = {}
    for ind in standardIndices + HFIndices_raw:
        ROR, indNew = getIndData(ind, 'ROR')
        Date, indNew = getIndData(ind, 'Date')
        end = len(ROR)
        rollingac = []
        upbound = []
        lowbound = []
        for i in range(36, end):
            sampleY = ROR[i - 36:i]
            #sampleX = Date[i]
            r, se = autocorr(sampleY, 1)
            rollingac.append(r[-1])
            upbound.append(r + 1.96 * se)
            lowbound.append(r - 1.96 * se)
        rAC = np.array(rollingac)
        uB = np.array(upbound)
        lB = np.array(lowbound)
        tAxis = Date[36:]
        print len(tAxis), len(rAC)
        #fig, ax = plt.subplots()
        #ax.plot_date(tAxis, rAC, linestyle='--')
        #ax.set_title('%s'%(indNew))
        #ax.annotate('Test', (mdates.date2num(tAxis[1]), rAC[1]), xytext=(15, 15), textcoords='offset points', arrowprops=dict(arrowstyle='-|>'))

        #fig.autofmt_xdate()
        #plt.show()
        output[indNew] = [rAC, uB, lB]
Exemplo n.º 3
0
def AggregateIlliquidity(endDate, n=25):
    nameArray, dataArray = getNames(endDate, inst=['hedgefunds'], numComps=n)
    k = 1  #lag steps we want to analyze
    sumAUM = 0.0
    for name in nameArray:
        sumAUM += float(name[1])
    rho_prime = 0.0
    for ind, data in enumerate(dataArray):
        r_arr, se = autocorr(data, k, SE=True)
        rho = r_arr[-1]
        weight = float(nameArray[ind][1]) / sumAUM
        rho_prime += weight * rho
    return rho_prime
Exemplo n.º 4
0
def AggregateIlliquidity(endDate, n=25):
    nameArray, dataArray = getNames(endDate, inst=['hedgefunds'], numComps = n)
    k = 1 #lag steps we want to analyze
    sumAUM = 0.0
    for name in nameArray:
        sumAUM += float(name[1])
    rho_prime = 0.0
    for ind, data in enumerate(dataArray):
        r_arr, se = autocorr(data, k, SE=True)
        rho = r_arr[-1]
        weight = float(nameArray[ind][1])/sumAUM
        rho_prime += weight*rho
    return rho_prime
Exemplo n.º 5
0
def Qstatistic(endDate, n=25):
    Qarray = []
    nameArray, dataArray = getNames(endDate, inst=['hedgefunds'], numComps=n)
    k = 6  #lag steps we want to analyze
    for data in dataArray:
        r_arr, se = autocorr(data, k, SE=True)
        T = len(data)
        sum1 = 0.0
        for i in range(1, k + 1):
            #print r_arr
            sum1 += r_arr[i]**2 / (T - i)
        sum1 = sum1 * T * (T + 2)
        Qarray.append(sum1)
    print Qarray
    return nameArray, Qarray
Exemplo n.º 6
0
def Qstatistic(endDate, n=25):
    Qarray = []
    nameArray, dataArray = getNames(endDate, inst=['hedgefunds'], numComps = n)
    k = 6 #lag steps we want to analyze
    for data in dataArray:
        r_arr, se = autocorr(data, k, SE=True)
        T = len(data)
        sum1 =  0.0
        for i in range(1, k+1):
            #print r_arr
            sum1+= r_arr[i]**2/(T-i)
        sum1 = sum1*T*(T+2)
        Qarray.append(sum1)
    print Qarray
    return nameArray, Qarray
Exemplo n.º 7
0
    for ind in standardIndices+HFIndices_raw:
        ROR, indNew = getIndData(ind, 'ROR', aDate, bDate)
        rorDataDict[indNew] = ROR
    
    outputDict = {}
    
    for ind in rorDataDict.keys():
        print ind
        #print rorDataDict[ind]
        ror = rorDataDict[ind]
        stats1 =  stats.describe(ror)
        #stats1 is the output defined in scipy.stats.describe.html
        rho_arr = []
        pval_arr = []
        for i in range(1, 4):
            r, p = autocorr(ror, i)
            rho_arr.append(r)
            pval_arr.append(p)
        output = [stats1[0], stats1[2]*12,np.sqrt(12*stats1[3]), stats1[1][0], stats1[1][1], 
                  np.median(ror), stats1[4], stats1[5],
                  rho_arr[0], pval_arr[0],
                  rho_arr[1], pval_arr[1],
                  rho_arr[2], pval_arr[2]]
        outputDict[ind] = output
        print output
    
    Dateoutput = open('SummaryStatistic.pkl', 'wb')
    pickle.dump(outputDict, Dateoutput)
    return outputDict

if __name__ == '__main__':
Exemplo n.º 8
0
    for ind in standardIndices + HFIndices_raw:
        ROR, indNew = getIndData(ind, 'ROR', aDate, bDate)
        rorDataDict[indNew] = ROR

    outputDict = {}

    for ind in rorDataDict.keys():
        print ind
        #print rorDataDict[ind]
        ror = rorDataDict[ind]
        stats1 = stats.describe(ror)
        #stats1 is the output defined in scipy.stats.describe.html
        rho_arr = []
        pval_arr = []
        for i in range(1, 4):
            r, p = autocorr(ror, i)
            rho_arr.append(r)
            pval_arr.append(p)
        output = [
            stats1[0], stats1[2] * 12,
            np.sqrt(12 * stats1[3]), stats1[1][0], stats1[1][1],
            np.median(ror), stats1[4], stats1[5], rho_arr[0], pval_arr[0],
            rho_arr[1], pval_arr[1], rho_arr[2], pval_arr[2]
        ]
        outputDict[ind] = output
        print output

    Dateoutput = open('SummaryStatistic.pkl', 'wb')
    pickle.dump(outputDict, Dateoutput)
    return outputDict