Aggregation
Sampling
Weekdays
Temporal.mondays
— Functionmondays(x::TS)
Return a time series containing all observations occuring on Mondays of the given TS
object.
Temporal.tuesdays
— Functiontuesdays(x::TS)
Return a time series containing all observations occuring on Tuesdays of the given TS
object.
Temporal.wednesdays
— Functionwednesdays(x::TS)
Return a time series containing all observations occuring on Wednesdays of the given TS
object.
Temporal.thursdays
— Functionthursdays(x::TS)
Return a time series containing all observations occuring on Thursdays of the given TS
object.
Temporal.fridays
— Functionfridays(x::TS)
Return a time series containing all observations occuring on Fridays of the given TS
object.
Temporal.saturdays
— Functionsaturdays(x::TS)
Return a time series containing all observations occuring on Saturdays of the given TS
object.
Temporal.sundays
— Functionsundays(x::TS)
Return a time series containing all observations occuring on Sundays of the given TS
object.
Interval Boundaries
Weekly
Temporal.bow
— Functionbow(x::TS; cal::Bool=false)
Return a time series containing all observations occuring at the beginnings of the weeks of the input.
- If
cal
isfalse
, only observations occurring the last calendar day of the week are returned - If
cal
istrue
, all observation for which the previous index is a prior week are returned
Temporal.eow
— Functioneow(x::TS; cal::Bool=false)
Return a time series containing all observations occuring at the ends of the weeks of the input.
- If
cal
isfalse
, only observations occurring the last calendar day of the week are returned - If
cal
istrue
, all observation for which the next index is a new week are returned
Monthly
Temporal.bom
— Functionbom(x::TS; cal::Bool=false)
Return a time series containing all observations occuring at the beginnings of the months of the input.
- If
cal
isfalse
, only observations occurring the last calendar day of the month are returned - If
cal
istrue
, all observation for which the previous index is a prior month are returned
Temporal.eom
— Functioneom(x::TS; cal::Bool=false)
Return a time series containing all observations occuring at the ends of the months of the input.
- If
cal
isfalse
, only observations occurring the last calendar day of the month are returned - If
cal
istrue
, all observation for which the next index is a new month are returned
Quarterly
Temporal.boq
— Functionboq(x::TS; cal::Bool=false)
Return a time series containing all observations occuring at the beginnings of the quarters of the input.
- If
cal
isfalse
, only observations occurring the last calendar day of the quarter are returned - If
cal
istrue
, all observation for which the previous index is a prior quarter are returned
Temporal.eoq
— Functioneoq(x::TS; cal::Bool=false)
Return a time series containing all observations occuring at the ends of the quarters of the input.
- If
cal
isfalse
, only observations occurring the last calendar day of the quarter are returned - If
cal
istrue
, all observation for which the next index is a new quarter are returned
Yearly
Temporal.boy
— Functionboy(x::TS; cal::Bool=false)
Return a time series containing all observations occuring at the beginnings of the years of the input.
- If
cal
isfalse
, only observations occurring the last calendar day of the year are returned - If
cal
istrue
, all observation for which the previous index is a prior year are returned
Temporal.eoy
— Functioneoy(x::TS; cal::Bool=false)
Return a time series containing all observations occuring at the ends of the years of the input.
- If
cal
isfalse
, only observations occurring the last calendar day of the year are returned - If
cal
istrue
, all observation for which the next index is a new year are returned
Collapsing
Temporal.collapse
— Functioncollapse(x::TS, at::Function; fun::Function=last, args...)::TS
Compute the function fun
over period boundaries defined by at
(e.g. eom
, boq
, etc.) and returng a time series of the results.
Keyword arguments (args...
) are passed to the function fun
.
julia> using Temporal, Statistics, Dates
julia> X = TS(randn(100, 4))
100x4 TS{Float64,Dates.Date}: 2019-10-15 to 2020-01-22
Index A B C D
2019-10-15 -0.1866 -0.84 -0.1397 2.2043
2019-10-16 0.7517 -0.8447 -0.5989 -1.4443
2019-10-17 -1.8092 0.0303 0.6289 -1.8995
2019-10-18 -1.1157 1.3227 1.0881 0.283
2019-10-19 2.3262 -1.0653 0.8624 -1.4475
2019-10-20 -1.3373 -0.8158 -0.7763 1.7431
2019-10-21 -1.4505 0.7358 -1.1379 -0.2587
⋮
2020-01-15 -1.2701 0.0881 0.3331 0.3654
2020-01-16 -0.547 -0.656 0.3009 1.12
2020-01-17 -0.0798 -1.5292 -1.2675 0.8403
2020-01-18 1.0677 -0.1692 -0.229 -0.8929
2020-01-19 0.2681 -0.5048 0.569 -0.0101
2020-01-20 2.202 0.171 0.1568 -0.8425
2020-01-21 1.1247 -0.882 -1.7938 1.926
2020-01-22 0.0681 -1.7146 1.472 -0.6442
julia> collapse(X, eom, fun=mean)
3x4 TS{Float64,Dates.Date}: 2019-10-31 to 2019-12-31
Index A B C D
2019-10-31 0.1631 0.0517 0.0729 -0.1831
2019-11-30 -0.0219 0.0558 0.4351 0.0572
2019-12-31 -0.0135 -0.0714 -0.0587 0.1542
julia> last_month = string(X.index[end])[1:7]
"2020-01"
julia> mean(X[last_month])
-0.0264185897272492
Summarizing
Temporal.apply
— Functionapply(x::TS, dim::Int=1; fun::Function=sum)
Apply function fun
across dimension dim
of a time series x
.
- If
dim
is 1, then applyfun
to each row ofx
, returning a time series (TS
) object of the results - If
dim
is 2, then applyfun
to each column ofx
, returning anArray
of the results
julia> using Temporal, Statistics
julia> X = TS(randn(100, 4))
100x4 TS{Float64,Dates.Date}: 2019-10-15 to 2020-01-22
Index A B C D
2019-10-15 -0.9595 0.1335 -1.0634 0.2979
2019-10-16 -0.5834 1.2348 -0.744 0.2918
2019-10-17 1.2931 -1.4254 -0.653 -0.2039
2019-10-18 0.8427 1.3852 0.8431 0.243
2019-10-19 -0.8869 1.131 -0.2246 0.6173
2019-10-20 1.2795 0.7889 -1.2842 1.0755
2019-10-21 -2.2764 1.0616 0.6205 -0.0099
⋮
2020-01-15 -0.5043 -1.3508 -0.1313 -0.9573
2020-01-16 -1.485 1.021 -1.9404 0.9268
2020-01-17 0.8451 -1.4235 0.3153 -0.0515
2020-01-18 -0.1652 0.1091 -0.1821 -2.225
2020-01-19 -0.2702 1.1492 0.7934 1.5887
2020-01-20 -0.2894 0.3906 0.817 0.9331
2020-01-21 -0.4678 -0.7675 -1.7152 0.4977
2020-01-22 -0.2223 -0.5855 -0.5913 -0.5921
julia> apply(X, 1, fun=sum)
100x1 TS{Float64,Dates.Date}: 2019-10-15 to 2020-01-22
Index Sum
2019-10-15 -1.5915
2019-10-16 0.1992
2019-10-17 -0.9892
2019-10-18 3.3139
2019-10-19 0.6368
2019-10-20 1.8597
2019-10-21 -0.6042
⋮
2020-01-15 -2.9437
2020-01-16 -1.4776
2020-01-17 -0.3146
2020-01-18 -2.4633
2020-01-19 3.261
2020-01-20 1.8512
2020-01-21 -2.4528
2020-01-22 -1.9912
julia> apply(X, 2, fun=sum)
1×4 LinearAlgebra.Adjoint{Float64,Array{Float64,1}}:
-8.12431 5.90707 9.15881 0.403375