Description

Stock punters have many tips for ignorant stock newbie. Some say using Closing Price as an indication of NEXT up or down. Here I will prove that using Closing Price is not a reliable indicator.

Source of Data

I downloaded both STI and NOL Closing prices from year 2000 to year 2015. Only the STI column “Increase” is manually computed. That is TRUE(1) if today’s price is higher than yesterday’s price and FALSE(0) if today’s price is lower than yesterday’s price.

Yahoo Historical

Column “Adjusted Close” - Close price adjusted for dividends and splits

## Source: local data frame [5 x 8]
## 
##         Date    Open    High     Low   Close STI_CLOSE Increase NOL_CLOSE
##       (time)   (dbl)   (dbl)   (dbl)   (dbl)     (dbl)    (dbl)     (dbl)
## 1 2000-01-03 2502.28 2582.94 2502.28 2582.94   2582.94        1     2.089
## 2 2000-01-04 2580.50 2580.50 2520.80 2530.15   2530.15        0     2.022
## 3 2000-01-05 2481.73 2481.73 2373.67 2391.03   2391.03        0     1.918
## 4 2000-01-06 2404.79 2427.97 2318.17 2359.21   2359.21        0     1.908
## 5 2000-01-07 2358.33 2406.04 2349.48 2406.04   2406.04        1     2.089

Algorithm : k-Nearest Neighbour Classification

Many algorithm exists - i chose the simplest one.

prediction <- knn(predictors[stocksTrain, ], predictors[!stocksTrain, ], stocks$Increase[stocksTrain], k = 1)

We can see it’s accuracy using table

table(prediction, stocks$Increase[!stocksTrain])
##           
## prediction   0   1
##          0  93  86
##          1 149 149

And we can measure it’s accuracy as follows

mean(prediction == stocks$Increase[!stocksTrain])
## [1] 0.5073375

This is only marginally better than random guessing (50%). Let’s see if we can get a better accuracy by changing the value of k. We can use a for loop to see how the algorithm performs for different values of k.

Conclusion

As we can see, the model has the highest accuracy of ~ 50% when k = 4. While this may not seem any good, it is often extremely hard to predict the price of stocks. Ater all, if it was that easy to predict the prices, wouldn’t we all be trading in stocks for the easy money instead of learning these algorithms?

Therefore using Stock Price as an indicator of next UP or DOWN has only an accuracy of 50%. It is proven that using Closing Price alone is no good predictor of whether the next day market is up or down.

So stop looking at timeline charts and attempt to make a contra out of it. Rather spend time understanding the company ratio will be a better option.

End