准备环境
import pandas as pd
import numpy as np
import datetime
from WindPy import w
w.start()
在lst_mkt里设置需要观测的指数wind代码,可以自由添加数量
lst_mkt = "000300.SH,000016.SH,000010.SH,399330.SZ,399005.SZ,399006.SZ"
mkt_n = w.wss(lst_mkt, "sec_name").Data[0]
index_m=lst_mkt.split(",")
mkt_n = pd.Series(mkt_n,index = index_m)
设置好日期,默认为报表生成日(可手动改日期啦)
自动生成前一交易日td和上一周最后交易日tw
t=datetime.datetime.now().date()
# t=datetime.date(2020,3,11)
def SetTime(T0):
weekday = t.weekday()
t_w = T0 - datetime.timedelta(weekday+3)
if weekday == 0:
t_d = t_w
else:
t_d = T0 - datetime.timedelta(1)
return t_d, t_w
td,tw = SetTime(t)
手动输入上一年【低频修改就不写公式了】
ty=datetime.date(2019,12,31)
# print(t,tw,td)
取得市场数据并计算、排版
err,mkt=w.wsd(lst_mkt, "close",ty ,t ,"",usedf=True)
# mkt.head()
mkt = mkt.T
col_1 = round(mkt[t],2)
col_2 = round((mkt[t]/mkt[td]-1)*100,2)
col_3 = round((mkt[t]/mkt[tw]-1)*100,2)
col_4 = round((mkt[t]/mkt[ty]-1)*100,2)
mkt_table = {"指数":mkt_n,"收盘价":col_1,"日涨幅%":col_2,"周涨幅%":col_3,"年涨幅%":col_4}
mkt_table = pd.DataFrame(mkt_table)
mkt_table.columns.name = str(t)
mkt_table
输出结果如下表:
image.png
网友评论