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
"""
#獲取破指定天數(shù)內(nèi)的新高 比如破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)
非常好的模式,讓我今年收益翻倍的文章嘹悼,強(qiáng)烈推薦分享下:
2020年4月至6月凈利潤斷層實(shí)戰(zhàn)小結(jié)-真香~