JuliaStats / TimeSeries.jl

Time series toolkit for Julia
Other
349 stars 69 forks source link

collapse to quarter #501

Closed sellingsrud closed 2 years ago

sellingsrud commented 2 years ago

Quarterly data is prevalent in social science, it'd be useful with a collapse(x, quarter) method.

iblislin commented 2 years ago

Is quarterofyear suitable for you?

julia> collapse(cl, quarterofyear, first, mean)
8×1 TimeArray{Float64, 1, Date, Vector{Float64}} 2000-01-03 to 2001-10-01
│            │ Close    │
├────────────┼──────────┤
│ 2000-01-03 │ 115.1667 │
│ 2000-04-03 │ 99.8794  │
│ 2000-07-03 │ 53.4998  │
│ 2000-10-02 │ 18.4517  │
│ 2001-01-02 │ 19.6232  │
│ 2001-04-02 │ 22.6063  │
│ 2001-07-02 │ 19.129   │
│ 2001-10-01 │ 19.4522  │
sellingsrud commented 2 years ago

Perfect, that's exactly the functionality I needed.

Maybe it's already there? I only checked "quarter" and looked at the list in the docs. Sorry about that

iblislin commented 2 years ago

ah, I will update the doc.

iblislin commented 2 years ago

I just recalled https://github.com/JuliaStats/TimeSeries.jl/issues/498#issue-932229197. So, this might be more accurate:

collapse(cl, Dates.quarter, first, mean)