This repository has been 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
/
SHFE.py
66 lines (64 loc) · 1.7 KB
/
SHFE.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
import pandas as pd
from Time import time_column
"""
in `shves`
{
"_id" : ObjectId("5b3ec535b651391089db5075"),
"PRODUCTID" : "cu_f",
"PRODUCTSORTNO" : 10,
"PRODUCTNAME" : "铜",
"DELIVERYMONTH" : "1807",
"PRESETTLEMENTPRICE" : 51320,
"OPENPRICE" : 51500,
"HIGHESTPRICE" : 51500,
"LOWESTPRICE" : 50830,
"CLOSEPRICE" : 51090,
"SETTLEMENTPRICE" : 51190,
"ZD1_CHG" : -230,
"ZD2_CHG" : -130,
"VOLUME" : 34764,
"OPENINTEREST" : 81580,
"OPENINTERESTCHG" : -5294,
"ORDERNO" : 0,
"DATE" : "20180702",
"__v" : 0
}
"""
def generalize(queries):
"""
Returns:
'InstrumentName','InstrumentMonth','OpenPrice','HighestPrice','LowestPrice','ClosePrice','SettlementPrice','ZD1','ZD2','Volume','OpenInterest','Delta','TradingDay'
"""
data = pd.DataFrame([(
doc['PRODUCTNAME'],
doc['DELIVERYMONTH'],
doc['OPENPRICE'],
doc['HIGHESTPRICE'],
doc['LOWESTPRICE'],
doc['CLOSEPRICE'],
doc['SETTLEMENTPRICE'],
doc['ZD1_CHG'],
doc['ZD2_CHG'],
doc['VOLUME'],
doc['OPENINTEREST'],
doc['OPENINTERESTCHG'],
doc['DATE']
) for doc in queries], columns= [
'InstrumentName',
'InstrumentMonth',
'OpenPrice',
'HighestPrice',
'LowestPrice',
'ClosePrice',
'SettlementPrice',
'ZD1',
'ZD2',
'Volume',
'OpenInterest',
'Delta',
'TradingDay'
])
data['Instrument'] = data['InstrumentName'] + data['InstrumentMonth']
data['TradingDay'] = pd.Series(list(time_column(data['TradingDay'])))
data.set_index('Instrument', inplace=True)
return data