This repository was archived by the owner on Feb 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCZCE.py
60 lines (58 loc) · 1.43 KB
/
CZCE.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
import pandas as pd
from Time import time_column
"""
in `czces`
{
"_id" : ObjectId("5b3e08d7ac41716715d0607a"),
"instrumentid" : "AP807",
"lstcloseprice" : 8946,
"openprice" : 8706,
"highestprice" : 8888,
"lowestprice" : 8706,
"closeprice" : 8888,
"zd1" : 8827,
"zd2" : -58,
"volume" : -119,
"openinterest" : 6,
"delta" : 184,
"turnover" : -4,
"settlementprice" : 52.96,
"date" : "180705",
"__v" : 0
}
"""
def generalize(queries):
"""
Returns:
'Instrument','TradingDay''OpenPrice','HighestPrice','LowestPrice','ClosePrice','PreSettlementPrice','SettlementPrice','Volume','OpenInterest','TurnOver','ExpireDate'
"""
data = pd.DataFrame([(
doc['instrumentid'],
doc['date'],
doc['openprice'],
doc['highestprice'],
doc['lowestprice'],
doc['closeprice'],
doc['zd1'],
doc['zd2'],
doc['volume'],
doc['openinterest'],
doc['delta'],
doc['turnover']
) for doc in queries], columns= [
'Instrument',
'TradingDay',
'OpenPrice',
'HighestPrice',
'LowestPrice',
'ClosePrice',
'ZD1',
'ZD2',
'Volume',
'OpenInterest',
'Delta',
'TurnOver'
])
data['TradingDay'] = pd.Series(list(time_column(data['TradingDay'], True)))
data.set_index('Instrument', inplace=True)
return data