semiVariance
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.8571Return
the semi-variance on the selected side of the threshold.
Parameters
the reference point that separates downside from upside. Defaults to the mean of the values.
which side of the threshold to measure. Defaults to SemiVarianceDirection.DOWNSIDE, measuring downside risk.
whether to compute sample or population semi-variance. Defaults to PopulationKind.SAMPLE, which divides by n-1 (Bessel's correction).
See also
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
the reference point that separates downside from upside. Defaults to the mean of the values.
which side of the threshold to measure. Defaults to SemiVarianceDirection.DOWNSIDE, measuring downside risk.
whether to compute sample or population semi-variance. Defaults to PopulationKind.SAMPLE, which divides by n-1 (Bessel's correction).
See also
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
which side of the threshold to measure. Defaults to SemiVarianceDirection.DOWNSIDE, measuring downside risk.
whether to compute sample or population semi-variance. Defaults to PopulationKind.SAMPLE, which divides by n-1 (Bessel's correction).
See also
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
which side of the threshold to measure. Defaults to SemiVarianceDirection.DOWNSIDE, measuring downside risk.
whether to compute sample or population semi-variance. Defaults to PopulationKind.SAMPLE, which divides by n-1 (Bessel's correction).
See also
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, sampleReturn
the semi-variance on the selected side of the threshold.
Parameters
the reference point that separates downside from upside.
which side of the threshold to measure. Defaults to SemiVarianceDirection.DOWNSIDE, measuring downside risk.
whether to compute sample or population semi-variance. Defaults to PopulationKind.SAMPLE, which divides by n-1 (Bessel's correction).