forked from drlgistics/Wt4ElegantRL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataset_from_storage.py
110 lines (99 loc) · 3.04 KB
/
dataset_from_storage.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import pandas as pd
from ctypes import POINTER
from os import makedirs
from wtpy.wrapper.WtDtHelper import WtDataHelper
from wtpy.WtCoreDefs import WTSBarStruct
from wtpy import WtDtServo
class DataReader:
df: pd.DataFrame
def __len__(self) -> int:
return len(self.df)
def set_bars(self, data: pd.DataFrame) -> tuple:
dtype = {
'date': int,
'time': int,
'open': float,
'high': float,
'low': float,
'close': float,
'money': float,
'vol': int,
'hold': int,
'diff': int,
}
self.df = data[dtype.keys()].astype(dtype)
def get_bars(self, curBar: POINTER(WTSBarStruct), idx: int) -> bool:
curBar.contents.date = self.df['date'].iloc[idx]
curBar.contents.time = self.df['time'].iloc[idx]
curBar.contents.open = self.df['open'].iloc[idx]
curBar.contents.high = self.df['high'].iloc[idx]
curBar.contents.low = self.df['low'].iloc[idx]
curBar.contents.close = self.df['close'].iloc[idx]
curBar.contents.money = self.df['money'].iloc[idx]
curBar.contents.vol = self.df['vol'].iloc[idx]
curBar.contents.hold = self.df['hold'].iloc[idx]
curBar.contents.diff = self.df['diff'].iloc[idx]
return True
reader: DataReader = DataReader()
helper: WtDataHelper = WtDataHelper()
dt: WtDtServo = WtDtServo()
dt.setBasefiles(
commfile='./config/01commom/commodities.json',
contractfile='./config/01commom/contracts.json',
holidayfile='./config/01commom/holidays.json',
sessionfile='./config/01commom/sessions.json',
hotfile='./config/01commom/hots.json'
)
dt.setStorage('D:/Github/test/Storage/')
dt.commitConfig()
securities: tuple = (
'CFFEX.IC.HOT',
'CFFEX.IF.HOT',
'CFFEX.IH.HOT',
'CFFEX.T.HOT',
'CFFEX.TF.HOT',
'CZCE.RM.HOT',#
'CZCE.JR.HOT',#
'CZCE.AP.HOT',
'CZCE.CF.HOT',
'CZCE.MA.HOT',
'CZCE.SF.HOT',
'CZCE.SR.HOT',
'CZCE.TA.HOT',#
'CZCE.ZC.HOT',
'DCE.a.HOT',
'DCE.c.HOT',#
'DCE.cs.HOT',#
'DCE.i.HOT',
'DCE.jd.HOT',
'DCE.l.HOT',
'DCE.m.HOT',#
'DCE.p.HOT',
'DCE.pp.HOT',
'DCE.y.HOT',
'DCE.rr.HOT',#
'INE.sc.HOT',
'INE.lu.HOT',
'SHFE.ag.HOT',
'SHFE.al.HOT',
'SHFE.bu.HOT',
'SHFE.cu.HOT',
'SHFE.fu.HOT',
'SHFE.hc.HOT',
'SHFE.ni.HOT',
'SHFE.pb.HOT',
'SHFE.rb.HOT',
'SHFE.zn.HOT',
)
for period, name in {'d1': 'day', 'm5': 'min5', }.items():#, 'm1': 'min1'
for code in securities:
print(period, code)
path = './dataset/his/%s/%s' % (name, code.split('.')[0])
makedirs(path, exist_ok=True)
df = dt.get_bars(code, period=period, fromTime=201601011600,
endTime=202110131600).to_pandas()
reader.set_bars(df)
helper.trans_bars(barFile='%s/%s.dsb' % (path, code.replace('.HOT', '_HOT')), getter=reader.get_bars,
count=len(reader), period='d' if period == 'd1' else period)
# break
# break