简 介:
此桌面小程序主要是通过请求基金接口,获得对应的基金情况,并通过基金投资公式计算出最终份额和收益,并用可视化图形直观展示.
关键词: python, tikinter, gui, matplotlib, 桌面程序
————————————————
成品图:
剖析:
此次任务可以拆解为以下三部分.
一.GUI图形界面
二.数据来源
三.可视化图表
其中第一部分可以分成:1.输入,2.输出
第二部分可以分成:1.请求数据,2.处理数据
第三部分可以分成:1.读取数据, 2.展示数据
因此:
我们先从基础数据获取来下手, 股票,基金的获取途径还是很多的,本次直接用比较好用的
tushare库可以直接拿到数据.
def calc():
global df
#获得数据,传入基金代码 开始时间 结束时间
#返回的是df数据
df = ts.get_k_data(code.get(), start=start.get(), end=end.get())
df=df.reset_index()
df['amount'] = .0
df['profit'] = .0
piece = float(amount.get())
last = None
for i, row in df.iterrows():
df.loc[i, 'amount'] = piece / df.loc[i, 'close']
if last is not None:
df.loc[i, 'amount'] += last['amount']
df.loc[i, 'profit'] = df.loc[i, 'amount'] * df.loc[i, 'close'] - piece * i
last = df.loc[i]
UI布局
def ui():
global res
n=0
m=len(df)-1
row13 = Label(root, text="Open")
row13.place(x=180, y=10)
row14 = Entry(root,width=10)
row14.place(x=225, y=10)
row14.insert(0, df['open'][n])
row14.update()
row15 = Label(root, text="High")
row15.place(x=275,y=10)
row16 = Entry(root,width=10)
row16.place(x=318,y=10)
row16.insert(0,df['high'][n])
row16.update()
row17 = Label(root, text="Low")
row17.place(x=375,y=10)
row18 = Entry(root,width=10)
row18.place(x=412,y=10)
row18.insert(0,df['low'][n])
row18.update()
row19 = Label(root, text="Volume")
row19.place(x=470,y=10)
row110 = Entry(root,width=10)
row110.place(x=528,y=10)
row110.insert(0,df['volume'][n])
row110.update()
row23 = Label(root, text="Open")
row23.place(x=180,y=40)
row24 = Entry(root,width=10)
row24.place(x=225,y=40)
row24.insert(0,df['open'][m])
row24.update()
row25 = Label(root, text="High")
row25.place(x=275,y=40)
row26 = Entry(root,width=10)
row26.place(x=318,y=40)
row26.insert(0,df['high'][m])
row26.update()
row27 = Label(root, text="Low")
row27.place(x=375,y=40)
row28 = Entry(root,width=10)
row28.place(x=412,y=40)
row28.insert(0,df['low'][m])
row28.update()
row29 = Label(root, text="Volume")
row29.place(x=470,y=40)
row210 = Entry(root,width=10)
row210.place(x=528,y=40)
row210.insert(0,df['volume'][m])
row210.update()
res = []
for i in range(len(df)):
res.append({
'开盘日期': df['date'][i],
'利润': (df['close'][i] - df['open'][i])*100,
'收盘价格': df['close'][i],
})
res = pd.DataFrame(res)
lirun = res['利润'].tolist()
total = []
for i in range(len(lirun)):
total.append(sum(lirun[:i]))
res['总利润'] = total
可视化:
def draw_plt():
plt.rcParams['font.sans-serif'] = ['SimHei'] # 显示中文标签
plt.rcParams['axes.unicode_minus'] = False
calc()
fig.clear() #画布是有清空的功能
plt.subplot(211)
plt.title('收盘价曲线图', size=10)
plt.plot(df['date'], df['profit'])
plt.gca().xaxis.set_major_locator(ticker.MultipleLocator(30))
plt.xticks(rotation=30)
plt.subplot(212)
plt.subplots_adjust(wspace=0, hspace=1)
plt.title('净利润曲线图', size=10)
plt.plot(res['开盘日期'], res['收盘价格'])
plt.gca().xaxis.set_major_locator(ticker.MultipleLocator(30))
plt.xticks(rotation=30)
canvas1.draw()
另:本工作室长期接单,放单。涉及领域有python java 前后端 机器学习 网站 系统 app 小程序等。
需要接单加v备注技术领域:ad2021wyz 或q 进接单群的加 2234590550 备注清楚领域
需要源码和代做需求的加v备注客户:ad2020wyz