-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathDataReaderFromWind.py
52 lines (34 loc) · 1.2 KB
/
DataReaderFromWind.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
# coding: utf-8
# In[6]:
from WindPy import w
from datetime import date
w.start()
# In[ ]:
import pandas as pd
import numpy as np
from datetime import date
import math
def py_wsi(tickers,fields,startDt,endDt, name="", options=""):
# If tickers is an array, only the first field will be returned.
#print type(tickers)
if type(tickers) <> type([]):
temp = w.wsi(tickers,fields,startDt,endDt,options)
dataMat = np.array(temp.Data).T
result = pd.DataFrame(dataMat,index=temp.Times,columns=temp.Fields)
return result
if type(tickers) == type([]):
temp = w.wsi(tickers,fields,startDt,endDt,options)
dataMat = np.array(temp.Data).T
result = pd.DataFrame(dataMat,index=temp.Times,columns=temp.Codes)
return result
def my_wsi(tickers,fields,startDt,endDt):
data_all = py_wsi(tickers,fields,startDt,endDt)
data_all['time'] = data_all.index
data_all.index = np.arange(len(data_all))
del_index = []
for i in data_all.index:
if math.isnan(data_all.iloc[i,0]):
del_index.append(i)
data_all = data_all.drop(del_index)
data_all.index = np.arange(len(data_all))
return data_all