# PythonStock（9）：使用优矿uqer.io 进行简单的数据分析

### 前言

https://github.com/pythonstock/stock

http://blog.csdn.net/freewebsys/article/category/7076584

### 1，研究股票数据

An Introduction to Stock Market Data Analysis with Python (Part 1)
https://ntguardian.wordpress.com/2016/09/19/introduction-stock-market-data-python-1/
An Introduction to Stock Market Data Analysis with Python (Part 2)
https://ntguardian.wordpress.com/2016/09/26/introduction-stock-market-data-python-2/

Python股市数据分析教程——学会它，或可以实现半“智能”炒股 (Part 1)
https://yq.aliyun.com/articles/66878
Python股市数据分析教程——学会它，或可以实现半“智能”炒股 (Part 2)
https://yq.aliyun.com/articles/66817

### 2，代码实现：

import pandas as pd
import pandas.io.data as web
import matplotlib.pyplot as plt
import datetime
import numpy as np

start = datetime.datetime(2016, 1, 1)
end = datetime.date.today() - datetime.timedelta(days=1)  # yesterday .

# IOError Traceback (most recent call last)
# apple = web.DataReader("AAPL", "yahoo", start, end)

# 以【平安银行】为例：
out_data = DataAPI.MktEqudGet(secID=u"000001.XSHE", beginDate=start, endDate=end, pandas="1")
print(start, end)

# openPrice float   今开盘
# highestPrice  float   最高价
# lowestPrice   float   最低价
# closePrice    float   今收盘
# turnoverVol   float   成交量
# turnoverValue float   成交金额
# dealAmount    int 成交笔数
# turnoverRate  float   日换手率
# 重新设置 index 和数据。
out_data = pd.DataFrame({
"openPrice": out_data["openPrice"].values,
"highestPrice": out_data["highestPrice"].values,
"lowestPrice": out_data["lowestPrice"].values,
"closePrice": out_data["closePrice"].values,
"turnoverVol": out_data["turnoverVol"].values,
"turnoverValue": out_data["turnoverValue"].values,
"dealAmount": out_data["dealAmount"].values,
"turnoverRate": out_data["turnoverRate"].values
},
index=out_data["tradeDate"].values)

print("####### len:", len(out_data))
figsiz_all = (18, 4)
# .subplots(1, 3, figsize=(9, 3), sharey=True) plt.figure()
out_data["closePrice"].plot(grid=True, figsize=figsiz_all, title="closePrice")

####################### 计算今日收盘价回归 #######################
plt.figure()  # 在新创建一个图表。
out_data["return"] = np.log(out_data["closePrice"] / out_data["closePrice"].shift(1))
# print(out_data.head())
out_data["return"].plot(grid=True, figsize=figsiz_all, title="closePrice return")

####################### 计算今日收盘价波动 #######################
out_data["25d"] = pd.rolling_mean(out_data["closePrice"], window=25)
out_data["50d"] = pd.rolling_mean(out_data["closePrice"], window=50)
print(out_data.head(n=2))
plt.figure()  # 在新创建一个图表。
out_data[["closePrice", "25d", "50d"]].plot(grid=True, figsize=figsiz_all, title="25d 50d")


https://uqer.io/data/browse/0/?page=1

out_data["return"] = np.log(out_data["closePrice"] / out_data["closePrice"].shift(1))

out_data["25d"] = pd.rolling_mean(out_data["closePrice"], window=25)
out_data["50d"] = pd.rolling_mean(out_data["closePrice"], window=50)

### 3，总结

pandas 处理股票数据，还是非常的方便的。