import pymongo import os import pandas as pd import numpy as np #读取股票代码 stock_name=[] path1='C:/new_tdx/vipdoc/sh/pythondata' path2='C:/new_tdx/vipdoc/sz/pythondata' name1=os.listdir(path1) name2=os.listdir(path2) for i in name1: stock_name.append(i[2:-4]) for i in name2: stock_name.append(i[2:-4]) print(stock_name) #链接数据库,获取股票数据 client=pymongo.MongoClient() conn=client.db #获取一只 """ for itme in conn[stock_name[0]].find() : print (itme) """ #获取股票的交易日期 result_set=set() for stock in stock_name[:100]: date_list=[] for item in conn[stock].find(): date_list.append(item['date ']) result_set=result_set|set(date_list) result_date=list(result_set) result_date.sort() #获取股票数据,并分析是否形成突破缺口 tiaokong_result={} for date in result_date[1:]: date_tiaokong_up=[] date_tiaokong_down=[] for stock in stock_name: date_list=[] for item in conn[stock_name[0]].find(): date_list.append(item['date ']) if date in date_list: #获取当天的高开低收数据 data=conn[stock].find_one({'date ':date}) stock_open=data['open'] stock_high=data[' high '] stock_low=data['low'] stock_close=data[' close '] stock_vol=data[' vol '] stock_amount=data['amout'] #获取前天高开低收的数据 index=date_list.index(date) predate=data_list[index-1] data=conn[stock].find_one({'date ':predate}) stock_preopen=data['open'] stock_prehigh=data[' high '] stock_prelow=data['low'] stock_preclose=data[' close '] stock_prevol=data[' vol '] stock_preamount=data['amout'] #分析是否存在缺口 if stock_open>stock_prehigh and stock_low>stock_prehigh: print('存在向上的跳空缺口') date_tiaokong_up.append(stock) if stock_open<stock_prelow and stock_high<stock_prelow: print('存在向下的跳空缺口') date_tiaokong_down.append(stock) tiaokong_result{str(date)}=[date_tiaokong_up,date_tiaokong_down]