python根据财务指标寻找价值股票

确定股票池

from concurrent.futures import ThreadPoolExecutor
import urllib
import os
from time import sleep
import pandas as pd
# 上证代码
shanghaicode = []
for i in range(600000, 606000, 1):shanghaicode.append(str(i))# 深证代码
shenzhencode = []
for i in range(1000000, 1005000, 1):i = str(i)[1:]shenzhencode.append(i)

 爬取数据

def get_data(num):url = 'http://quotes.money.163.com/service/lrb_' + str(num) + '.html'while True:try:content = urllib.request.urlopen(url, timeout=2).read()path = '利润表_multi/' + str(num) + '.csv'if os.path.exists(path):print(path + " already existed!!!")breakwith open('利润表_multi/' + str(num) + '.csv', 'wb') as f:f.write(content)print(num)sleep(1)except Exception as e:if str(e) == 'HTTP Error 404: Not Found':print(f"{num} : {e}")breakelse:print(e)

多线程运作

executor = ThreadPoolExecutor(max_workers=10)
executor.map(get_data, shenzhencode)
executor.shutdown()executor = ThreadPoolExecutor(max_workers=10)
executor.map(get_data, shanghaicode)
executor.shutdown()

 读取本地数据

def generatefile(path):names = []for dirpath, dirnames, filenames in os.walk(path):names = filenamesreturn names

datapath = '利润表_multi/'
datalist = generatefile(datapath)
invest = []
for data in datalist:try:path = datapath + datatemp = pd.read_csv(path, encoding='gbk', header=None)temp = pd.DataFrame(temp.values.T, index=temp.columns, columns=temp.index)temp.columns = temp.loc[0]temp = temp[1:]temp = temp[:-1]#temp['报告日期'] = temp['报告日期'].apply(convert_date)temp = temp[['报告日期','净利润(万元)']]temp['净利润(万元)'] = temp['净利润(万元)'].astype(int)temp_g = pd.DataFrame(temp.groupby('报告日期').sum())temp_g = temp_g[:-1] # 去除2021temp_g.reset_index(inplace=True)temp_g = temp_g['净利润(万元)']anu_diff = temp_g.diff()temp_g = temp_g.values# anu_diff = anu_diff.valuestemp_g = temp_g[::-1]ratio = 0.3if len(temp_g) >= 5:# rate = anu_diff[-5:]/temp_g[-6:-1]# if rate[-1] >= ratio and rate[-2] >= ratio and rate[-3] >= ratio and rate[-4] >= ratio:#         invest.append(data)growth_anu = []for i in range(len(temp_g)):if i == (len(temp_g)-1):continueyear = temp_g[i]ex_year = temp_g[i+1]if i+1 <= 5:growth = (year - ex_year)/ex_yeargrowth_anu.append(growth)if growth_anu[0] >= ratio and growth_anu[1] >= ratio and growth_anu[2] >= ratio and growth_anu[3] >= ratio:invest.append(data)except Exception as e:print(data + f':{e}')
invest = pd.DataFrame(invest)
invest.to_excel('连续4年增长30%.xls')

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/449470.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

WPF Bitmap转BitmapSource,Image

//引用&#xff1a;using System.Windows.Interop; //Imagingusing System.Drawing; //Bitmap public static Imaging.BitmapSource ConvertToBitmapSource(Bitmap btmap) { return Imaging.CreateBitmapSourceFromHBitmap(btmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empt…

解决jboss.resteasy.spi.UnhandledException: Response is committed, can‘t handle exception

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到教程。 报错如题&#xff0c;如图&#xff1a; 我的情况是&#xff1a;项目作压测&#xff0c;这个接口请求量不大时是OK的 &#xff0c;当达到…

linux下如何做ghost,又简单又方便,很实用的方法!!!

Linux 做ghost 使用指南。 转载时请注明本博客地址。 1. 使用unetbootin-windows-585.exe 软件做 ubuntu 的liveusb &#xff0c;一定是做liveusb&#xff0c;不是liveCD&#xff0c;如果你做的是liveCD&#xff0c;要把做好的文件拷出来&#xff0c;否则&#xff0c;重…

Webpack4: Tree-shaking 深度解析

什么是Tree-shaking 所谓Tree-shaking就是‘摇’的意思&#xff0c;作用是把项目中没必要的模块全部抖掉&#xff0c;用于在不同的模块之间消除无用的代码&#xff0c;可列为性能优化的范畴。 Tree-shaking早期由rollup实现&#xff0c;后来webpack2也实现了Tree-shaking的功能…

真格量化——GFTD策略

#!/usr/bin/env python # coding:utf-8 from PoboAPI import * import datetime import numpy as np import math#开始时间,用于初始化一些参数 def OnStart(context) :print "I\m starting..."#设置全局变量g.signalcount = 0 g.signal_list = []g.buysignal = 0 g…

解决org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException: Encountered a duplicated sql ...

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到教程。 报错如题&#xff1a; org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException: Encountered a duplicated sql alias [id]…

Spring WebFlux 响应式编程学习笔记(一)

各位Javaer们&#xff0c;大家都在用SpringMVC吧&#xff1f;当我们不亦乐乎的用着SpringMVC框架的时候&#xff0c;Spring5.x又悄(da)无(zhang)声(qi)息(gu)的推出了Spring WebFlux。web? 不是已经有SpringMVC这么好用的东西了么&#xff0c;为啥又冒出个WebFlux&#xff1f;…

Django Rest Framework -解析器

基本代码结构 urls.py rom django.conf.urls import url, include from web.views.s5_parser import TestViewurlpatterns [url(rtest/, TestView.as_view(), nametest), ]views.py from rest_framework.views import APIView from rest_framework.response import Response f…

真格量化——菜粕策略

#!/usr/bin/env python # coding:utf-8 from PoboAPI import * import datetime import time import numpy as np from copy import *#开始时间,用于初始化一些参数 def OnStart(context) :context.myacc = None#登录交易账号if context.accounts["回测期货"].Login…

PostgreSQL查看版本信息

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到教程。 1.查看客户端版本 psql --version 1 2.查看服务器端版本 2.1 查看详细信息 select version(); 1 2.2 查看版本信息 show server_ve…

U盘版便携式Linux制作, casper-rw 解析

一直都在想&#xff0c;不管用谁的电脑&#xff0c;我都可以得到一个完全一致的工作环境&#xff0c;上面有我喜爱的软件&#xff0c;有我保存的重要资料&#xff0c;甚至浏览器的各种偏好都得一模一样&#xff01;现在的云计算技术可以部分解决这个问题&#xff0c;但是远远不…

真格量化-50ETF期权波动率策略

#!/usr/bin/env python # coding:utf-8 from PoboAPI import * import datetime import time import numpy as np #日线级别 #开始时间,用于初始化一些参数 def OnStart(context) :print("I\m starting...")#设定一个全局变量品种,本策略交易50ETF期权g.code = Get…

canvas反向裁剪技巧

我们都知道在canvas 可以通过clip来实现剪裁功能&#xff0c;其步骤一般是先设置要裁剪的区域&#xff08;路径&#xff09;&#xff0c;然后通过ctx.clip()的实现裁剪&#xff0c;裁剪之后&#xff0c;后续的绘制只能在裁剪的区域显示效果&#xff0c;比如如下一段代码&#x…

set 和select 的区别

简单赋值是没有区别的 转载于:https://www.cnblogs.com/bingyizhihun/p/10597908.html

postgres大版本升级

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到教程。进行升级版本之前请一定做好备份&#xff01;查看当前版本&#xff1a;[postgresnode1 ~]$ psqlpsql (9.4.4)Type "help" for h…

马上有钱:揭密25种成为有钱人的方法(图)

1、做你真正感兴趣的事—你会花很多时间在上面&#xff0c;因此你一定要感兴趣才行&#xff0c;如果不是这样的话&#xff0c;你不愿意把时间花在上面&#xff0c;就得不到成功。 2、自己当老板。为别人打工&#xff0c;你绝不会变成巨富&#xff0c;老板一心一意地缩减开支&a…

无人承运平台系统流程图

转载于:https://www.cnblogs.com/procedureMonkey/p/10598052.html

Neither the JAVA_HOME nor the JRE_HOME environment variable is defined

Centos7.5 启动tomcat报错 报错: Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this program原因:没有安装java 解决方法:安装java yum install java -y转载于:https://www.cnblogs…

让自己变成一个上进的人

1.认真设计你的环境2.引入外部监督 求“绑架”3.获取不确定的反馈4.选择一条既细密&#xff0c;又永无止境的职业上升台阶。转载于:https://www.cnblogs.com/Julietma/p/10600241.html

年买笔记本的8个小技巧 最适合自己才最好(组图)

显然&#xff0c;智能手机和平板在一定程度上可以替代传统电脑&#xff0c;让我们可以随时随地上网、使用各种应用。不过&#xff0c;传统电脑也拥有它的不可替代性&#xff0c;比如移动办公、视频编辑、玩游戏&#xff0c;笔记本电脑可能是个更好的选择。 作为一种成熟的电脑…