07-26-2018, 07:30 PM
Predicting stock market direction is interesting area of many researchers and traders. We can predict candlestick direction by some features with Random Forest algorithm. The key of success here is applying Exponential Smoothing to our features. Exponential Smoothing applies more weightage to the recent observation and exponentially decreasing weights to past observations.
Features we used:
The above features are can be calculated easily in Python with ta_lib library.
So we used these features:
RSI(14), MACD(12,26,9) , Williams(14), %K of Stochastic(14) , OBV, PROC
This method has accuracy of about 90%.
Features we used:
Code:
Relative Strength Index (RSI)
RSI = 100 - 100/(1+RS)
RS = Average Gain Over past 14 days / Average Loss Over past 14 days
RSI is a momentum indicator which determines the stock is overbought or oversold.
Code:
Stochastic Oscillator
%K = 100 * (C - L14)/(H14 - L14)
C = Current Closing Price
L14 = Lowest Low over the past 14 days
H14 = Highest High over the past 14 days
Stochastic follows of speed or the momentum of the price.
Code:
Williams %R
%R = (H14 - C) / (H14 - L14) * -100
Values are between -100 and 0.
Code:
Moving Average Convergence Divergence
MACD = EMA12(C) - EMA26(C)
Signal Line = EMA9 * MACD
EMAn = n day Exponential Moving Average
Code:
Price Rate Of Change:
PROC (t) = (C(t) - C(t-n) )/ C(t-n)
Code:
On Balance Volume:
If C(t) > C(t - 1) => OBV = OBV(t-1) + Vol(t)
If C(t) < C(t-1) = > OBV = OBV(t-1) - Vol(t)
If C(t) = C(t-1)
Code:
Or target (Y) is Sign(Close (t+d) - close (t))
The above features are can be calculated easily in Python with ta_lib library.
So we used these features:
RSI(14), MACD(12,26,9) , Williams(14), %K of Stochastic(14) , OBV, PROC
This method has accuracy of about 90%.