Skip to content

Statistics

Summarize observed returns and combine their mean with a critic prediction.

Maintain the count, mean, and sample variance of observed returns without retaining every observation. Calibration models read this record to compare outcomes with the critic prediction.

from focus.statistics import RunningStats

stats = RunningStats.of([0.0, 1.0])
stats.add(1.0)
assert stats.n == 3
assert round(stats.mean, 3) == 0.667

The three outcomes are summarized by a count, mean, and squared-deviation accumulator. variance returns the sample variance and is zero until two observations are available.

Definition

@dataclass
class RunningStats

Fields

n: int = 0
mean: float = 0.0
m2: float = 0.0
def add(self, value: float) -> None

Incorporate one return into the count, mean, and squared-deviation accumulator.

@classmethod
def of(cls, values: Sequence[float]) -> RunningStats

Summarize a sequence of observed returns using the same incremental update as add().

@property
def variance(self) -> float

Return the sample variance, or zero with fewer than two observations.