程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[quantitative investment system Python] mplfinance drawing K-line diagram 4

編輯:Python

The first three times have been improved and explored step by step , Used on the final system presentation K The line chart must conform to the habits of China's securities trading , Red means up , Green means falling .

In the final system implementation, it is called in the form of function .
Function as follows

#path Is the path of the data ,K Represents the last stored file name 
def Drawmpf1(path,k):
# Data processing 
df= pd.read_csv(path)
df.columns = ['Date','Open','Close','High', 'Low','Volume',"Money"]
df.head()
df =df.set_index(["Date"])
df.index = pd.DatetimeIndex(df.index)# Multiple indexes can be directly operated 
open1=df['Open']
high2=df['High']
low3=df['Low']
close4=df['Close']
volume5=df['Volume']
money6=df['Money']
data=pd.concat([open1,high2,low3,close4,volume5,money6],keys=['Open', 'High','Low' ,'Close','Volume',"Money"],axis=1)
# Image rendering 
apds = [mpf.make_addplot((df["Money"][-120:-1]),panel='lower',color='b',linestyle='dotted')]
save = dict(fname=k+".jpg",dpi=120,pad_inches=0)
# Red up , Green down 
mc = mpf.make_marketcolors(up='r',down='g',edge='inherit',
wick={
'up':'r','down':'g'},
volume='cornflowerblue',
ohlc='i'
)
s = mpf.make_mpf_style(marketcolors=mc)
mpf.plot(data.iloc[-120:-1],addplot=apds,figscale=1,mav=(5,10,20),volume=True,figratio=(17,7),type='candle', style=s,savefig=save)
# 

Call function

1. Call directly

Drawmpf1(path,'SAVE')

The pictures will be stored in the corresponding directory .

2. Cycle call
Process multiple files at once

# Folder Directory 
l=["ETF/"]
for i in l:
for k in os.listdir(i):
path=i+k
# Output corresponding path 
print(path)
Drawmpf2(path,k)

Use mplfinance draw K End of line diagram , It is really simple and convenient to compare with the previous ones .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved