Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. def cokurt(df):
  2. # Number of stocks
  3. num = len(df.columns)
  4.  
  5. #First Tensor Product Matrix
  6. mtx1 = np.zeros(shape = (len(df), num**2))
  7.  
  8. #Second Tensor Product Matrix
  9. mtx2 = np.zeros(shape = (len(df), num**3))
  10.  
  11. v = df.values
  12. means = v.mean(0,keepdims=True)
  13. v1 = (v-means).T
  14.  
  15. for k in range(num):
  16. for i in range(num):
  17. for j in range(num):
  18. vals = v1[i]*v1[j]*v1[k]
  19. mtx2[:,(k*(num**2))+(i*num)+j] = vals/float((len(df)-1)*df.iloc[:,i].std()*\
  20. df.iloc[:,j].std()*df.iloc[:,k].std())
  21.  
  22. m4 = np.dot(v1,mtx2)
  23. for i in range(num**3):
  24. use = i%num
  25. m4[:,i] = m4[:,i]/float(df.iloc[:,use].std())
  26.  
  27. return m4
  28.  
  29. m4 = cokurt(log_ret)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement