siat 2.0.19__py3-none-any.whl → 2.1.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
siat/grafix.py CHANGED
@@ -911,7 +911,7 @@ def plot_line2_twinx2(df01,ticker1,colname1,label1, \
911
911
 
912
912
  #==============================================================================
913
913
  def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
914
- data_label=True,resample_freq='H',smooth=True,linewidth=1.5,loc='best'):
914
+ data_label=True,resample_freq='H',smooth=True,linewidth=1.5,loc='best',annotate=False):
915
915
  """
916
916
  函数功能:根据df的内容绘制折线图
917
917
  输入参数:
@@ -974,7 +974,17 @@ def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
974
974
  continue
975
975
 
976
976
  #plt.plot(dfg,label=c,linewidth=linewidth,ls=lsc,marker=mkc,markersize=3)
977
- plt.plot(dfg,label=codetranslate(c),linewidth=linewidth,ls=lsc,marker=mkc,markersize=3)
977
+ if not annotate:
978
+ plt.plot(dfg,label=codetranslate(c),linewidth=linewidth,ls=lsc,marker=mkc,markersize=3)
979
+ else:
980
+ plt.plot(dfg[c],label=codetranslate(c),linewidth=linewidth,ls=lsc,marker=mkc,markersize=3)
981
+ df_end=dfg.tail(1)
982
+ y_end = round(df_end[c].min(),2) # 末端的y坐标
983
+ x_end = df_end[c].idxmin() # 末端值的x坐标
984
+ plt.annotate(text=codetranslate(c)+':'+str(y_end),
985
+ xy=(x_end, y_end),
986
+ xytext=(x_end, y_end),fontsize=9)
987
+
978
988
  #plt.plot(df[c],label=c,linewidth=1.5,marker=mkc,markersize=3)
979
989
  #为折线加数据标签
980
990
  if data_label==True:
siat/stock.py CHANGED
@@ -1237,7 +1237,8 @@ def compare_msecurity(tickers,measure,start,end, \
1237
1237
  axhline_value=0,axhline_label='', \
1238
1238
  preprocess='none',linewidth=1.5, \
1239
1239
  scaling_option='start', \
1240
- graph=True,loc='best'):
1240
+ graph=True,loc='best', \
1241
+ annotate=False):
1241
1242
  """
1242
1243
  功能:比较并绘制多条证券指标曲线(多于2条),个数可为双数或单数
1243
1244
  注意:
@@ -1496,9 +1497,10 @@ def compare_msecurity(tickers,measure,start,end, \
1496
1497
  axhline_label='收益零线'
1497
1498
 
1498
1499
  draw_lines(dfs2,y_label,x_label,axhline_value,axhline_label,title_txt, \
1499
- data_label=False,resample_freq='H',smooth=True,linewidth=linewidth,loc=loc)
1500
+ data_label=False,resample_freq='H',smooth=True,linewidth=linewidth,loc=loc, \
1501
+ annotate=annotate)
1500
1502
 
1501
- return dfs
1503
+ return dfs2
1502
1504
 
1503
1505
  if __name__ =="__main__":
1504
1506
  tickers=['000001.SS',"^HSI","^TWII"]
@@ -1589,7 +1591,7 @@ if __name__ =="__main__":
1589
1591
  df=compare_msecurity(tickers2,measure1,start,end)
1590
1592
  df=compare_msecurity(tickers2,measure2,start,end)
1591
1593
  #==============================================================================
1592
- def candlestick(stkcd,fromdate,todate,volume=True,style='China',mav=[5,20]):
1594
+ def candlestick(stkcd,fromdate,todate,volume=True,style='China',mav=[5,10]):
1593
1595
  """
1594
1596
  功能:绘制证券价格K线图。
1595
1597
  输入:证券代码ticker;开始日期fromdate,结束日期todate;
@@ -1687,17 +1689,32 @@ def candlestick(stkcd,fromdate,todate,volume=True,style='China',mav=[5,20]):
1687
1689
  figratio=(12.8,7.2)
1688
1690
  )
1689
1691
  """
1690
- mpf.plot(daily,type='candle',
1692
+ fig, axlist = mpf.plot(daily,type='candle',
1691
1693
  volume=volume,
1694
+ show_nontrading=False,#自动剔除非交易日空白
1692
1695
  style=s,
1693
- title=titletxt,
1696
+ #title=titletxt,
1694
1697
  datetime_format='%Y-%m-%d',
1695
1698
  tight_layout=True,
1699
+ #tight_layout=False,
1696
1700
  xrotation=15,
1697
1701
  ylabel=texttranslate(ylabel_txt),
1698
1702
  ylabel_lower=texttranslate(ylabel_lower_txt),
1699
1703
  mav=mav,
1700
- figratio=(12.8,7.2))
1704
+ figratio=(12.8,7.2),
1705
+ #figscale=1.5,
1706
+ returnfig=True
1707
+ )
1708
+
1709
+ # add a title the the correct axes, 0=first subfigure
1710
+ titletxt=titletxt+":K线图走势,日移动均线="+str(mav)
1711
+ axlist[0].set_title(titletxt,
1712
+ fontsize=16,
1713
+ #style='italic',
1714
+ #fontfamily='fantasy',
1715
+ loc='center')
1716
+
1717
+ fig.show()
1701
1718
 
1702
1719
  reset_plt()
1703
1720
 
@@ -1767,6 +1784,13 @@ if __name__ =="__main__":
1767
1784
  line=False
1768
1785
  price=candlestick_pro("000002.SZ","2020-2-1","2020-2-29")
1769
1786
  #==============================================================================
1787
+ if __name__ =="__main__":
1788
+ stkcd='BABA'
1789
+ fromdate='2023-6-5'
1790
+ todate='2023-6-9'
1791
+
1792
+ colorup='red';colordown='green';width=0.7
1793
+
1770
1794
  def candlestick_demo(stkcd,fromdate,todate,colorup='red',colordown='green',width=0.7):
1771
1795
  """
1772
1796
  功能:绘制证券价格K线图,叠加收盘价。
@@ -1780,7 +1804,9 @@ def candlestick_demo(stkcd,fromdate,todate,colorup='red',colordown='green',width
1780
1804
  if p is None:
1781
1805
  print(" #Error(candlestick_demo): failed to get price info of",stkcd,fromdate,todate)
1782
1806
  return
1783
-
1807
+
1808
+ p['Date']=p.index
1809
+
1784
1810
  import numpy as np
1785
1811
  b= np.array(p.reset_index()[['Date','Open','High','Low','Close']])
1786
1812
 
@@ -1831,7 +1857,7 @@ def candlestick_demo(stkcd,fromdate,todate,colorup='red',colordown='green',width
1831
1857
  price_txt='Price'
1832
1858
  source_txt="Source: "
1833
1859
  else:
1834
- titletxt=texttranslate("证券价格走势蜡烛图演示:")+codetranslate(str(stkcd))
1860
+ titletxt=texttranslate("K线图/蜡烛图演示:")+codetranslate(str(stkcd))
1835
1861
  price_txt='价格'
1836
1862
  source_txt="数据来源: "
1837
1863