Array indexing
Indexing out a time series is done with common bracketing semantics.
Row indexing
Integer
Example | Description | Indexing value |
---|---|---|
[1] | First row of data only | single integer |
[1:3] | First through third row only | integer range |
[1:2:10] | Odd row between first to tenth row | integer range with step |
[[1:3; 8]] | First through third row and eight row | integer range & single integer |
[end] | Last row |
Examples in REPL:
julia> ohlc[1]
1×4 TimeArray{Float64, 2, Date, Matrix{Float64}} 2000-01-03 to 2000-01-03 ┌────────────┬────────┬───────┬────────┬────────┐ │ │ Open │ High │ Low │ Close │ ├────────────┼────────┼───────┼────────┼────────┤ │ 2000-01-03 │ 104.88 │ 112.5 │ 101.69 │ 111.94 │ └────────────┴────────┴───────┴────────┴────────┘
julia> ohlc[1:3]
3×4 TimeArray{Float64, 2, Date, Matrix{Float64}} 2000-01-03 to 2000-01-05 ┌────────────┬────────┬────────┬────────┬────────┐ │ │ Open │ High │ Low │ Close │ ├────────────┼────────┼────────┼────────┼────────┤ │ 2000-01-03 │ 104.88 │ 112.5 │ 101.69 │ 111.94 │ │ 2000-01-04 │ 108.25 │ 110.62 │ 101.19 │ 102.5 │ │ 2000-01-05 │ 103.75 │ 110.56 │ 103.0 │ 104.0 │ └────────────┴────────┴────────┴────────┴────────┘
julia> ohlc[1:2:10]
5×4 TimeArray{Float64, 2, Date, Matrix{Float64}} 2000-01-03 to 2000-01-13 ┌────────────┬────────┬────────┬────────┬────────┐ │ │ Open │ High │ Low │ Close │ ├────────────┼────────┼────────┼────────┼────────┤ │ 2000-01-03 │ 104.88 │ 112.5 │ 101.69 │ 111.94 │ │ 2000-01-05 │ 103.75 │ 110.56 │ 103.0 │ 104.0 │ │ 2000-01-07 │ 96.5 │ 101.0 │ 95.5 │ 99.5 │ │ 2000-01-11 │ 95.94 │ 99.38 │ 90.5 │ 92.75 │ │ 2000-01-13 │ 94.48 │ 98.75 │ 92.5 │ 96.75 │ └────────────┴────────┴────────┴────────┴────────┘
julia> ohlc[[1:3;8]]
4×4 TimeArray{Float64, 2, Date, Matrix{Float64}} 2000-01-03 to 2000-01-12 ┌────────────┬────────┬────────┬────────┬────────┐ │ │ Open │ High │ Low │ Close │ ├────────────┼────────┼────────┼────────┼────────┤ │ 2000-01-03 │ 104.88 │ 112.5 │ 101.69 │ 111.94 │ │ 2000-01-04 │ 108.25 │ 110.62 │ 101.19 │ 102.5 │ │ 2000-01-05 │ 103.75 │ 110.56 │ 103.0 │ 104.0 │ │ 2000-01-12 │ 95.0 │ 95.5 │ 86.5 │ 87.19 │ └────────────┴────────┴────────┴────────┴────────┘
julia> ohlc[end]
1×4 TimeArray{Float64, 2, Date, Matrix{Float64}} 2001-12-31 to 2001-12-31 ┌────────────┬───────┬───────┬───────┬───────┐ │ │ Open │ High │ Low │ Close │ ├────────────┼───────┼───────┼───────┼───────┤ │ 2001-12-31 │ 22.51 │ 22.66 │ 21.83 │ 21.9 │ └────────────┴───────┴───────┴───────┴───────┘
Date and DateTime
Example | Description | Indexing value |
---|---|---|
[Date(2000, 1, 3)] | The row containing Jan 3, 2000 timestamp | single Date |
[[Date(2000, 1, 3), Date(2000, 2, 4)]] | The rows containing Jan 3 & Feb 4, 2000 | multiple Dates |
[Date(2000, 1, 3):Day(1):Date(2000, 2, 4)] | The rows between Jan 3, 2000 & Feb 4, 2000 | range of Date |
Examples in REPL:
julia> ohlc[Date(2000, 1, 3)]
1×4 TimeArray{Float64, 2, Date, Matrix{Float64}} 2000-01-03 to 2000-01-03 ┌────────────┬────────┬───────┬────────┬────────┐ │ │ Open │ High │ Low │ Close │ ├────────────┼────────┼───────┼────────┼────────┤ │ 2000-01-03 │ 104.88 │ 112.5 │ 101.69 │ 111.94 │ └────────────┴────────┴───────┴────────┴────────┘
julia> ohlc[Date(2000, 1, 3):Day(1):Date(2000, 2, 4)]
24×4 TimeArray{Float64, 2, Date, Matrix{Float64}} 2000-01-03 to 2000-02-04 ┌────────────┬────────┬────────┬────────┬────────┐ │ │ Open │ High │ Low │ Close │ ├────────────┼────────┼────────┼────────┼────────┤ │ 2000-01-03 │ 104.88 │ 112.5 │ 101.69 │ 111.94 │ │ 2000-01-04 │ 108.25 │ 110.62 │ 101.19 │ 102.5 │ │ 2000-01-05 │ 103.75 │ 110.56 │ 103.0 │ 104.0 │ │ 2000-01-06 │ 106.12 │ 107.0 │ 95.0 │ 95.0 │ │ 2000-01-07 │ 96.5 │ 101.0 │ 95.5 │ 99.5 │ │ 2000-01-10 │ 102.0 │ 102.25 │ 94.75 │ 97.75 │ │ 2000-01-11 │ 95.94 │ 99.38 │ 90.5 │ 92.75 │ │ 2000-01-12 │ 95.0 │ 95.5 │ 86.5 │ 87.19 │ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │ │ 2000-01-27 │ 108.81 │ 113.0 │ 107.0 │ 110.0 │ │ 2000-01-28 │ 108.19 │ 110.88 │ 100.62 │ 101.62 │ │ 2000-01-31 │ 101.0 │ 103.88 │ 94.5 │ 103.75 │ │ 2000-02-01 │ 104.0 │ 105.0 │ 100.0 │ 100.25 │ │ 2000-02-02 │ 100.75 │ 102.12 │ 97.0 │ 98.81 │ │ 2000-02-03 │ 100.31 │ 104.25 │ 100.25 │ 103.31 │ │ 2000-02-04 │ 103.94 │ 110.0 │ 103.62 │ 108.0 │ └────────────┴────────┴────────┴────────┴────────┘ 9 rows omitted
Column indexing
Symbol
Example | Description | Indexing value |
---|---|---|
[:Open] | The column named :Open | single symbol |
[:Open, :Close] | The columns named :Open and :Close | multiple symbols |
[[:Open, :Close]] | The columns named :Open and :Close | multiple symbols |
Examples in REPL:
julia> ohlc[:Open]
500×1 TimeArray{Float64, 1, Date, Vector{Float64}} 2000-01-03 to 2001-12-31 ┌────────────┬────────┐ │ │ Open │ ├────────────┼────────┤ │ 2000-01-03 │ 104.88 │ │ 2000-01-04 │ 108.25 │ │ 2000-01-05 │ 103.75 │ │ 2000-01-06 │ 106.12 │ │ 2000-01-07 │ 96.5 │ │ 2000-01-10 │ 102.0 │ │ 2000-01-11 │ 95.94 │ │ 2000-01-12 │ 95.0 │ │ ⋮ │ ⋮ │ │ 2001-12-20 │ 21.4 │ │ 2001-12-21 │ 21.01 │ │ 2001-12-24 │ 20.9 │ │ 2001-12-26 │ 21.35 │ │ 2001-12-27 │ 21.58 │ │ 2001-12-28 │ 21.97 │ │ 2001-12-31 │ 22.51 │ └────────────┴────────┘ 485 rows omitted
julia> ohlc[:Open, :Close]
500×2 TimeArray{Float64, 2, Date, Matrix{Float64}} 2000-01-03 to 2001-12-31 ┌────────────┬────────┬────────┐ │ │ Open │ Close │ ├────────────┼────────┼────────┤ │ 2000-01-03 │ 104.88 │ 111.94 │ │ 2000-01-04 │ 108.25 │ 102.5 │ │ 2000-01-05 │ 103.75 │ 104.0 │ │ 2000-01-06 │ 106.12 │ 95.0 │ │ 2000-01-07 │ 96.5 │ 99.5 │ │ 2000-01-10 │ 102.0 │ 97.75 │ │ 2000-01-11 │ 95.94 │ 92.75 │ │ 2000-01-12 │ 95.0 │ 87.19 │ │ ⋮ │ ⋮ │ ⋮ │ │ 2001-12-20 │ 21.4 │ 20.67 │ │ 2001-12-21 │ 21.01 │ 21.0 │ │ 2001-12-24 │ 20.9 │ 21.36 │ │ 2001-12-26 │ 21.35 │ 21.49 │ │ 2001-12-27 │ 21.58 │ 22.07 │ │ 2001-12-28 │ 21.97 │ 22.43 │ │ 2001-12-31 │ 22.51 │ 21.9 │ └────────────┴────────┴────────┘ 485 rows omitted
julia> cols = [:Open, :Close]
2-element Vector{Symbol}: :Open :Close
julia> ohlc[cols]
500×2 TimeArray{Float64, 2, Date, Matrix{Float64}} 2000-01-03 to 2001-12-31 ┌────────────┬────────┬────────┐ │ │ Open │ Close │ ├────────────┼────────┼────────┤ │ 2000-01-03 │ 104.88 │ 111.94 │ │ 2000-01-04 │ 108.25 │ 102.5 │ │ 2000-01-05 │ 103.75 │ 104.0 │ │ 2000-01-06 │ 106.12 │ 95.0 │ │ 2000-01-07 │ 96.5 │ 99.5 │ │ 2000-01-10 │ 102.0 │ 97.75 │ │ 2000-01-11 │ 95.94 │ 92.75 │ │ 2000-01-12 │ 95.0 │ 87.19 │ │ ⋮ │ ⋮ │ ⋮ │ │ 2001-12-20 │ 21.4 │ 20.67 │ │ 2001-12-21 │ 21.01 │ 21.0 │ │ 2001-12-24 │ 20.9 │ 21.36 │ │ 2001-12-26 │ 21.35 │ 21.49 │ │ 2001-12-27 │ 21.58 │ 22.07 │ │ 2001-12-28 │ 21.97 │ 22.43 │ │ 2001-12-31 │ 22.51 │ 21.9 │ └────────────┴────────┴────────┘ 485 rows omitted
Mixed approach
Example | Description | Indexing value |
---|---|---|
[1:3, :Open] | :Open column & first 3 rows | single symbol & integer range |
[:Open][Date(2000, 1, 3)] | :Open column and Jan 3, 2000 | single symbol & Date |
Examples in REPL:
julia> ohlc[1:3, :Open]
3×1 TimeArray{Float64, 2, Date, Matrix{Float64}} 2000-01-03 to 2000-01-05 ┌────────────┬────────┐ │ │ Open │ ├────────────┼────────┤ │ 2000-01-03 │ 104.88 │ │ 2000-01-04 │ 108.25 │ │ 2000-01-05 │ 103.75 │ └────────────┴────────┘
julia> ohlc[:Open][Date(2000, 1, 3)]
1×1 TimeArray{Float64, 1, Date, Vector{Float64}} 2000-01-03 to 2000-01-03 ┌────────────┬────────┐ │ │ Open │ ├────────────┼────────┤ │ 2000-01-03 │ 104.88 │ └────────────┴────────┘