from tkinter import *
import akshare as ak
import matplotlib.pyplot as plt
def find(n):
fund_em_info_df = ak.fund_em_open_fund_info(fund=n, indicator="单位净值走势")
return fund_em_info_df
def take(fund_em_info_df):
dp1=fund_em_info_df["单位净值"]
dp2=fund_em_info_df["净值日期"]
data1=dp1.tolist()
data2=dp2.tolist()
kdata=data1[:-100:-1][::-1]
ddate=data2[:-100:-1][::-1]
for x in range(len(ddate)):
ddate[x]=ddate[x].strftime('%Y-%m-%d')
pass
dict_now=dict(zip(ddate,kdata))
l=[]
for key,value in dict_now.items():
s="%s:%s"%(key,value)
l.append(s)
ss="|".join(l)
return ss,kdata
def write(ss):
with open("C:\\Users\\史莱克\\PycharmProjects\\数据\\量化交易数据.txt","w") as pd:
pd.write(ss)
def draw(kdata):
max_k=max(kdata)
max_k=[max_k]*len(kdata)
min_k=min(kdata)
min_k=[min_k]*len(kdata)
mean_k=sum(kdata)/len(kdata)
mean_k=[mean_k]*len(kdata)
plt.figure(figsize=(8,6),dpi=80)
plt.plot(range(len(kdata)),kdata,color='b')
plt.plot(range(len(kdata)),mean_k,color='r',linestyle='--')
plt.plot(range(len(kdata)),max_k)
plt.plot(range(len(kdata)),min_k)
plt.savefig("C:\\Users\\史莱克\\PycharmProjects\\数据\\量化数据交易.jpg")
plt.ylabel("量化交易")
plt.show()
def main(n):
a,b=take(find(n))
write(a)
draw(b)
if __name__ == '__main__':
def display():
n = my_entry.get()
main(n)
root.destroy()
def quit_window():
root.destroy()
sys.exit()
root = Tk()
root.geometry('300x300')
my_label = Label(root, text="fund")
my_label.pack(pady=10)
my_entry = Entry(root)
my_entry.pack(pady=20)
my_button = Button(root, text="查询", command=display, width=10)
my_button.pack(pady=10)
my_button2 = Button(root, text="退出", command=quit_window, width=10)
my_button2.pack(pady=10)
root.mainloop()
调用akshare获取基金数据
于 2021-09-20 15:34:17 首次发布