Ejemplo n.º 1
0
def getGCPvalues(aDate):
    
    tick = time()
    npNArray, npDArray = getNames(aDate)
    p_values = grangerCausality(npDArray)
    tock = time()
    print 'getting p-values takes %f' %(tock-tick)
    return npNArray, p_values
Ejemplo n.º 2
0
def getGCPvalues(aDate):

    tick = time()
    npNArray, npDArray = getNames(aDate)
    p_values = grangerCausality(npDArray)
    tock = time()
    print 'getting p-values takes %f' % (tock - tick)
    return npNArray, p_values
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo n.º 7
0
'''
def PCA(index_names=[], window = 36, index=False, startDate = dt.date(1994, 01, 01), endDate = dt.date(2013, 01, 01)):
    if index:
        for i, ind in enumerate(index_names):
            ROR, newInd = getIndData(ind, 'ROR', startDate, endDate)
            #print newInd
            listtmp = np.ndarray.tolist(ROR)
            #print len(listtmp)
            if i==0:
                RORs = np.array([listtmp])
            else:
                RORs = np.append(RORs, [listtmp], axis= 0)
        #print RORs
        covMat = np.cov(RORs)
    else:
        npNarr, npDarr = getNames(endDate, window=window)
        covMat = np.cov(npDarr)
        
    eigVal, eigVec = np.linalg.eig(covMat)
    return eigVal, eigVec
'''
given eigenvalues, return the cumulative risk fraction
===Input===
eigVal:  The eigenvalues
===Output===
returns the CRF for the given eigVal
'''
def CumulRiskFrac(eigVal):
    sort1 = sorted(eigVal, reverse=True)
    return sort1[0]/sum(sort1)
Ejemplo n.º 8
0
        startDate=dt.date(1994, 01, 01),
        endDate=dt.date(2013, 01, 01)):
    if index:
        for i, ind in enumerate(index_names):
            ROR, newInd = getIndData(ind, 'ROR', startDate, endDate)
            #print newInd
            listtmp = np.ndarray.tolist(ROR)
            #print len(listtmp)
            if i == 0:
                RORs = np.array([listtmp])
            else:
                RORs = np.append(RORs, [listtmp], axis=0)
        #print RORs
        covMat = np.cov(RORs)
    else:
        npNarr, npDarr = getNames(endDate, window=window)
        covMat = np.cov(npDarr)

    eigVal, eigVec = np.linalg.eig(covMat)
    return eigVal, eigVec


'''
given eigenvalues, return the cumulative risk fraction
===Input===
eigVal:  The eigenvalues
===Output===
returns the CRF for the given eigVal
'''