Array indexing

Array indexing

Indexing out a time series is done with common bracketing semantics.

Row indexing

Integer

ExampleDescriptionIndexing value
[1]First row of data onlysingle integer
[1:3]First through third row onlyinteger range
[1:2:10]Odd row between first to tenth rowinteger range with step
[[1:3; 8]]First through third row and eight rowinteger range & single integer
[end]Last row

Examples in REPL:

julia> ohlc[1]
1×4 TimeArray{Float64,2,Date,Array{Float64,2}} 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,Array{Float64,2}} 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,Array{Float64,2}} 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,Array{Float64,2}} 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,Array{Float64,2}} 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

ExampleDescriptionIndexing value
[Date(2000, 1, 3)]The row containing Jan 3, 2000 timestampsingle Date
[[Date(2000, 1, 3), Date(2000, 2, 4)]]The rows containing Jan 3 & Feb 4, 2000multiple Dates
[Date(2000, 1, 3):Day(1):Date(2000, 2, 4)]The rows between Jan 3, 2000 & Feb 4, 2000range of Date

Examples in REPL:

julia> ohlc[Date(2000, 1, 3)]
1×4 TimeArray{Float64,2,Date,Array{Float64,2}} 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,Array{Float64,2}} 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-13 │ 94.48  │ 98.75  │ 92.5   │ 96.75  │
   ⋮
│ 2000-01-26 │ 110.0  │ 114.19 │ 109.75 │ 110.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  │

Column indexing

Symbol

ExampleDescriptionIndexing value
[:Open]The column named :Opensingle symbol
[:Open, :Close]The columns named :Open and :Closemultiple symbols

Examples in REPL:

julia> ohlc[:Open]
500×1 TimeArray{Float64,1,Date,Array{Float64,1}} 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   │
│ 2000-01-13 │ 94.48  │
   ⋮
│ 2001-12-19 │ 20.58  │
│ 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  │

julia> ohlc[:Open, :Close]
500×2 TimeArray{Float64,2,Date,Array{Float64,2}} 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  │
│ 2000-01-13 │ 94.48  │ 96.75  │
   ⋮
│ 2001-12-19 │ 20.58  │ 21.62  │
│ 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   │

Mixed approach

ExampleDescriptionIndexing value
[:Open][1:3]:Open column & first 3 rowssingle symbol & integer range
[:Open][Date(2000, 1, 3)]:Open column and Jan 3, 2000single symbol & Date

Examples in REPL:

julia> ohlc[:Open][1:3]
3×1 TimeArray{Float64,1,Date,Array{Float64,1}} 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,Array{Float64,1}} 2000-01-03 to 2000-01-03
│            │ Open   │
├────────────┼────────┤
│ 2000-01-03 │ 104.88 │