close

主要是參考"IT邦幫忙鐵人賽"的文章

網址 : https://ithelp.ithome.com.tw/articles/10206894

先利用之前的文章, 抓個2017-01-01到2018-01-01的資料

擷取.PNG

import talib
import pandas as pd
stock_file = pd.read_csv(r'D:\0050.TW.csv')
df['Date'] = pd.to_datetime(df['Date'])

df.set_index("Date", inplace=True)

print(df.head(5))

擷取.PNG

import matplotlib.pyplot as plt
df["Close"].plot(color='red')
plt.title('0050')
plt.grid(True)
plt.show()

擷取.PNG

import numpy as np
K,D = talib.STOCH(high = np.array(df['High']), 
                low = np.array(df['Low']), 
                close = np.array(df['Close']),
                fastk_period=9,
                slowk_period=3,
                slowk_matype=0,
                slowd_period=3,
                slowd_matype=0)

擷取.PNG

import mpl_finance as mpf
%matplotlib inline

fig = plt.figure(figsize=(24, 20))
ax = fig.add_axes([0,0.3,1,0.4])
ax2 = fig.add_axes([0,0.2,1,0.1])

ax.set_xticks(range(0, len(df.index), 10))
ax.set_xticklabels(df.index[::10])
mpf.candlestick2_ochl(ax, df['Open'], df['Close'], df['High'],
                      df['Low'], width=0.6, colorup='r', colordown='g', alpha=0.75)

ax2.plot(K, label='K值')
ax2.plot(D, label='D值')
ax2.set_xticks(range(0, len(df.index), 10))
ax2.set_xticklabels(df.index[::10])

下載.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

arrow
arrow
    全站熱搜

    張郎屋 發表在 痞客邦 留言(0) 人氣()