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
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
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
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
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
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
''' 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)
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 '''