Skip to content
All library documents

Using K-Nearest Neighbors to Classify Next-Day Market Direction

Article QuantInsti blog

Summary

The document introduces K-nearest neighbors (KNN), a supervised learning method that classifies or estimates a new observation using nearby examples selected by a distance metric. For classification, neighboring labels determine the predicted class by majority vote. It outlines a trading workflow: prepare historical data, choose the neighbor count and distance measure, fit on training observations, and predict outcomes for new data.

Its example uses SPY daily data, with open-to-close and high-to-low measures as predictors and the following session's up or down direction as the target. It describes a chronological 70/30 training and test split and reports training accuracy of 0.63 and test accuracy of 0.45 for a 15-neighbor model. The gap cautions against reading training fit as predictive success. The article also notes sensitivity to feature scaling, computational cost, and memory use; it does not provide a robust out-of-sample study or account for transaction costs.

Key ideas

  • KNN predicts a class or value based on similarity to nearby training observations.
  • The choice of distance metric, neighbor count, data preparation, and feature scaling affects results.
  • The example uses intraday price-range features to predict next-day SPY direction.
  • The reported test accuracy is lower than training accuracy, limiting evidence for predictive usefulness.
  • KNN can be computationally and memory intensive on large datasets.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.