-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic8020.py
47 lines (36 loc) · 1.33 KB
/
basic8020.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
import pandas as pd
import basedf as basedf
def trade8020(close, priorhigh, priorlow, prioropen, priorclose):
min_perc = 0.20
max_perc = 0.80
priordayrange = priorhigh - priorlow
if priordayrange == 0:
r = 'notrade'
else:
o_perc = (prioropen - priorlow)/priordayrange
c_perc = (priorclose - priorlow)/priordayrange
if prioropen > priorclose and c_perc < min_perc and o_perc > max_perc \
and close > priorlow:
r = 'longwin'
elif prioropen > priorclose and c_perc < min_perc and \
o_perc > max_perc and close <= priorlow:
r = 'longloss'
elif priorclose > prioropen and c_perc > max_perc and \
o_perc < min_perc and close < priorhigh:
r = 'shortwin'
elif priorclose > prioropen and c_perc > max_perc and \
o_perc < min_perc and close >= priorhigh:
r = 'shortloss'
else:
r = 'notrade'
return r
def run8020test(df):
df['Trade8020'] = df.apply(lambda x: trade8020(x['Close'],
x['PriorHigh'],x['PriorLow'],x['PriorOpen'],x['PriorClose']),axis=1)
df.shape
df.head(20)
table = pd.pivot_table(df, index=['Trade8020'], aggfunc='count')
print(table['Close'])
if __name__ == "__main__":
df = basedf.prepcoredata()
run8020test(df)