-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalysis_ta_overlap_studies.py
132 lines (98 loc) · 3.77 KB
/
analysis_ta_overlap_studies.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
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__))
stock_symbol = parser.get('general_settings','stock_symbol')
base_dir = parser.get('directory','base_dir')
in_dir = parser.get('directory','company_stock_marketprice_baseprice_prefilter')
out_dir = parser.get('directory','company_stock_marketprice_processed')
def main():
# read csv file and transform it to datafeed (df):
df = pd.read_csv(current_dir+"/"+base_dir+"/"+in_dir+"/"+in_dir+'_'+stock_symbol+'.csv')
# 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']
#########################################
####### Overlap Study Function ##########
#########################################
#Bollinger Band Indicator
upperBB, middleBB, lowerBB = ta.BBANDS(close, matype=MA_Type.T3)
#Double Exponential Moving Average
dema = ta.DEMA(close, timeperiod=30)
#Exponential Moving Average
ema = ta.EMA(close, timeperiod=30)
#HT_TRENDLINE - Hilbert Transform - Instantaneous Trendline
ht = ta.HT_TRENDLINE(close)
#KAMA - Kaufman Adaptive Moving Average
kama = ta.KAMA(close, timeperiod=30)
#MA10 - Moving average 10
ma10 = ta.MA(close, timeperiod=10, matype=0)
#MA100 - Moving average
ma100 = ta.MA(close, timeperiod=100, matype=0)
#MAMA - MESA Adaptive Moving Average
#mama, fama = ta.MAMA(close, fastlimit=0, slowlimit=0)
#MAVP - Moving average with variable period
#mavp = ta.MAVP(close, periods, minperiod=2, maxperiod=30, matype=0)
#MIDPOINT - MidPoint over period
midpoint = ta.MIDPOINT(close, timeperiod=14)
#MIDPRICE - Midpoint Price over period
midprice = ta.MIDPRICE(high, low, timeperiod=14)
#SAR - Parabolic SAR
sar = ta.SAR(high, low, acceleration=0, maximum=0)
#SAREXT - Parabolic SAR - Extended
sarext = ta.SAREXT(high, low, startvalue=0, offsetonreverse=0, accelerationinitlong=0, accelerationlong=0, accelerationmaxlong=0, accelerationinitshort=0, accelerationshort=0, accelerationmaxshort=0)
#Simple Moving Average indicator sample 10
sma10 = ta.SMA(close, 10)
#T3 - Triple Exponential Moving Average (T3)
t3 = ta.T3(close, timeperiod=5, vfactor=0)
#TEMA - Triple Exponential Moving Average
tema = ta.TEMA(close, timeperiod=30)
#TRIMA - Triangular Moving Average
trima = ta.TRIMA(close, timeperiod=30)
#WMA - Weighted Moving Average
wma = ta.WMA(close, timeperiod=30)
df_save = pd.DataFrame(data ={
'date': date,
'upperBB': upperBB,
'middleBB': middleBB,
'lowerBB': lowerBB,
'dema':dema,
'ema':ema,
'ht':ht,
'kama':kama,
'ma10':ma10,
'ma100':ma100,
#'mama':mama,
#'fama':fama,
'midpoint':midpoint,
'midprice':midprice,
'sar':sar,
'sarext':sarext,
'sma10':sma10,
't3':t3,
'tema':tema,
'trima':trima,
'wma':wma,
'close':close
})
#df_save = df_save.dropna()
df_save.to_csv(current_dir+"/"+base_dir+"/"+out_dir+'/'+stock_symbol+"/"+out_dir+'_ta_overlap_studies_'+stock_symbol+'.csv',index=False)
if __name__ == '__main__':
main()