Welcome to Francis Academic Press

Academic Journal of Computing & Information Science, 2024, 7(6); doi: 10.25236/AJCIS.2024.070606.

Improved KNN-based Stock Price Prediction


Yiwen Wang1, Yuchen Xie2, Yuhao Wu3, Yichen Yang4

Corresponding Author:
Yiwen Wang

1Jilin Provincial Experimental School, Changchun, Jilin, China

2Maranatha Christian Academy, Windsor, Ontario, Canada

3Golden Sun Experimental High School, Nanchang, Jiangxi, China

4HD Beijing School, Beijing, China


Accurate prediction of stock prices is of great significance as it provides critical information for investors, financial institutions, and government policymakers to manage risks, optimize investment portfolios, and formulate sound capital operation strategies. Addressing the challenges in stock price prediction, this paper proposes a novel stock price prediction model based on the K-Nearest Neighbors (KNN) algorithm. The model leverages the core idea of the KNN algorithm by identifying the nearest neighbor data samples to predict future trends in stock prices. Unlike traditional KNN approaches, the proposed model integrates an improved strategy incorporating the price change trends of the preceding N days in time-series data to forecast the price change of the subsequent day more accurately. Experimental results demonstrate that the proposed improved KNN model enhances the accuracy of stock price prediction. This model provides more reliable forecasting information for investors and financial institutions, assisting them in making wiser investment decisions and reducing investment risks. Additionally, this model offers valuable insights for government agencies in formulating monetary policies and risk management, thereby promoting economic stability and capital market development.


Machine Learning, Stock Price Prediction, KNN

Cite This Paper

Yiwen Wang, Yuchen Xie, Yuhao Wu, Yichen Yang. Improved KNN-based Stock Price Prediction. Academic Journal of Computing & Information Science (2024), Vol. 7, Issue 6: 38-43. https://doi.org/10.25236/AJCIS.2024.070606.


[1] Peiqi Zhang, Navy Liu, Dongxiao Pei, Xiyue Wang. Stock price prediction based on SVM-KNN. Statistics and Applications, 08.6(2019):859-871..

[2] Bo Wang, and Fuyun Cheng. Application of KNN algorithm in stock prediction. Technology Entrepreneurship Monthly, 28.16(2015):2.

[3] Li Tang, Heping Pan, Yiyong Yao. A prediction model based on nonlinear feature extraction and weighted K nearest neighbour meta-regression. Journal of Information Systems, 2(2019):10. 

[4] Wei-Nan Zhang, Uni-Yu Lu, & Jian-Ming Sun. K-nearest neighbour and its integrated model for stock price prediction. Electronic Technology Applications, 45.5(2019):6. 

[5] Xiaoying Liu. Research on stock price trend prediction based on KNN method. Heilongjiang: Northeast Agricultural University, 2015. 

[6] Tong Yang. A stock ranking method based on machine learning. Tianjin University of Technology, 2017. 

[7] Alkhatib, Khalid, et al. "Stock price prediction using k-nearest neighbor (kNN) algorithm." International Journal of Business, Humanities and Technology 3.3 (2013): 32-44.

[8] Latha, R. S., Sreekanth, G. R., Suganthe, R. C., Geetha, M., Selvaraj, R. E., Balaji, S., ... & Ponnusamy, P. P. Stock Movement Prediction using KNN Machine Learning Algorithm, 2022 International Conference on Computer Communication and Informatics (ICCCI), IEEE, (2022), pp. 1-5.

[9] Yunneng, Qian, A new stock price prediction model based on improved KNN, 2020 7th International Conference on Information Science and Control Engineering (ICISCE), IEEE, (2020), pp. 77-80.

[10] Sarala, V., and GNV PHANI BHUSHAN. "Stock Market Trend Prediction Using K-Nearest Neighbor (KNN) Algorithm." J. Eng. Sci. 13.8 (2022): 249-256.