tushare获取突破60日新高的股票

system:OSX 10.11.6
python version:Python 3.5.2 :: Anaconda custom (x86_64)
tushare version:0.5.0
mysql version:Ver 14.14 Distrib 5.7.14, for osx10.11 (x86_64) using  EditLine wrapper
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 23 15:45:05 2016
@author: edgarcai
"""

#获取破指定天数内的新高 比如破60日新高
import tushare as ts
import datetime
import pandas as pd

info=ts.get_stock_basics()
highlist =pd.DataFrame({"date":"","open":"","high":"","close":"","low":"","volume":"","amount":""},index=["0"])

def loop_all_stocks():
    days = 60
    count =0
    for EachStockID in info.index:
        end_day=datetime.date(datetime.date.today().year,datetime.date.today().month,datetime.date.today().day)
        days=days*7/5
        start_day=end_day-datetime.timedelta(days)     #考虑到周六日非交易
        start_day=start_day.strftime("%Y-%m-%d")
        end_day=end_day.strftime("%Y-%m-%d")
        df= ts.get_h_data(EachStockID,start=start_day,end=end_day)
        if not(df is None):
            period_high=df['high'].max()
            today_high=df.iloc[0]['high']
            if today_high>=period_high:
                highlist.append(df,ignore_index=True)
                count+=1
                     
if __name__ == '__main__':
    loop_all_stocks()
    print("a new high list",highlist)



tushare获取突破60日新高的股票_第1张图片
赞赏是最真诚的认可

你可能感兴趣的:(tushare获取突破60日新高的股票)