最近听了一个线上讲座,讲座的内容大概就是讲解量化投资的。因为本人目前没做过相关的实践,但是对于老师提出的思路很赞同,老师的思路是股票市场往往都是机构说了算,但是机构具体想要拉升那只股票,就不得而知。那么有没有一种类似阴谋论的现实现象来串通一气,然后拉升股票的价格。确实是有这种操作。当然不能说是串通一气了,但是多少有那种意思。而这种所谓串通一气的方式就叫做“机构调研”,也就是说机构管理者会在持股前与上市公司进行沟通,表达机构想要持有该上市公司的股票的想法。当然也不能说这么明白的话,机构调研除了投资的成分还有现场观摩等,相当于机构了解了该公司运作,当然具体的调研结果也是会通过报表的方式向外进行暴露。一个潜在的现象是调研后的股票会有一定的异动,所以这也是一般投资者应该关注的地方。
所以这块作者就通过天天基金网站来拉取股票的机构调研信息。具体代码如下
配置文件
-
[Mysql-Database]
-
host=localhost
-
user=root
-
passwd=tianjingle
-
db=noun
-
charset=utf8
-
[Email]
-
pass=
1
-
user=
1062879@qq.com
-
sender=
2695062879@qq.com
-
receiver=
2695062879@qq.com,
1640910489@qq.com
-
[System]
-
syn=
True
-
scans=
4000
-
[Jgdy]
-
fetchUrl=http://datainterface3.eastmoney.com/EM_DataCenter_V3/api/JGDYHZ/GetJGDYMX?js=datatable435798&tkn=eastmoney&secuCode={
0}&sortfield=
4&sortdirec=
1&pageNum={
1}&pageSize={
2}&cfg=jgdyhz&p=
2&page
No={
3}&_=
1610583145484
配置文件初始化
-
import configparser
-
class Connection:
-
-
-
host =
'localhost'
-
port =
3307
-
user =
'root'
-
passwd =
''
-
db =
'noun'
-
charset =
'utf8'
-
-
-
emailPass=
''
-
emaialUser=
''
-
sender=
''
-
receivers=
''
-
-
-
jgdyUrl=
''
-
syn=False
-
scans=
2000
-
-
-
def __init__(self):
-
cf = configparser.ConfigParser()
-
cf.read(
"config.ini")
-
self.emailPass = cf.get(
"Email",
"pass")
-
self.emaialUser = cf.get(
"Email",
"user")
-
self.sender = cf.get(
"Email",
"sender")
-
self.receivers = cf.get(
"Email",
"receiver")
-
self.host = cf.get(
"Mysql-Database",
"host")
-
self.user = cf.get(
"Mysql-Database",
"user")
-
self.passwd = cf.get(
"Mysql-Database",
"passwd")
-
self.db = cf.get(
"Mysql-Database",
"db")
-
self.charset = cf.get(
"Mysql-Database",
"charset")
-
self.syn=cf.get(
"System",
"syn")
-
self.scans=cf.get(
"System",
"scans")
-
self.jgdyUrl=cf.get(
"Jgdy",
"fetchUrl")
获取数据相关代码
-
import json
-
import uuid
-
-
-
import pymysql
-
import requests
-
from prettytable import PrettyTable
-
-
-
from src.NewTun.Connection import Connection
-
-
-
class JgdyQuery:
-
-
-
connection = None
-
cursor = None
-
#解析数据
-
def __init__(self):
-
self.connection = Connection()
-
-
-
#解析数据
-
def printJgdyInfo(self,code,page):
-
url =
self.connection.jgdyUrl
-
url=url.format(code,page,
10,page)
-
datas =
self.get_url(url)
-
-
-
# 取出json
-
datas = datas[datas.find(
'{')
:datas.find(
'}') +
3]
# 从出现第一个{开始,取到第三个花括号}
-
jsonBody = json.loads(datas)
-
jsonDatas = jsonBody[
'Data']
-
realData=jsonDatas[
0]
-
splitStr=realData[
"SplitSymbol"]
-
FieldName=realData[
"FieldName"]
-
FieldNames=FieldName.split(
',')
-
myData=realData[
'Data']
-
fundsArray=[]
-
for data
in
myData:
-
fundsArray = data.split(splitStr)
-
self.save2DB(fundsArray)
-
-
-
#获取数据
-
def get_url(self, url, params=None, proxies=None):
-
rsp = requests.get(url, params=params, proxies=proxies)
-
rsp.raise_for_status()
-
return rsp.text
-
-
-
def save2DB(self,item):
-
connect = pymysql.Connect(
-
host=
self.connection.host,
-
port=
self.connection.port,
-
user=
self.connection.user,
-
passwd=
self.connection.passwd,
-
db=
self.connection.db,
-
charset=
self.connection.charset
-
)
-
cursor=connect.cursor()
-
#去重
-
sql =
"select * from ajgdy where CompanyCode='%s' and Licostaff='%s' and NoticeDate='%s'"
-
data = (item[
0], item[
15],item[
7])
-
cursor.execute(sql % data)
-
if len(list(cursor)) ==
0:
-
#入库
-
sql =
"INSERT INTO ajgdy (id, CompanyCode,CompanyName,OrgCode,OrgName,OrgSum,SCode,SName,NoticeDate,StartDate,EndDate,Place,Description,Orgtype,OrgtypeName,Personnel,Licostaff,Maincontent,ChangePercent,Close) " \
-
"VALUES ( '%s', '%s','%s', '%s','%s', '%s', '%s','%s', '%s','%s','%s', '%s','%s', '%s','%s', '%s', '%s','%s', '%s','%s')"
-
data = (uuid.uuid1(), item[
0], item[
1], item[
2], item[
3], item[
4], item[
5], item[
6], item[
7],item[
8], item[
9], item[
10], item[
11],item[
12], item[
13], item[
14], item[
15],item[
16], item[
17], item[
18])
-
cursor.execute(sql % data)
-
connect.commit()
-
-
-
# tianjl = JgdyQuery()
-
# tianjl.printJgdyInfo("300232",1)
如下图所示为作者拉取部分上市公司的机构调研数据的结果。
转载:https://blog.csdn.net/tianjingle_blog/article/details/112792966
查看评论