---
title: "k-Nearest Neighbors Supervised Portfolio"
method: POST
path: "/portfolios/optimization/supervised/nearest-neighbors-based"
tags: ["Portfolio Optimization"]
---

# k-Nearest Neighbors Supervised Portfolio

`POST /portfolios/optimization/supervised/nearest-neighbors-based`

Compute the asset weights forecasted by a k-nearest neighbors supervised portfolio allocation algorithm.
       
References
 * [Chevalier, G., Coqueret, G., & Raffinot, T. (2022). Supervised portfolios. Quantitative Finance, 22(12), 2275–2295](https://www.tandfonline.com/doi/full/10.1080/14697688.2022.2122543)
 * [David Varadi, Jason Teed, Adaptive Portfolio Allocations, NAAIM paper](https://cssanalytics.wordpress.com/2014/05/06/adaptive-portfolio-allocations/)
 * [Abu Alfeilat HA, Hassanat ABA, Lasassmeh O, Tarawneh AS, Alhasanat MB, Eyal Salman HS, Prasath VBS. Effects of Distance Measure Choice on K-Nearest Neighbor Classifier Performance: A Review. Big Data. 2019 Dec;7(4):221-248](https://pubmed.ncbi.nlm.nih.gov/31411491/)
 * [Oren Anava, Kfir Levy, k*-Nearest Neighbors: From Global to Local, Advances in Neural Information Processing Systems 29 (NIPS 2016)](https://papers.nips.cc/paper_files/paper/2016/hash/2c6ae45a3e88aee548c0714fad7f8269-Abstract.html)

## Request body

- object
  - `assets` integer, required — The number of assets
  - `assetsTrainingSample` object[], required — assetsTrainingSample[i] is the i-th training data point for the k-nearest neighbors regression algorithm
    - `assetsFeatures` number[], required — assetsFeatures[i] is the i-th numerical feature associated to the portfolio whose optimal asset weights to learn are provided in assetsWeights
    - `assetsWeights` number[], required — assetsWeights[i] is the weight of the asset i in the portfolio whose optimal asset weights to learn are provided, in percentage
  - `assetsInferenceSample` object[], required — assetsInferenceSample[i] is the i-th inference data point for the k-nearest neighbors regression algorithm
    - `assetsFeatures` number[], required — assetsFeatures[i] is the i-th numerical feature associated to the portfolio whose optimal asset weights are to be estimated by the k-nearest neighbors regression algorithm
  - `nearestNeighborsForecastMethod` 'kMean' | 'kStar' | 'kEnsemble' — The forecast method used to determine the label of an inference point
  - `nearestNeighbors` integer — The number of nearest neighbors used to determine the label of an inference point when nearestNeighborsForecastMethod is equal to 'kMean'
  - `nearestNeighborsDistanceMetric` 'euclidean' | 'hassanat' — The distance metric used to compute the nearest neighbors of an inference point

## Response `200`

OK

- object
  - `portfolios` object[], required
    - `assetsWeights` number[], required — assetsWeights[i] is the weight of the asset i in the portfolio, in percentage

---

[API](https://skmtc.dev/portfoliooptimizer/apis/portfolio-optimizer.md) · [All operations](https://skmtc.dev/portfoliooptimizer/apis/portfolio-optimizer/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/portfoliooptimizer/portfolio-optimizer/revisions/d047148d28bd/schema)
