股票市场投资很重要的一个指标:交易量。因此绘制出当日交易额分布。
相关链接:
python量化交易学习】从tushare获取交易数据,按1%的涨跌幅统计A股涨跌股票数量,并用pyecharts画出柱状图
import tushare as ts
import pandas as pd
from pyecharts.charts import Bar
from pyecharts import options as opts
# 初始化pro接口。使用自己的token
pro = ts.pro_api('d437118*********2')
tradedate = "20220315"
# 拉取数据
df = pro.daily(**{
"ts_code": "",
"trade_date": tradedate,
"start_date": "",
"end_date": "",
"offset": "",
"limit": ""
}, fields=[
"ts_code",
"trade_date",
"open",
"high",
"low",
"close",
"pre_close",
"change",
"pct_chg",
"vol",
"amount"
])
#按涨跌幅统计
bins =[ i*20000 for i in range(0,50)]
cuts = pd.cut(df['amount'], bins=bins)
tade_amount = df.groupby(cuts)['amount'].count().tolist()
#将数据转换为pyecharts需要的格式
x =[ i*2 for i in range(0,50)]
c = (
Bar()
.add_xaxis(x)
.add_yaxis("",tade_amount)
.set_global_opts(
xaxis_opts=opts.AxisOpts(name='千万元'),
yaxis_opts=opts.AxisOpts(name='股票数'),
title_opts=opts.TitleOpts(title=tradedate +'日交易额分布',pos_left='middle')
)
.render("交易额分布.html")
)
生成柱状图如下: