csp icon indicating copy to clipboard operation
csp copied to clipboard

Adjusted, unbiased EMA covariance with a finite horizon does not handle initial NaN values correctly

Open AdamGlustein opened this issue 8 months ago • 1 comments

Describe the bug

Using csp.stats.ema_cov with a finite horizon (rolling window) and adjusted=True will have incorrect results if the initial stream values are NaN and those values are then removed from the window, as m_nan_count is not being incremented in AlphaDebiasEMA.

https://github.com/Point72/csp/blob/main/cpp/csp/cppnodes/statsimpl.h#L1629

To Reproduce

Expected behavior

We need to increment the NaN count even if m_first = true, so that the decrement when those numbers are removed from the window is valid.

Error Message

Runtime Environment

Additional context

AdamGlustein avatar Apr 23 '25 18:04 AdamGlustein