fintech-algorithms

Top-N Index Contribution

Install and import

bash
npm install fintech-algorithms
ts
import { calculate } from "fintech-algorithms/market-breadth-and-internals/concentration-and-diffusion/top-n-index-contribution";

Signature

calculate(rows, topN)

Worked example

executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

Input

rows
[
  {
    "security_id": "S01",
    "weight": 0.17821782178217824,
    "return": 0.065,
    "sector": "Tech",
    "ready": true
  },
  {
    "security_id": "S02",
    "weight": 0.13861386138613863,
    "return": 0.041,
    "sector": "Financials",
    "ready": true
  },
  {
    "security_id": "S03",
    "weight": 0.10891089108910892,
    "return": 0.028,
    "sector": "Industrials",
    "ready": true
  }
]

Showing 3 of 24 elements.

topN
5

Call

calculate(rows, topN)

Returns

object with 6 fields: status, top_n, top_contribution, total_contribution, share, leaders

{
  "status": "resolved",
  "top_n": 5,
  "top_contribution": 0.02225742574257426,
  "total_contribution": 0.021676237623762376,
  "share": 1.0268122230850045,
  "leaders": [
    {
      "security_id": "S01",
      "contribution": 0.011584158415841586
    },
    {
      "security_id": "S02",
      "contribution": 0.005683168316831684
    },
    {
      "security_id": "S03",
      "contribution": 0.00304950495049505
    }
  ]
}

Diagrams

Top-N Index Contribution — decision boundary
Top-N Index Contribution — family map

How it works

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References