Package Options

There are two package options that can be adjusted to change the way that Temporal behaves.

Range Delimiter

The RANGE_DELIMITER option specifies what value should separate the Strings when indexing a TS object's rows using the String indexing syntax.

By default, RANGE_DELIMITER is set to '/', and can be changed dynamically using the function set_range_delimiter_option.

julia> using Temporal, Dates;

julia> t = Date("2017-01-01"):Day(1):Date("2017-12-31");

julia> vals = rand(length(t), 4);

julia> X = TS(vals, t)
365x4 TS{Float64,Dates.Date}: 2017-01-01 to 2017-12-31

Index       A       B       C       D
2017-01-01  0.1072  0.8574  0.2335  0.9893
2017-01-02  0.6335  0.3741  0.1189  0.3185
2017-01-03  0.7113  0.1756  0.0512  0.8062
2017-01-04  0.1227  0.9839  0.8301  0.4192
2017-01-05  0.5186  0.3651  0.8456  0.9159
2017-01-06  0.8607  0.1827  0.1154  0.5903
2017-01-07  0.1892  0.7507  0.8684  0.5941
⋮
2017-12-24  0.0172  0.0308  0.2167  0.633
2017-12-25  0.6061  0.3724  0.7569  0.2734
2017-12-26  0.2341  0.6407  0.4981  0.723
2017-12-27  0.8685  0.9318  0.7318  0.6461
2017-12-28  0.9149  0.9831  0.639   0.8597
2017-12-29  0.6592  0.4388  0.3759  0.3694
2017-12-30  0.2511  0.5314  0.2005  0.8377
2017-12-31  0.863   0.3022  0.8407  0.8027

julia> X["2017-03-15/2017-06-15"]
93x4 TS{Float64,Dates.Date}: 2017-03-15 to 2017-06-15

Index       A       B       C       D
2017-03-15  0.8968  0.541   0.0326  0.3913
2017-03-16  0.1717  0.7262  0.0021  0.3676
2017-03-17  0.6964  0.7962  0.638   0.1697
2017-03-18  0.0584  0.6534  0.3525  0.0013
2017-03-19  0.8014  0.0767  0.1966  0.8523
2017-03-20  0.5668  0.4626  0.8473  0.8024
2017-03-21  0.9264  0.2486  0.5453  0.2434
⋮
2017-06-08  0.3968  0.6134  0.9734  0.1368
2017-06-09  0.0619  0.9657  0.523   0.8783
2017-06-10  0.7686  0.517   0.4824  0.5407
2017-06-11  0.8368  0.2405  0.4624  0.7307
2017-06-12  0.9961  0.7274  0.5957  0.8908
2017-06-13  0.463   0.6417  0.6508  0.83
2017-06-14  0.9937  0.1234  0.6556  0.0124
2017-06-15  0.6206  0.4718  0.8669  0.4065

julia> set_range_delimiter_option("::")
ERROR: UndefVarError: set_range_delimiter_option not defined

julia> X["2017-03-15::2017-06-15"]
ERROR: AssertionError: Invalid indexing string: Unable to parse 2017-03-15::2017-06-15

Name Sanitization

The SANITIZE_NAMES option is a boolean value indicating whether the column names (that is, the object's fields member), should be cleaned of whitespace and non-alphanumeric characters before constructing TS objects. This can make it easier to deal with names of columns more quickly and easily in some cases.

By default, SANITIZE_NAMES is set to false, so that generally speaking the raw user input data is used. This option can be changed with the set_sanitize_names_option function.

Notice in the sample below how the Adj Close column name becomes AdjClose after changing the setting to true.

julia> using Temporal, Dates;

julia> A = tsread(Pkg.dir("Temporal", "data", "XOM.csv"))
ERROR: UndefVarError: Pkg not defined

julia> set_sanitize_names_option(true)
ERROR: UndefVarError: set_sanitize_names_option not defined

julia> B = tsread(Pkg.dir("Temporal", "data", "XOM.csv"))
ERROR: UndefVarError: Pkg not defined

Rename columns

Not in place

rename function return a TS.

julia> using Temporal

julia> N = 252*3
756

julia> K = 4
4

julia> data = cumsum(randn(N,K), dims=1)
756×4 Array{Float64,2}:
  1.0895     1.97171  -0.240316   0.61921
  2.53565    2.81847  -0.73297   -0.4793
  3.77363    3.28842  -1.04041    0.478627
  4.12425    2.982    -0.321533  -0.788348
  4.60952    3.87655  -1.42987   -2.26979
  6.7308     1.91224  -1.84674   -1.64479
  7.26357    1.99823  -2.59636   -1.89419
  6.5971     2.77929  -1.54775   -2.11033
  6.79898    1.82697  -1.39044   -3.13487
  7.6067     1.40426  -2.64277   -2.71915
  ⋮
  0.521219  -1.51245   6.56423   24.207
 -0.386044  -1.66345   5.83795   23.2714
 -1.63529   -2.34824   6.39998   23.0424
 -2.24438   -3.47195   7.04949   23.7661
 -2.87783   -3.35872   6.39502   25.2678
 -3.81742   -4.85864   7.83293   25.6281
 -1.29491   -4.27939   9.58645   25.1884
 -1.09359   -7.21136   8.70883   26.8908
 -1.71845   -5.7547    8.411     24.5481

julia> dates = today()-Day(N-1):Day(1):today()
ERROR: UndefVarError: today not defined

julia> ts = TS(data, dates, [:a, :b, :c, :d])
ERROR: UndefVarError: dates not defined

julia> rename(ts, :a => :A, :d => :D)
ERROR: MethodError: no method matching rename(::Type{TS}, ::Pair{Symbol,Symbol}, ::Pair{Symbol,Symbol})
Closest candidates are:
  rename(!Matched::TS, ::Pair{Symbol,Symbol}...) at /home/travis/build/dysonance/Temporal.jl/src/util/alter.jl:28
  rename(::Union{Function, Type}, !Matched::TS) at /home/travis/build/dysonance/Temporal.jl/src/util/alter.jl:34
  rename(::Union{Function, Type}, !Matched::TS, !Matched::Type{Symbol}) at /home/travis/build/dysonance/Temporal.jl/src/util/alter.jl:34
  ...

julia> rename(ts, Dict(:a => :A, :d => :D)...)
ERROR: MethodError: no method matching rename(::Type{TS}, ::Pair{Symbol,Symbol}, ::Pair{Symbol,Symbol})
Closest candidates are:
  rename(!Matched::TS, ::Pair{Symbol,Symbol}...) at /home/travis/build/dysonance/Temporal.jl/src/util/alter.jl:28
  rename(::Union{Function, Type}, !Matched::TS) at /home/travis/build/dysonance/Temporal.jl/src/util/alter.jl:34
  rename(::Union{Function, Type}, !Matched::TS, !Matched::Type{Symbol}) at /home/travis/build/dysonance/Temporal.jl/src/util/alter.jl:34
  ...

julia> rename(Symbol ∘ uppercase ∘ string, ts)
ERROR: MethodError: no method matching rename(::getfield(Base, Symbol("##58#59")){getfield(Base, Symbol("##58#59")){DataType,typeof(uppercase)},typeof(string)}, ::Type{TS})
Closest candidates are:
  rename(::Union{Function, Type}, !Matched::TS) at /home/travis/build/dysonance/Temporal.jl/src/util/alter.jl:34
  rename(::Union{Function, Type}, !Matched::TS, !Matched::Type{Symbol}) at /home/travis/build/dysonance/Temporal.jl/src/util/alter.jl:34
  rename(::Union{Function, Type}, !Matched::TS, !Matched::Type{String}) at /home/travis/build/dysonance/Temporal.jl/src/util/alter.jl:40

julia> rename(uppercase, ts, String)
ERROR: MethodError: no method matching rename(::typeof(uppercase), ::Type{TS}, ::Type{String})
Closest candidates are:
  rename(::Union{Function, Type}, !Matched::TS, ::Type{String}) at /home/travis/build/dysonance/Temporal.jl/src/util/alter.jl:40
  rename(::Union{Function, Type}, !Matched::TS) at /home/travis/build/dysonance/Temporal.jl/src/util/alter.jl:34
  rename(::Union{Function, Type}, !Matched::TS, !Matched::Type{Symbol}) at /home/travis/build/dysonance/Temporal.jl/src/util/alter.jl:34

In place

rename! function modify name of columns in place and return true when a TS is renamed.

rename!(ts, :a => :A, :d => :D)
rename!(ts, Dict(:a => :A, :d => :D)...)
rename!(Symbol ∘ uppercase ∘ string, ts)
rename!(uppercase, ts, String)