-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanalysis_ta_math_transform_loop.py
More file actions
120 lines (88 loc) · 3.4 KB
/
analysis_ta_math_transform_loop.py
File metadata and controls
120 lines (88 loc) · 3.4 KB
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
import numpy as np
import pandas as pd
import talib as ta
from talib import MA_Type
import os
import configparser
parser = configparser.ConfigParser()
parser.read('config.ini')
current_dir = os.path.dirname(os.path.realpath(__file__))
base_dir = parser.get('directory','base_dir')
in_dir = parser.get('directory','company_datalist_prefilter')
in_dir1 = parser.get('directory','company_stock_marketprice_baseprice_prefilter')
out_dir = parser.get('directory','company_stock_marketprice_processed')
comp_datalist = pd.read_csv(current_dir+"/"+base_dir+"/"+in_dir+"/"+in_dir+"_combined.csv")
for i in range(0,comp_datalist['stock_symbol'].count()):
try:
# read csv file and transform it to datafeed (df):
df = pd.read_csv(current_dir+"/"+base_dir+"/"+in_dir1+"/"+in_dir1+'_'+comp_datalist['stock_symbol'][i]+'.csv')
print("[Status]Processing TA Math Transform for "+comp_datalist['stock_symbol'][i])
# set numpy datafeed from df:
df_numpy = {
'Date': np.array(df['date']),
'Open': np.array(df['open'], dtype='float'),
'High': np.array(df['high'], dtype='float'),
'Low': np.array(df['low'], dtype='float'),
'Close': np.array(df['close'], dtype='float'),
'Volume': np.array(df['volume'], dtype='float')
}
date = df_numpy['Date']
openp = df_numpy['Open']
high = df_numpy['High']
low = df_numpy['Low']
close = df_numpy['Close']
volume = df_numpy['Volume']
#########################################
##### Math Transform Functions ######
#########################################
#ACOS - Vector Trigonometric ACos
acos = ta.ACOS(close)
#ASIN - Vector Trigonometric ASin
asin = ta.ASIN(close)
#ATAN - Vector Trigonometric ATan
atan = ta.ATAN(close)
#CEIL - Vector Ceil
ceil = ta.CEIL(close)
#COS - Vector Trigonometric Cos
cos = ta.COS(close)
#COSH - Vector Trigonometric Cosh
cosh = ta.COSH(close)
#EXP - Vector Arithmetic Exp
exp = ta.EXP(close)
#FLOOR - Vector Floor
floor = ta.FLOOR(close)
#LN - Vector Log Natural
ln = ta.LN(close)
#LOG10 - Vector Log10
log10 = ta.LOG10(close)
#SIN - Vector Trigonometric Sin
sin = ta.SIN(close)
#SINH - Vector Trigonometric Sinh
sinh = ta.SINH(close)
#SQRT - Vector Square Root
sqrt = ta.SQRT(close)
#TAN - Vector Trigonometric Tan
tan = ta.TAN(close)
#TANH - Vector Trigonometric Tanh
tanh = ta.TANH(close)
df_save = pd.DataFrame(data ={
'date': np.array(df['date']),
'acos':acos,
'asin':asin,
'atan':atan,
'ceil':ceil,
'cos':cos,
'cosh':cosh,
'exp':exp,
'floor':floor,
'ln':ln,
'log10':log10,
'sin':sin,
'sinh':sinh,
'sqrt':sqrt,
'tan':tan,
'tanh':tanh
})
df_save.to_csv(current_dir+"/"+base_dir+"/"+out_dir+'/'+comp_datalist['stock_symbol'][i]+"/"+out_dir+'_ta_math_transform_'+comp_datalist['stock_symbol'][i]+'.csv',index=False)
except:
print("[Status]Error fail to processed TA Math Transform for "+comp_datalist['stock_symbol'][i])