joshday / OnlineStats.jl

⚡ Single-pass algorithms for statistics
https://joshday.github.io/OnlineStats.jl/latest/
MIT License
831 stars 62 forks source link

Extract field of an observation before feeding an OnlineStats - ValueExtractor wrapper #271

Closed femtotrader closed 8 months ago

femtotrader commented 8 months ago

Hello,

I'm looking for a way to wrap a function which could extract a field of an observation and feed its value to a OnlineStat object.

I found in OnlineStats doc CallFun which call f(o) each time an observation data is being updated but what I'm looking for is exactly the opposite: call f(data), feed f(data) to o I'm aware I can directly do fit!(o, f(data) but I want to do fit!(wrapped_o, data) where wrapped_o contains both OnelineStat o and function f

Does such a wrapper exists in OnlineStats? (or in OnlineStatsBase) If not how can it be implemented?

My use case:

I want to wrap the EMA indicator in a ValueExtractor object with a function like candle -> candle.close Something like

ema = EMA{Float64}(period=ma_period)
o = ValueExtractor{OHLCV{Missing,Float64,Float64}}(ema, candle -> candle.close)

Kind regards

joshday commented 8 months ago

See https://joshday.github.io/OnlineStats.jl/latest/api/#OnlineStatsBase.FilterTransform

I meant to split out Filter and Transform as separate wrappers but I guess I never got around to it.

femtotrader commented 8 months ago

Thanks @joshday