tushare 股票数据获取,收益率计算,直方图绘制

# hanbb
# come on!!!
import tushare as ts
import matplotlib.pyplot as plt

# 股票数据获取
data = ts.get_hist_data('000001',start='2015-06-23',end='2017-11-16')

# 收益率计算
data['returns'] = (data['close']-data['close'].shift(1))/data['close'].shift(1)

returns = data["returns"].values
returns_list = returns.tolist()  # 将array 转化为lsit
returns_list = returns_list[1:]  # 舍去空值

# 绘制直方图
plt.hist(returns_list)
plt.show()

 

posted @ 2017-12-12 21:05  hbb360  阅读(1847)  评论(0编辑  收藏  举报