市赢率,市净率折线图
获取财务数据¶
from jqdata import finance
import matplotlib.pyplot as plt
from matplotlib import gridspec
import pandas as pd
from datetime import datetime
def draw_pe_pb(stock,start_year):
q = query(
valuation
).filter(
valuation.code == stock
)
now = datetime.today().date()
df = pd.DataFrame()
for y in range(start_year,now.year+1):
for quater in range(1,5):
df = df.append(get_fundamentals(q, statDate = "{}q{}".format(y,quater)))
df['day'] = pd.to_datetime(df['day'])
df.index = df.day
fig = plt.gcf()
fig.set_size_inches(10.5, 10.5)
gs = gridspec.GridSpec(3, 1,
height_ratios=[2,4,4]
)
ax0 = plt.subplot(gs[1],facecolor='white',ylabel=u"市净率",label="PB")
ax1 = ax0.twinx() # this is the important function
ax1.set_ylabel(u"市赢率")
ax0.plot(df.index,df.pb_ratio,'r',label=u'市净率')
ax1.plot(df.index,df.pe_ratio,'b',label = u'市赢率')
ax0.legend(loc="upper left")
ax1.legend(loc='upper right')
ax0.set_title(stock)
stock = '000001.XSHE'
draw_pe_pb(stock,2010)