semiVariance

fun DoubleArray.semiVariance(threshold: Double = mean(), direction: SemiVarianceDirection = SemiVarianceDirection.DOWNSIDE, kind: PopulationKind = SAMPLE): Double(source)

Computes the semi-variance of the values on one side of a threshold.

Semi-variance measures variability on only one side of a threshold, ignoring values on the other side. It is commonly used in finance to quantify downside risk separately from upside potential. The divisor uses the total number of elements (n-1 for sample, n for population), not just the count on the measured side, matching the Apache Commons Math convention. When the threshold equals the mean, the sum of downside and upside semi-variance equals the full variance. Uses Neumaier compensated summation for numerical stability.

Example:

val data = doubleArrayOf(2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0)
data.semiVariance() // 1.7143 (downside, sample, threshold = mean)
data.semiVariance(direction = SemiVarianceDirection.UPSIDE) // 2.8571

Return

the semi-variance on the selected side of the threshold.

Parameters

threshold

the reference point that separates downside from upside. Defaults to the mean of the values.

direction

which side of the threshold to measure. Defaults to SemiVarianceDirection.DOWNSIDE, measuring downside risk.

kind

whether to compute sample or population semi-variance. Defaults to PopulationKind.SAMPLE, which divides by n-1 (Bessel's correction).

See also


fun Iterable<Double>.semiVariance(threshold: Double, direction: SemiVarianceDirection = SemiVarianceDirection.DOWNSIDE, kind: PopulationKind = SAMPLE): Double(source)

Computes the semi-variance of the values on one side of a threshold.

Semi-variance measures variability on only one side of a threshold, ignoring values on the other side. It is commonly used in finance to quantify downside risk separately from upside potential. The divisor uses the total number of elements (n-1 for sample, n for population), not just the count on the measured side. When the threshold equals the mean, the sum of downside and upside semi-variance equals the full variance.

Example:

listOf(2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0).semiVariance() // 1.7143 (downside, sample)

Return

the semi-variance on the selected side of the threshold.

Parameters

threshold

the reference point that separates downside from upside. Defaults to the mean of the values.

direction

which side of the threshold to measure. Defaults to SemiVarianceDirection.DOWNSIDE, measuring downside risk.

kind

whether to compute sample or population semi-variance. Defaults to PopulationKind.SAMPLE, which divides by n-1 (Bessel's correction).

See also


fun Iterable<Double>.semiVariance(direction: SemiVarianceDirection = SemiVarianceDirection.DOWNSIDE, kind: PopulationKind = SAMPLE): Double(source)

Computes the semi-variance using the mean as the threshold.

This overload materializes the iterable once and computes the mean from the materialized array, avoiding double iteration of single-use iterables.

Return

the semi-variance on the selected side of the mean.

Parameters

direction

which side of the threshold to measure. Defaults to SemiVarianceDirection.DOWNSIDE, measuring downside risk.

kind

whether to compute sample or population semi-variance. Defaults to PopulationKind.SAMPLE, which divides by n-1 (Bessel's correction).

See also


fun Sequence<Double>.semiVariance(direction: SemiVarianceDirection = SemiVarianceDirection.DOWNSIDE, kind: PopulationKind = SAMPLE): Double(source)

Computes the semi-variance of the values on one side of a threshold.

Semi-variance measures variability on only one side of a threshold, ignoring values on the other side. It is commonly used in finance to quantify downside risk separately from upside potential. The divisor uses the total number of elements (n-1 for sample, n for population), not just the count on the measured side. When the threshold equals the mean, the sum of downside and upside semi-variance equals the full variance.

This overload uses the mean of the data as the threshold. Since sequences can only be consumed once, the data is materialized internally.

Example:

sequenceOf(2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0).semiVariance() // 1.7143 (downside, sample)

Return

the semi-variance on the selected side of the threshold.

Parameters

direction

which side of the threshold to measure. Defaults to SemiVarianceDirection.DOWNSIDE, measuring downside risk.

kind

whether to compute sample or population semi-variance. Defaults to PopulationKind.SAMPLE, which divides by n-1 (Bessel's correction).

See also


fun Sequence<Double>.semiVariance(threshold: Double, direction: SemiVarianceDirection = SemiVarianceDirection.DOWNSIDE, kind: PopulationKind = SAMPLE): Double(source)

Computes the semi-variance of the values on one side of a threshold.

Semi-variance measures variability on only one side of a threshold, ignoring values on the other side. It is commonly used in finance to quantify downside risk separately from upside potential. The divisor uses the total number of elements (n-1 for sample, n for population), not just the count on the measured side. When the threshold equals the mean, the sum of downside and upside semi-variance equals the full variance.

Example:

sequenceOf(2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0).semiVariance(5.0) // downside, sample

Return

the semi-variance on the selected side of the threshold.

Parameters

threshold

the reference point that separates downside from upside.

direction

which side of the threshold to measure. Defaults to SemiVarianceDirection.DOWNSIDE, measuring downside risk.

kind

whether to compute sample or population semi-variance. Defaults to PopulationKind.SAMPLE, which divides by n-1 (Bessel's correction).

See also