MCPcopy Create free account
hub / github.com/Open-Quant/openquant / _lag1_autocorr

Function _lag1_autocorr

python/openquant/bars.py:123–135  ·  view source on GitHub ↗
(values: list[float])

Source from the content-addressed store, hash-verified

121
122
123def _lag1_autocorr(values: list[float]) -> float:
124 if len(values) < 3:
125 return 0.0
126 x = values[:-1]
127 y = values[1:]
128 mx = sum(x) / len(x)
129 my = sum(y) / len(y)
130 cov = sum((a - mx) * (b - my) for a, b in zip(x, y))
131 sx = math.sqrt(sum((a - mx) ** 2 for a in x))
132 sy = math.sqrt(sum((b - my) ** 2 for b in y))
133 if sx == 0.0 or sy == 0.0:
134 return 0.0
135 return cov / (sx * sy)
136
137
138def bar_diagnostics(df: pl.DataFrame) -> dict[str, float]:

Callers 1

bar_diagnosticsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected