fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Downside Deviation and Target Shortfall

Install and import#

bash
npm install fintech-algorithms
ts
import { downsideDeviationAndTargetShortfall } from "fintech-algorithms/foundations/financial-risk-and-performance-statistics/downside-deviation-and-target-shortfall";

Signature#

downsideDeviationAndTargetShortfall(input)

Measures dispersion of returns below a target only, so upside swings do not count as risk.

Parameters#

NameTypeNotes
inputD00InputReads returns and benchmark, two aligned non-empty lists of finite periodic returns, frequency, the number of periods per year, and target, the return level below which a period counts as a shortfall.

Returns#

D00Output

downsideDeviation is the root mean square of the shortfalls below target, averaged over every observation rather than only the shortfalls. shortfallCount counts the returns strictly below the target, and target is echoed back.

Errors#

  • When returns or benchmark is absent, empty, or holds a non-finite number — throws RangeError
  • When returns and benchmark differ in length, or hold fewer than two observations — throws RangeError
  • When frequency is zero or negative — throws RangeError

Complexity: time O(n), space O(n).

Worked example#

verified This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.

Input#

input
{
  "returns": [0.01, -0.02, 0.015, -0.01, 0.03],
  "benchmark": [0.008, -0.01, 0.012, -0.006, 0.02],
  "frequency": 252,
  "target": 0,
  "confidence": 0.8,
  "riskFree": 0.0001,
  "weights": [0.6, 0.4],
  "covarianceMatrix": [
    [0.04, 0.01],
    [0.01, 0.09]
  ]
}

Call#

downsideDeviationAndTargetShortfall(input)

Returns#

object with 2 fields: downsideDeviation, shortfallCount

{
  "downsideDeviation": 0.01,
  "shortfallCount": 2
}

Diagrams#

Downside Deviation and Target Shortfall — article hero
Downside Deviation and Target Shortfall — calculation ledger
Downside Deviation and Target Shortfall — concept anatomy
Downside Deviation and Target Shortfall — failure boundary
Downside Deviation and Target Shortfall — method map
Downside Deviation and Target Shortfall — scenario contrast

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#

The rest of the Financial Risk and Performance Statistics family#