-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIV_many2one_getLabels.py
39 lines (35 loc) · 1.32 KB
/
IV_many2one_getLabels.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
"""
To get labels for deep learning.
"""
import os
from pathlib import Path
import xlrd, xlwt
import pandas as pd
import numpy as np
dataDirName = "/run/user/1000/gvfs/smb-share:server=crjlambda-pc,share=data"
class getLabels:
def __init__(self, indexWanted):
self.indexWanted = indexWanted
self.readFilename = Path(os.getcwd(), dataDirName, self.indexWanted[0]+'.xls')
self.workSheet = self.readFiles()
self.returnLabels = self.generateLabels()
def readFiles(self):
labelWorkbook = xlrd.open_workbook(self.readFilename)
workSheet = labelWorkbook.sheet_by_index(0)
# print('Reading LABEL FILE...<DONE!>...')
return workSheet
def generateLabels(self):
workSheet = self.workSheet
returnLabels = pd.DataFrame(columns=['DATE', 'LABELS'])
returnLabels['DATE'] = [xlrd.xldate_as_datetime(dt.value, 0) for dt in workSheet.col(2)[2:-6]]
# Using daily log return as the labels.
close_t = [cl.value for cl in workSheet.col(6)[2:-6]]
close_t1 = [cl.value for cl in workSheet.col(6)[1:-7]]
logr = [np.log(close_t[i]/close_t1[i]) for i in range(len(close_t))]
returnLabels['LABELS'] = logr
return returnLabels
"""
indexWanted = ['RU0']
glReturn = getLabels(indexWanted=indexWanted)
labels = glReturn.returnLabels
"""