tushare id:463640
import pandas as pd
import tushare as ts
import datetime
# 获取今天(现在时间)
today = datetime.datetime.today()
yesterday = today - datetime.timedelta(days=1)
# 昨天
day_yes = 10000 * yesterday.year + 100 * yesterday.month + yesterday.day
# 上月
month_yes = 10000 * yesterday.year + 100 * (yesterday.month-1) + yesterday.day
# 去年昨天
year_yes = 10000 * (yesterday.year-1) + 100 * yesterday.month + yesterday.day
# 数据接口//***填Tushare接口token
pro = ts.pro_api('***')
#
df = pro.daily_info(start_date=str(year_yes),end_date=str(day_yes),ts_code = 'SH_MARKET,SZ_MARKET')
amount_df = pd.DataFrame(df.groupby('trade_date')['amount'].sum())
amount_df = amount_df.apply(lambda x:round(x,2))
# 年图
import pyecharts.options as opts
from pyecharts.charts import Line,Grid,Page
l1 = (
Line(init_opts=opts.InitOpts(width="1500px", height="360px"))
.add_xaxis(xaxis_data=[datetime.datetime.strptime(x, "%Y%m%d").strftime('%Y-%m-%d') for x in amount_df.index.tolist()])
.add_yaxis(
series_name="成交金额(亿元)",
y_axis=amount_df['amount'].tolist(),
label_opts=opts.LabelOpts(is_show=False),
linestyle_opts=opts.LineStyleOpts(width=1.5),
is_smooth=True
)
.set_global_opts(
title_opts=opts.TitleOpts(
title="中国股市近一年每日成交金额",
pos_left="center",
pos_top="top",
),
tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"),
legend_opts=opts.LegendOpts(is_show=False),
datazoom_opts=[
opts.DataZoomOpts(range_start=0, range_end=100),
opts.DataZoomOpts(type_="inside", range_start=0, range_end=100),
],
xaxis_opts=opts.AxisOpts(type_="category", boundary_gap=False),
yaxis_opts=opts.AxisOpts(name="成交金额(亿元)", type_="value", min_=5000,max_=20000),
)
.set_series_opts(
markline_opts=opts.MarkLineOpts(
data=[
{"yAxis": 10000},
],
label_opts=opts.LabelOpts(position="end"),
)
)
.render("中国股市每日成交金额统计.html")
)
import webbrowser
webbrowser.open_new_tab('中国股市每日成交金额统计.html')