-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbalanceRise.py
57 lines (48 loc) · 1.51 KB
/
balanceRise.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
#coding:utf-8
#匀线上升:沿20日匀线上升,限定向上偏差和向下偏差
import pymongo
import pandas as pd
import time
client = pymongo.MongoClient(host='localhost', port=27017)
db = client.ffgHarvester
stockDailyCol = db.stockDaily
stockCalendarCol = db.stockCalendar
stockListCol = db.stockList
upOffset = 0.10
downOffset = 0.02
seriesDays = 60
def analyzeBalanceRise():
todayStr = time.strftime("%Y%m%d", time.localtime())
dayList = list(stockCalendarCol.find({"is_open":1,'cal_date':{"$lte":todayStr}}).limit(seriesDays).sort('cal_date', pymongo.DESCENDING)) #倒推获取指定时间的交易日期
lastCal = dayList[len(dayList)-1]
lastDayStr = lastCal['cal_date'] #第一个交易日的日期
stocks = stockDailyCol.find({'trade_date':{'$lte':todayStr,'$gte':lastDayStr}})
stocksDF = pd.DataFrame(stocks)
stockList = stockListCol.find()
i = 1
for stock in stockList:
df = stocksDF[(stocksDF['ts_code'] == stock['ts_code'])]
if len(df) < seriesDays:
# print('股票代码:'+stock['ts_code']+'近期不足交易日期')
i+=1
continue
allow = True
for index,row in df.iterrows():
ma20 = row['ma20']
close = row['close']
if close >= ma20:
if ((close-ma20)/ma20)>upOffset:
allow = False
break
else:
if ((ma20-close)/ma20)>downOffset:
allow = False
break
if allow:
print('沿20日匀线上升,股票代码:'+stock['ts_code'])
# print('分析第'+str(i)+'支股票')
i+=1
def main():
analyzeBalanceRise()
if __name__ == '__main__':
main()