先用一个程序获得所有股票代码:
import tushare as ts,os
#使用自己的token,到官网申请
token=''
ts.set_token(token)
pro = ts.pro_api()
data = pro.query('stock_basic', exchange='', list_status='L')
data.to_csv(os.path.join("D:","stock_list.csv"))
CSV文件保存目录自己可选,按自己习惯定义。
然后使用以下程序选出需要的股票:
import tushare as ts,os
import pandas as pd
from collections import Counter
token=''
ts.set_token(token)
pro = ts.pro_api()
stock_list = pd.read_csv(os.path.join("D:", "stock_list.csv"))
tenyear_grow = dict()
fiveyear_grow = dict()
threeyear_grow = dict()
oneyear_grow = dict()
for i in range(len(stock_list)):
stock_code = stock_list["ts_code"][i]
try:
df_daily = pro.daily(ts_code=stock_code,start_date=20000101,end_date=20210401)
print("get stock data successsful!", i, stock_code, stock_list['name'][i])
try:
if(len(df_daily) >= 250*10):
tenyear_grow[stock_list['name'][i]] = (df_daily['close'][0] - df_daily['close'][2500-1]) / df_daily['close'][2500-1]
if (len(df_daily) >= 250 * 5):
fiveyear_grow[stock_list['name'][i]] = (df_daily['close'][0] - df_daily['close'][250 * 5-1]) / df_daily['close'][250 * 5-1]
if (len(df_daily) >= 250 * 3):
threeyear_grow[stock_list['name'][i]] = (df_daily['close'][0] - df_daily['close'][250 * 3-1]) / df_daily['close'][250 * 3-1]
if (len(df_daily) >= 250 * 1):
oneyear_grow[stock_list['name'][i]] = (df_daily['close'][0] - df_daily['close'][250 * 1-1]) / df_daily['close'][250 * 1-1]
except Exception as e:
pass
except Exception as e:
pass
tenyear_grow = Counter(tenyear_grow)
fiveyear_grow = Counter(fiveyear_grow)
threeyear_grow = Counter(threeyear_grow)
oneyear_grow = Counter(oneyear_grow)
print("10年涨幅排行:", tenyear_grow.most_common(50))
print("5年涨幅排行:", fiveyear_grow.most_common(50))
print("3年涨幅排行:", threeyear_grow.most_common(50))
print("1年涨幅排行:", oneyear_grow.most_common(50))
这里提供一个选出的结果,供大家白嫖^_^:
10年涨幅排行: [('闻泰科技', 30.92182410423453), ('通策医疗', 16.982770997846373), ('紫光国微', 11.368786127167628), ('中国中免', 10.84061895551257), ('酒鬼酒', 10.562310030395137), ('贵州茅台', 9.151078773179728), ('长春高新', 7.7942890442890445), ('紫光学大', 7.56599552572707), ('五粮液', 6.907347300088523), ('妙可蓝多', 6.505277044854881), ('中航沈飞', 6.4523536165327195), ('宏发股份', 5.811034482758621), ('视觉中国', 5.353711790393014), ('中炬高新', 5.016149068322981), ('万华化学', 4.856905158069883), ('泸州老窖', 4.424783027965285), ('恒生电子', 4.3742802303262955), ('ST生物', 4.2591093117408905), ('航锦科技', 4.15625), ('ST舍得', 4.047560975609756), ('扬农化工', 3.857027136492507), ('中环股份', 3.778716216216216), ('恒力石化', 3.626182965299684), ('上海机场', 3.6246006389776357), ('双林生物', 3.5985037406483795), ('京基智农', 3.5509499136442146), ('百川能源', 3.5396825396825395), ('振华科技', 3.3505976095617527), ('中国海防', 3.3222222222222224), ('普洛药业', 3.246268656716418), ('山西汾酒', 3.1751348638815715), ('上峰水泥', 3.1698473282442747), ('福耀玻璃', 3.07787610619469), ('西部创业', 3.0416666666666665), ('贝瑞基因', 3.034912718204489), ('长电科技', 2.9389400921658986), ('招商银行', 2.915708812260536), ('五矿稀土', 2.8747300215982725), ('万科A', 2.8461538461538463), ('*药业', 2.7704280155642027), ('片仔癀', 2.552364446645209), ('北新建材', 2.5117982099267695), ('风华高科', 2.427942794279428), ('航天电器', 2.410144927536232), ('山东路桥', 2.3879781420765025), ('中航光电', 2.3715710723192016), ('航天发展', 2.341772151898734), ('法拉电子', 2.338487394957983), ('东方银星', 2.3202898550724633), ('中原传媒', 2.296460176991151)]
5年涨幅排行: [('山西汾酒', 20.40192926045016), ('五粮液', 10.147254575707157), ('酒鬼酒', 9.670406732117813), ('贵州茅台', 8.8519027069439), ('泸州老窖', 8.770733825445072), ('重庆啤酒', 7.853619729514717), ('闻泰科技', 7.80503144654088), ('隆基股份', 7.453410182516811), ('恒立液压', 7.109700815956483), ('古井贡酒', 6.5901047309498), ('通策医疗', 6.070279424216765), ('三一重工', 6.026748971193415), ('水井坊', 5.851532567049809), ('中国中免', 5.568240343347639), ('智飞生物', 5.4967984934086624), ('星宇股份', 5.494845360824742), ('扬农化工', 4.951364764267991), ('海大集团', 4.869074492099323), ('片仔癀', 4.81714980741942), ('妙可蓝多', 4.671984047856431), ('海天味业', 4.6011216263582195), ('北方华创', 4.550657385924207), ('博汇纸业', 4.411575562700964), ('广联达', 4.375708502024292), ('万华化学', 4.346835443037975), ('卫星石化', 3.904947916666667), ('ST舍得', 3.857981220657278), ('泰格医药', 3.7714558169103625), ('北新建材', 3.6964091403699673), ('普洛药业', 3.417701863354037), ('神州数码', 3.304651162790698), ('中炬高新', 3.114698385726423), ('长春高新', 3.1127361918604657), ('百润股份', 3.05355150613611), ('华新水泥', 3.0511945392491464), ('华友钴业', 3.0245901639344264), ('晶盛机电', 3.0219780219780223), ('中航沈飞', 2.950699939135727), ('沪电股份', 2.902097902097902), ('太阳纸业', 2.881481481481482), ('航锦科技', 2.859649122807018), ('新城控股', 2.8304552590266874), ('海螺水泥', 2.819537658463833), ('宏大爆破', 2.801470588235294), ('士兰微', 2.797805642633229), ('阳光电源', 2.7778947368421054), ('海尔智家', 2.7657004830917873), ('东方雨虹', 2.6129943502824857), ('长城汽车', 2.6127098321342923), ('上峰水泥', 2.5355987055016187)]
3年涨幅排行: [('坚朗五金', 8.91213389121339), ('韦尔股份', 8.048995417694748), ('安井食品', 7.6039603960396045), ('百润股份', 7.436532507739938), ('酒鬼酒', 6.140309713749414), ('华测检测', 5.867469879518072), ('通策医疗', 5.80336773492667), ('珀莱雅', 5.590157154673284), ('妙可蓝多', 5.4282485875706215), ('山西汾酒', 4.989920806335493), ('智飞生物', 4.821464731690854), ('中国中免', 4.742589118198874), ('盐津铺子', 4.616496598639456), ('春风动力', 4.4963155613350665), ('中公教育', 4.375954198473282), ('普洛药业', 4.220183486238532), ('重庆啤酒', 4.128571428571429), ('闻泰科技', 4.093555093555094), ('中潜股份', 4.077090909090909), ('天华超净', 3.940298507462686), ('凯莱英', 3.8721538202057686), ('七一二', 3.7531206657420255), ('金域医学', 3.7389033942558747), ('宏大爆破', 3.5955555555555554), ('兴齐眼药', 3.301488238118099), ('振华科技', 3.2857142857142856), ('阳光电源', 3.2700773349196908), ('博腾股份', 3.234963913392141), ('亿纬锂能', 3.2290377039954987), ('昌红科技', 3.218795888399413), ('三一重工', 3.210850801479655), ('中国软件', 3.1287586738627597), ('中科创达', 3.101312689330191), ('北方华创', 3.0094972067039105), ('片仔癀', 2.8705152414351227), ('泰格医药', 2.8489743589743592), ('鸿路钢构', 2.784178187403994), ('泸州老窖', 2.7698106885575475), ('星宇股份', 2.666343355965082), ('五粮液', 2.649959139199128), ('沪电股份', 2.58458244111349), ('新宙邦', 2.570294255021018), ('石大胜华', 2.5387885228480336), ('大立科技', 2.4856711915535445), ('海大集团', 2.451327433628318), ('金发科技', 2.440570522979398), ('古井贡酒', 2.420735677083333), ('东方通', 2.3975000000000004), ('洽洽食品', 2.3092505064145845), ('诚迈科技', 2.296639064783244)]
1年涨幅排行: [('阳光电源', 6.4152892561983474), ('科沃斯', 6.315112540192926), ('酒鬼酒', 4.827652240520873), ('未来股份', 3.8986928104575163), ('朗姿股份', 3.8673740053050403), ('美迪西', 3.7377477339068976), ('传音控股', 3.5527288540987167), ('中国中免', 3.242273042273042), ('天赐材料', 3.1680286006128706), ('昌红科技', 3.145743145743146), ('山西汾酒', 3.1091492776886036), ('山东赫达', 3.0307982401005655), ('春风动力', 2.9625), ('隆基股份', 2.951504265828469), ('上机数控', 2.886918604651163), ('长城汽车', 2.862820512820513), ('泉阳泉', 2.8562300319488823), ('百润股份', 2.851590106007067), ('英科医疗', 2.8473809523809526), ('佰仁医疗', 2.8317380352644834), ('迈为股份', 2.7573438994398143), ('ST舍得', 2.7271499324628543), ('巨星科技', 2.648648648648649), ('ST毅达', 2.6455696202531644), ('汇川技术', 2.634084147896303), ('石头科技', 2.577998528329654), ('坚朗五金', 2.54261909848323), ('天华超净', 2.500587544065805), ('比亚迪', 2.416614745586708), ('中远海控', 2.414141414141414), ('ST抚钢', 2.4025974025974026), ('龙蟠科技', 2.395691609977324), ('名臣健康', 2.3906137184115526), ('*ST融捷', 2.3885714285714283), ('泸州老窖', 2.377157436590125), ('普丽盛', 2.2980599647266313), ('鸿路钢构', 2.2542932628797887), ('太平鸟', 2.2042723631508676), ('国际医学', 2.169724770642202), ('御家汇', 2.1072386058981234), ('康龙化成', 2.0708871132964553), ('锦浪科技', 2.0553647201454837), ('天山生物', 2.0546558704453437), ('海南发展', 2.0436893203883493), ('志邦家居', 2.020942408376963), ('东方盛虹', 2.0106609808102345), ('国茂股份', 1.9984012789768186), ('宁德时代', 1.9974879047264607), ('永兴材料', 1.9903412749517062), ('妙可蓝多', 1.9522573949143749)]