-
Notifications
You must be signed in to change notification settings - Fork 1
/
testdata.py
273 lines (206 loc) · 10.1 KB
/
testdata.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#v1.0
#v0.9 - All research graph via menu & mouse click
#v0.8 - Candlestick graphs
#v0.7 - Base version with all graphs and bug fixes
#v0.6
import pandas as pd
from pandas import DataFrame
from alpha_vantage.timeseries import TimeSeries
from alpha_vantage.techindicators import TechIndicators
class PrepareTestData():
def __init__(self, argFolder=None, argOutputSize='compact'):
super().__init__()
#argFolder='./scriptdata'
self.folder = argFolder + '/'
self.outputsize = argOutputSize.lower()
def loadDaily(self, argScript):
try:
if(self.outputsize == 'compact'):
filename=self.folder + 'daily_compact_'+argScript+'.csv'
else:
filename=self.folder + 'daily_full_'+argScript+'.csv'
csvdf = pd.read_csv(filename)
csvdf=csvdf.rename(columns={'open':'1. open', 'high':'2. high', 'low':'3. low', 'close':'4. close', 'volume': '5. volume'})
convert_type={'1. open':float, '2. high':float, '3. low':float, '4. close':float, '5. volume':float}
csvdf = csvdf.astype(convert_type)
csvdf.set_index('timestamp', inplace=True)
csvdf.index = pd.to_datetime(csvdf.index)
csvdf.index.names = ['date']
except Exception as e:
csvdf = DataFrame()
return csvdf
def loadIntra(self, argScript):
try:
if(self.outputsize == 'compact'):
filename=self.folder + 'intraday_5min_compact_'+argScript+'.csv'
else:
filename=self.folder + 'intraday_5min_full_'+argScript+'.csv'
csvdf = pd.read_csv(filename)
csvdf=csvdf.rename(columns={'open':'1. open', 'high':'2. high', 'low':'3. low', 'close':'4. close', 'volume': '5. volume'})
convert_type={'1. open':float, '2. high':float, '3. low':float, '4. close':float, '5. volume':float}
csvdf = csvdf.astype(convert_type)
csvdf.set_index('timestamp', inplace=True)
csvdf.index = pd.to_datetime(csvdf.index)
csvdf.index.names = ['date']
except Exception as e:
csvdf = DataFrame()
return csvdf
def loadSMA(self, argScript='', argPeriod=20):
try:
#if(argPeriod == 0):
# csvdf = pd.read_csv(self.folder + 'SMA_'+argScript+'.csv')
#else:
csvdf = pd.read_csv(self.folder + 'SMA_'+str(argPeriod)+ '_'+argScript+'.csv')
convert_type={'SMA':float}
csvdf = csvdf.astype(convert_type)
csvdf.set_index('time', inplace=True)
csvdf.index = pd.to_datetime(csvdf.index)
csvdf.index.names = ['date']
#ti = TechIndicators('XXXX', output_format='pandas')
#padf, pameta = ti.get_sma(argScript)
except Exception as e:
csvdf = DataFrame()
return csvdf
def loadEMA(self, argScript):
try:
csvdf = pd.read_csv(self.folder + 'EMA_'+argScript+'.csv')
convert_type={'EMA':float}
csvdf = csvdf.astype(convert_type)
csvdf.set_index('time', inplace=True)
csvdf.index = pd.to_datetime(csvdf.index)
csvdf.index.names = ['date']
#ti = TechIndicators('XXXX', output_format='pandas')
#padf, pameta = ti.get_ema(argScript)
except Exception as e:
csvdf = DataFrame()
return csvdf
def loadVWMP(self, argScript):
try:
csvdf = pd.read_csv(self.folder + 'VWAP_'+argScript+'.csv')
convert_type={'VWAP':float}
csvdf = csvdf.astype(convert_type)
csvdf.set_index('time', inplace=True)
csvdf.index = pd.to_datetime(csvdf.index)
csvdf.index.names = ['date']
#ti = TechIndicators('XXXX', output_format='pandas')
#padf, pameta = ti.get_ema(argScript)
except Exception as e:
csvdf = DataFrame()
return csvdf
def loadRSI(self, argScript):
try:
csvdf = pd.read_csv(self.folder + 'RSI_'+argScript+'.csv')
convert_type={'RSI':float}
csvdf = csvdf.astype(convert_type)
csvdf.set_index('time', inplace=True)
csvdf.index = pd.to_datetime(csvdf.index)
csvdf.index.names = ['date']
#ti = TechIndicators('XXXX', output_format='pandas')
#padf, pameta = ti.get_ema(argScript)
except Exception as e:
csvdf = DataFrame()
return csvdf
def loadStochasticOscillator(self, argScript):
try:
csvdf = pd.read_csv(self.folder + 'STOCH_'+argScript+'.csv')
convert_type={'SlowD':float, 'SlowK':float}
csvdf = csvdf.astype(convert_type)
csvdf.set_index('time', inplace=True)
csvdf.index = pd.to_datetime(csvdf.index)
csvdf.index.names = ['date']
#ti = TechIndicators('XXXX', output_format='pandas')
#padf, pameta = ti.get_ema(argScript)
except Exception as e:
csvdf = DataFrame()
return csvdf
def loadMACD(self, argScript):
try:
csvdf = pd.read_csv(self.folder + 'MACD_'+argScript+'.csv')
convert_type={'MACD':float, 'MACD_Hist':float, 'MACD_Signal':float}
csvdf = csvdf.astype(convert_type)
csvdf.set_index('time', inplace=True)
csvdf.index = pd.to_datetime(csvdf.index)
csvdf.index.names = ['date']
#ti = TechIndicators('XXXX', output_format='pandas')
#padf, pameta = ti.get_ema(argScript)
except Exception as e:
csvdf = DataFrame()
return csvdf
def loadAROON(self, argScript):
try:
csvdf = pd.read_csv(self.folder + 'AROON_'+argScript+'.csv')
convert_type={'Aroon Down':float, 'Aroon Up':float}
csvdf = csvdf.astype(convert_type)
csvdf.set_index('time', inplace=True)
csvdf.index = pd.to_datetime(csvdf.index)
csvdf.index.names = ['date']
#ti = TechIndicators('XXXX', output_format='pandas')
#padf, pameta = ti.get_ema(argScript)
except Exception as e:
csvdf = DataFrame()
return csvdf
def loadBBands(self, argScript):
try:
csvdf = pd.read_csv(self.folder + 'BBANDS_'+argScript+'.csv')
convert_type={'Real Lower Band':float, 'Real Middle Band':float, 'Real Upper Band':float}
csvdf = csvdf.astype(convert_type)
csvdf.set_index('time', inplace=True)
csvdf.index = pd.to_datetime(csvdf.index)
csvdf.index.names = ['date']
#ti = TechIndicators('XXXX', output_format='pandas')
#padf, pameta = ti.get_ema(argScript)
except Exception as e:
csvdf = DataFrame()
return csvdf
def loadADX(self, argScript):
try:
csvdf = pd.read_csv(self.folder + 'ADX_'+argScript+'.csv')
convert_type={'ADX':float}
csvdf = csvdf.astype(convert_type)
csvdf.set_index('time', inplace=True)
csvdf.index = pd.to_datetime(csvdf.index)
csvdf.index.names = ['date']
#ti = TechIndicators('XXXX', output_format='pandas')
#padf, pameta = ti.get_ema(argScript)
except Exception as e:
csvdf = DataFrame()
return csvdf
def GetQuoteEndPoint(self, argScript):
try:
csvdf = pd.read_csv(self.folder + 'global_quote_'+argScript+'.csv')
csvdf=csvdf.rename(columns={'symbol':'01. symbol', 'open':'02. open', 'high':'03. high', 'low':'04. low', 'price': '05. price', 'volume':'06. volume', 'latestDay':'07. latest trading day', 'previousClose':'08. previous close', 'change': '09. change', 'changePercent':'10. change percent'})
convert_type = {'01. symbol': object, '02. open':object, '03. high':object, '04. low':object, '05. price':object, '06. volume':object, '07. latest trading day':object, '08. previous close':object, '09. change':object, '10. change percent':object}
csvdf = csvdf.astype(convert_type)
csvdf.index = ['Global Quote']
except Exception as e:
csvdf = DataFrame()
return csvdf
def loadDailyTrial(self, argScript):
"""stemp = {"2020-03-20": ["1640.0000","1778.0000","1536.0500","1753.9000","327948"],
"2020-03-19": ["1640.0000","1778.0000","1536.0500","1753.9000","327948"]}"""
csvdf = pd.read_csv(self.folder + 'daily_'+argScript+'.csv')
csvdf=csvdf.rename(columns={'open':'1. open', 'high':'2. high', 'low':'3. low', 'close':'4. close', 'volume': '5. volume'})
convert_type={'1. open':float, '2. high':float, '3. low':float, '4. close':float, '5. volume':float}
csvdf = csvdf.astype(convert_type)
csvdf.set_index('timestamp', inplace=True)
csvdf.index = pd.to_datetime(csvdf.index)
csvdf.index.names = ['date']
filename = self.folder + 'daily_'+argScript+'.data'
stemp = ''
fhandle = open(filename, 'r')
for line in fhandle:
line = line.rstrip('\n')
line = line.lstrip()
stemp = stemp + line
stemp=eval(stemp)
dailydf = DataFrame.from_dict(stemp, orient='index', columns=['1. open', '2. high', '3. low', '4. close', '5. volume'])
convert_type={'1. open':float, '2. high':float, '3. low':float, '4. close':float, '5. volume':float}
dailydf = dailydf.astype(convert_type)
dailydf.index = pd.to_datetime(dailydf.index)
dailydf.index.names = ['date']
ts = TimeSeries('XXXX', output_format='pandas')
padf, pameta = ts.get_daily('HDFC.BSE')
if __name__ == "__main__":
obj = PrepareTestData()
obj.loadDaily('HDFC.BSE')
input()