Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def cokurt(df):
- # Number of stocks
- num = len(df.columns)
- #First Tensor Product Matrix
- mtx1 = np.zeros(shape = (len(df), num**2))
- #Second Tensor Product Matrix
- mtx2 = np.zeros(shape = (len(df), num**3))
- v = df.values
- means = v.mean(0,keepdims=True)
- v1 = (v-means).T
- for k in range(num):
- for i in range(num):
- for j in range(num):
- vals = v1[i]*v1[j]*v1[k]
- mtx2[:,(k*(num**2))+(i*num)+j] = vals/float((len(df)-1)*df.iloc[:,i].std()*\
- df.iloc[:,j].std()*df.iloc[:,k].std())
- m4 = np.dot(v1,mtx2)
- for i in range(num**3):
- use = i%num
- m4[:,i] = m4[:,i]/float(df.iloc[:,use].std())
- return m4
- m4 = cokurt(log_ret)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement