-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanalysis_ta_price_transform.py
More file actions
71 lines (52 loc) · 1.97 KB
/
analysis_ta_price_transform.py
File metadata and controls
71 lines (52 loc) · 1.97 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
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('analysis','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']
#########################################
##### Price Transform Functions #####
#########################################
#AVGPRICE - Average Price
avgprice = ta.AVGPRICE(openp, high, low, close)
#MEDPRICE - Median Price
medprice = ta.MEDPRICE(high, low)
#TYPPRICE - Typical Price
typprice = ta.TYPPRICE(high, low, close)
#WCLPRICE - Weighted Close Price
wclprice = ta.WCLPRICE(high, low, close)
df_save = pd.DataFrame(data ={
'date': np.array(df['date']),
'avgprice':avgprice,
'medprice':medprice,
'typprice':typprice,
'wclprice':wclprice
})
df_save.to_csv(current_dir+"/"+base_dir+"/"+out_dir+'/'+stock_symbol+"/"+out_dir+'_ta_price_transform_'+stock_symbol+'.csv',index=False)
if __name__ == '__main__':
main()