By decomposing the Stochastic Oscillator for the purpose of noise removal, we try to read the purchase from fluctuations in a longer cycle. The stock price of this ups and downs is clear to buy and sell without backtesting. 【reference】 ① [Introduction to system trading] I drew stc with python and played with it ♬ ② [Introduction to element decomposition] Arrange time series analysis methods in R and python ♬
・ Incorporate Decompose ・ What is the result?
The built-in is as follows The Lib to be used is as shown in Reference ②, and the duplicate code in Reference ① is omitted.
...
import matplotlib.pyplot as plt
...
import statsmodels.api as sm
from statsmodels.tsa.seasonal import STL
def...
The data acquisition is as follows, but define series = ... to prepare for Decompose.
stock = '6758.JP' #sony6758 Jal 9201 Sumitomo Mitsui Financial 8316 docomo 9437
start = dt.date(2020,1,1)
end = dt.date(2020,6,5)
df = pd.DataFrame(get_stock(stock, start, end))
series = df['Close']
print(series)
And finally Decompose. Plot the situation on the graph.
cycle, trend = sm.tsa.filters.hpfilter(series, 144)
fig, ax = plt.subplots(3,1)
ax[0].plot(series)
ax[0].set_title('close')
ax[1].plot(trend)
ax[1].set_title('Trend')
ax[2].plot(cycle)
ax[2].set_title('Cycle')
plt.savefig("./stock/close_%K%D_{}_now.png ".format(stock))
plt.pause(1)
plt.close()
The result is shown below, with the Trend data denoised. As a characteristic, the deviation Deviation from Observed Trend is also large when the stock price drops sharply. It can be said that the mullet is large.
df['Close']=trend
If you do this for High and Low, you will get the following graph. High, Low, Close can be seen separately. Then, with the same code as last time, calculate% K and% D with the data obtained in this way and draw it.
df['%K'] = STOK(df['Close'], df['Low'], df['High'], 14)
df['%D'] = STOD(df['Close'], df['Low'], df['High'], 14)
I got the graph to be very simple as below. With this, it seems that there are no mistakes in buying or selling. ** 6758 Sony; Overbuy risk area, risk area, so refrain from purchasing **
Everything has become simple! Obviously, it seems that you can buy and sell without making a mistake. ** 8316 Sumitomo Mitsui Financial; Over-raised area, selling scene soon? ** ** ** 9201 Japan Airlines; Risk area of over-raising, selling scene soon? ** ** ** 9437 NTT DoCoMo; Risk area of over-lowering, buying scene soon? ** **
・ I tried to remove noise from Stochastic Oscillator with the decompose function. ・ The graph has changed monotonously, making it easier to buy and sell.
・ Actually, let's apply ・ Let's apply it to short-term trading such as minute bars ・ Let's apply it automatically to all stocks and index the index at the time of buying and selling
On the contrary, short-term trading using daily ups and downs seems to be possible by using Deviation, so I tried it. When I tried it, it became as follows. This is fine, and it is doubtful that the High, Low, and Close values are really in that hierarchical relationship (it seems that it is not guaranteed because% K and% D exceed the range of 0-100). It's still worth a try, but it's not a guarantee that you're trading from the charts you get. Results of 6758 Results of 9437
Recommended Posts