-
Notifications
You must be signed in to change notification settings - Fork 0
/
stock.py
51 lines (41 loc) · 1.37 KB
/
stock.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
# coding=utf-8
import tushare as ts
import time
from collections import Iterable
from functools import reduce
def m30(code):
startDate = time.strftime("%Y-%m-%d", time.localtime(time.time() - 24 * 3600 * 30))
endDate = time.strftime("%Y-%m-%d", time.localtime(time.time()))
# print(startDate)
# print(endDate)
df = ts.get_hist_data(code, startDate, endDate)
closeList = df['close'].to_list()
def add(x, y):
return x + y
sum = reduce(add, closeList)
return round(sum / len(closeList), 2)
stockList = ts.get_zz500s()
startDate = time.strftime("%Y-%m-%d", time.localtime(time.time() - 24 * 3600 * 5))
endDate = time.strftime("%Y-%m-%d", time.localtime(time.time()))
goodStock1 = goodStock2 = {}
for index, row in stockList.iterrows():
code = row["code"]
name = row["name"]
print(name)
print(code)
m30 = m30(code)
print(m30)
df = ts.get_hist_data(code, startDate, endDate)
closeList = df['close'].to_list()
result = list(filter(lambda x: x > m30, closeList))
if len(result) == len(closeList):
goodStock1[code] = name
todayClose = closeList[-1]
if m30 <= todayClose <= 1.05 * m30:
goodStock2[code] = name
time.sleep(2)
# break
print('最近5天收盘价格都大于30日均价:')
print(goodStock1)
print('30日均价 <= 今日收盘价格 <= 30日均价*1.05:')
print(goodStock2)