-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathboll.py
40 lines (32 loc) · 1.01 KB
/
boll.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
import os,sys
import logging
import math
def readClosePrice(path):
closeArray=[]
try:
with open(path) as file:
data = file.read()
array = data.split('\n')
for i in range(0 , len(array)-1):
cell = array[i].split(' ')
closeArray.append(float(cell[4]))
logging.warning(cell[4])
except:
logging.info('read file failed.')
return closeArray
def square(x):
return x*x
def BOLL(closePrice , n):
if len(closePrice) > n:
for i in range(0,len(closePrice)-n):
print closePrice[n+i]
totalprice = sum(closePrice[i:n+i])
totalprice /= n
logging.warning('avg=%s' , totalprice)
det = round((sum([square(price-totalprice) for price in closePrice[i:n+i]])/n)**0.5 , 3)
upper = round(totalprice+2*det,2)
lower = round(totalprice-2*det,2)
logging.warning("up=%f mid=%f down=%f" , upper , totalprice , lower)
if __name__ == '__main__':
closePrice = readClosePrice("../KLineData/sz/002322.txt")
BOLL(closePrice , 20)