Specific methods for segmenting on time ranges or if condition is met is supported with the following methods.
The when
methods allows aggregating elements from a TimeArray
into
specific time periods, such as Mondays or the month of October:
using TimeSeries
using MarketData
when(cl, dayofweek, 1)
when(cl, dayname, "Monday")
The period argument holds a valid Date
method. Below are currently
available alternatives.
Dates method | Example |
---|---|
day |
Jan 3, 2000 = 3 |
dayname |
Jan 3, 2000 = "Monday" |
week |
Jan 3, 2000 = 1 |
month |
Jan 3, 2000 = 1 |
monthname |
Jan 3, 2000 = "January" |
year |
Jan 3, 2000 = 2000 |
dayofweek |
Monday = 1 |
dayofweekofmonth |
Fourth Monday in Jan = 4 |
dayofyear |
Dec 31, 2000 = 366 |
quarterofyear |
Dec 31, 2000 = 4 |
dayofquarter |
Dec 31, 2000 = 93 |
The from
method truncates a TimeArray
starting with the date passed to
the method:
using TimeSeries
using MarketData
from(cl, Date(2001, 12, 27))
The to
method truncates a TimeArray
after the date passed to the
method:
using TimeSeries
using MarketData
to(cl, Date(2000, 1, 5))
The findwhen
method test a condition and returns a vector of Date
or
DateTime
where the condition is true
:
using TimeSeries
using MarketData
green = findwhen(ohlc[:Close] .> ohlc[:Open]);
typeof(green)
ohlc[green]
The findall
method tests a condition and returns a vector of Int
representing the row in the array where the condition is true
:
using TimeSeries
using MarketData
red = findall(ohlc[:Close] .< ohlc[:Open]);
typeof(red)
ohlc[red]
The following example won't create a temporary Bool
vector, and gains better
performance.
using TimeSeries
using MarketData
findall(>(100), cl)
The head
method defaults to returning only the first value in a
TimeArray
. By selecting the second positional argument to a different
value, the user can modify how many from the top are selected:
using TimeSeries
using MarketData
head(cl)
The tail
method defaults to returning only the last value in a
TimeArray
. By selecting the second positional argument to a different
value, the user can modify how many from the bottom are selected:
using TimeSeries
using MarketData
tail(cl)
tail(cl, 3)