# 股票量化分析（二）PE和流通市值

### 一、分析

#### 1、动静分析

stock中有很多指标，比如市盈率（PE）、流通市值、委比、量比、换手率、获利比率、财物指标等等。其中一部分属于短期内变化不大的指标，如PE、流通市值。所以这类参数，我们可以将这类参数看为静态参数，可以一到一周其一次值的数据。像时时变化的委比、量比、换手率等为动态数据，这部分需要时时刷新的。

#### 2、参数信息

一般来说，市盈率水平为：
0-13-即价值被低估
14-20-即正常水平
21-28-即价值被高估
28+-反映股市出现投机性泡沫

<br />


#### 3、选取采集源

<a href="https://www.361way.com/wp-content/uploads/2015/06/stockid.png"><img src="https://www.361way.com/wp-content/uploads/2015/06/stockid-300x128.png" alt="stockid" width="300" height="128" class="alignnone size-medium wp-image-4604" /></a>


json中的键值对应关系为：

2034120:市盈率
3475914:流通市值 以元为单位，需除以（/1000/1000/100）得到亿元单位
10:当前价
461256:委比
1968584:换手率
<br />


### 二、采集分析

[root@361way stock]# more get_pe.py
#!/usr/bin/python
#coding=utf-8
# code by 运维之路（www.361way.com）
# 1、pe在 0~20 之间的企业
# 2、流通股本小于50亿的企业
import urllib2
import time
import json
def get_pe(stockid):
try:
'Host':'d.10jqka.com.cn',
'Referer':'http://stock.10jqka.com.cn/',
'Accept':'application/json, text/javascript, */*; q=0.01',
'Connection':'keep-alive',
'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36',
'X-Forwarded-For':'124.160.148.178',
'X-Requested-With':'XMLHttpRequest'
}
f = urllib2.urlopen(req)
data = data.split('})',1)[0]
#J_data = json.dumps(data,indent=4,encoding='utf-8')
stockpe = J_data['2034120']
stockname = J_data['name']
sumvalue = J_data['3475914']
currentprice = J_data['10']
#print stockid,stockname,stockpe
return stockname,stockpe,sumvalue,currentprice
except urllib2.HTTPError, e:
#return stockid ,'get happed httperror'
return e.code
if __name__ == '__main__':
print 'stockid  stockname  currentprice  stockpe  Billvalue'
stockids = [line.strip() for line in open("stock_exp.txt", 'r')]
for stockid in stockids:
try:
stockname,stockpe,sumvalue,currentprice = get_pe(stockid)
if sumvalue:
Billvalue = round(float(sumvalue)/1000/1000/100)
else:
Billvalue = 0
if stockpe:
if float(stockpe) > 0 and float(stockpe) < 20 and Billvalue < 50 :
print stockid,stockname,currentprice,stockpe,Billvalue
#else:
#   print stockid
except TypeError ,e:
print stockid ,'get is error'
<br />


<a href="https://www.361way.com/wp-content/uploads/2015/06/stock_result.png"><img src="https://www.361way.com/wp-content/uploads/2015/06/stock_result.png" alt="stock_result" width="425" height="107" class="alignnone size-full wp-image-4605" /></a>