Skip to content
LeetQuant

Medium · Python / C++ Quant Coding · Coding · ~10 min · #42

EWMA Volatility Filter

The exponentially weighted moving-average (EWMA) variance estimator updates

vt=λ vt−1+(1−λ) rt2,v_t = \lambda\,v_{t-1} + (1 - \lambda)\,r_t^2 ,

starting from an initial variance v0v_0.

Implement ewma_variance(returns: list[float], lam: float, v0: float) -> list[float] returning [v1,…,vn][v_1, \dots, v_n].

Examples

Input: ewma_variance([0.0, 0.0], 0.9, 0.04)

Output: [0.036, 0.0324]

Constraints

  • •

    0 < lam < 1

  • •

    v0 ≥ 0

Hints · 0 of 1 shown

Worked solution

Give the problem an honest attempt first, then reveal the full explanation.

Related questions

Concepts

EWMAVolatility clusteringRecursive filters

Relevant for

Quant DeveloperQuant ResearcherDesk Quant