-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathld1a17.py
67 lines (42 loc) · 1.14 KB
/
ld1a17.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# coding: utf-8
# In[12]:
from math import log
from math import sqrt
import pandas as pd
import numpy as np
from pandas import Series,DataFrame
def VE(a):
a.OPENPRC = a.OPENPRC.fillna(a.PRC.shift())
#a.OPENPRC[a.index[0]] = 1
ve = (np.log(a.ASKHI)-np.log(abs(a.OPENPRC)))*(np.log(a.ASKHI)-np.log(abs(a.PRC)))+(np.log(a.BIDLO)-np.log(abs(a.OPENPRC)))*(np.log(a.BIDLO)-np.log(a.PRC))
return(ve)
def ssd_v(t1, t2):
# len of one cusip
l=len(t1)
ssd=0
for i in range(l):
ssd=ssd + (t1[i]-t2[i])**2
return (ssd)
# # In[16]:
# f3=ssd_v()
# print(f3)
# In[17]:
# function2 = ssd_v()##########################################
# In[18]:
# t1 = VE(df,'12556910')
# t2 = VE(df,'15648910')
# In[19]:
def smd_v(t1, t2):
npvector1, npvector2 = np.array(t1), np.array(t2)
npvector = np.array([npvector1, npvector2])
X = np.linalg.inv(np.cov(t1, t2))
ma=0
for i in range(len(npvector.T)):
Y = npvector.T[i]
ma = ma + sqrt(np.dot(X, Y).dot(Y.T))
return (ma)
# In[20]:
# f3=smd_v()
# print(f3)
# In[21]:
# function3 = smd_v()###########################################