获取破发新股

#获取跌破发行价的新股,结果存在pofa_gupiao list里面,并将其close图形保存在pofa_gupiao文件夹
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import os

stock_list = []
pofa_gupiao = []
#设置路径
dir_list = []
lujing = r'C:\Users\tang\AnacondaProjects\new_stock'
for i in os.listdir(r'C:\Users\tang\AnacondaProjects\new_stock'):
    a = i.split('.')[0]
    if a[0] != '3':
        dir_list.append(lujing+'\\'+i)
        stock_list.append(i.split('.')[0])
        
#个股
for j in dir_list:
    #获取数据
    df = pd.read_table(j,header=1,usecols=range(6), parse_dates=[0], index_col=0,encoding='gb2312')
    df.index.rename('date', inplace=True)
    df.rename(columns={'    开盘':'open', '    最高':'high', '    最低':'low', '    收盘':'close','    成交量':'vol'}, inplace=True)
    df = df.drop('数据来源:通达信')
    df.index = df.index.astype(np.datetime64)
    df.close = df.close.astype(np.float32)#设置为32位,4字节,默认64位,8字节,append到list之后就会多小数位
    zuijin = df.tail(10)#获取最近10天的数据
    ipo_price = df.close[0]/1.44#获取发行价
    
    name = (j.split('\\')[-1]).split('.')[0]
    if not name[0] == '3':
        if zuijin.close.min() <= ipo_price:
            pofa_gupiao.append(name)
            #绘制跌破发行价的股票的close图形
            plt.figure(figsize=(10,8),dpi=80)
            plt.title(name)
            plt.ylabel('close')
            plt.ylim(df.low.min(),df.high.max())
            plt.plot(df.index,df.close,color='green',marker='o')
            #保存图片
            cur_dir = os.getcwd()  # get current path
            folder_name = 'pofa_gupiao'
            dir_new=os.path.join(cur_dir, folder_name)
            if not os.path.exists(dir_new):
                path=os.mkdir(dir_new)
            file_name = dir_new + r'/' + name
            plt.savefig(file_name,dpi=80)
            plt.close()
            plt.clf()

 

posted on 2018-01-01 21:33  斯文依旧在  阅读(167)  评论(0编辑  收藏  举报