美文网首页股票小工具系列
tushare获取突破60日新高的股票

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

作者: 平凡啊菜 | 来源:发表于2016-09-23 17:54 被阅读761次
    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日新高的股票

        本文链接:https://www.haomeiwen.com/subject/rhntyttx.html